Simplify logic

This commit is contained in:
cuom1999 2023-01-27 17:51:38 -06:00
parent 64a5c73c21
commit bd05ba6b78
2 changed files with 3 additions and 14 deletions

View file

@ -371,7 +371,7 @@ class Problem(models.Model):
@classmethod @classmethod
def get_visible_problems(cls, user): def get_visible_problems(cls, user):
# Do unauthenticated check here so we can skip authentication checks later on. # Do unauthenticated check here so we can skip authentication checks later on.
if not user.is_authenticated: if not user.is_authenticated or not user:
return cls.get_public_problems() return cls.get_public_problems()
# Conditions for visible problem: # Conditions for visible problem:

View file

@ -585,19 +585,8 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
] ]
def get_normal_queryset(self): def get_normal_queryset(self):
filter = Q(is_public=True) queryset = Problem.get_visible_problems(self.request.user)
if self.profile is not None: queryset = queryset.select_related("group")
filter |= Q(authors=self.profile)
filter |= Q(curators=self.profile)
filter |= Q(testers=self.profile)
queryset = (
Problem.objects.filter(filter).select_related("group").defer("description")
)
if not self.request.user.has_perm("see_organization_problem"):
filter = Q(is_organization_private=False)
if self.profile is not None:
filter |= Q(organizations__in=self.profile.organizations.all())
queryset = queryset.filter(filter)
if self.profile is not None and self.hide_solved: if self.profile is not None and self.hide_solved:
queryset = queryset.exclude( queryset = queryset.exclude(
id__in=Submission.objects.filter( id__in=Submission.objects.filter(