Fix recently visited organization
This commit is contained in:
parent
512bc92116
commit
87eb082a18
6 changed files with 104 additions and 85 deletions
|
@ -39,7 +39,7 @@ from judge.models.problem_data import (
|
|||
problem_data_storage,
|
||||
problem_directory_file,
|
||||
)
|
||||
from judge.models.profile import Organization, OrganizationRequest, Profile, Friend
|
||||
from judge.models.profile import Organization, OrganizationRequest, Profile, Friend, OrganizationProfile
|
||||
from judge.models.runtime import Judge, Language, RuntimeVersion
|
||||
from judge.models.submission import (
|
||||
SUBMISSION_RESULT,
|
||||
|
|
|
@ -9,7 +9,6 @@ from django.urls import reverse
|
|||
from django.utils.functional import cached_property
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from requests import delete
|
||||
from fernet_fields import EncryptedCharField
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
|
||||
|
@ -438,35 +437,24 @@ class OrganizationProfile(models.Model):
|
|||
verbose_name=_("organization"),
|
||||
related_name="last_vist",
|
||||
on_delete=models.CASCADE,
|
||||
db_index=True,
|
||||
)
|
||||
last_visit = models.AutoField(
|
||||
verbose_name=_("last visit"),
|
||||
verbose_name=_("last visit"),
|
||||
primary_key=True,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def is_organization(self, users, organization):
|
||||
return (
|
||||
self.objects.filter(users=users)
|
||||
.filter(organization=organization)
|
||||
.exists()
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def remove_organization(self, users, organization):
|
||||
organizationprofile = self.objects.filter(users=users).filter(
|
||||
organization=organization
|
||||
)
|
||||
organizationprofile.delete()
|
||||
organizationprofile = self.objects.filter(users=users, organization=organization)
|
||||
if organizationprofile.exists():
|
||||
organizationprofile.delete()
|
||||
|
||||
@classmethod
|
||||
def add_organization(self, users, organization):
|
||||
if self.is_organization(users, organization):
|
||||
self.remove_organization(users, organization)
|
||||
self.remove_organization(users, organization)
|
||||
new_organization = OrganizationProfile(users=users, organization=organization)
|
||||
new_organization.save()
|
||||
|
||||
@classmethod
|
||||
def get_organization(self, users):
|
||||
def get_most_recent_organizations(self, users):
|
||||
return self.objects.filter(users=users).order_by("-last_visit")[:5]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue