Skip to content

Commit

Permalink
test: add allow restricted_flag
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Apr 29, 2024
1 parent 5ab8545 commit 88e3459
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions course_discovery/apps/course_metadata/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
class DraftManager(models.Manager):
""" Model manager that hides draft rows unless you ask for them. """

def get_queryset(self):
return super().get_queryset().filter(draft=models.Value(0))

def _with_drafts(self):
return super().get_queryset()
def get_queryset(self, allow_restricted=False):
if allow_restricted:
return super().get_queryset().filter(draft=models.Value(0))
return super().get_queryset().filter(draft=models.Value(0), restricted_run__isnull=True)

def _with_drafts(self, allow_restricted=False):
if allow_restricted:
return super().get_queryset()
return super().get_queryset().filter(restricted_run__isnull=True)

def filter_drafts(self, **kwargs):
def filter_drafts(self, allow_restricted=False, **kwargs):
"""
Acts like filter(), but prefers draft versions.
If a draft is not available, we give back the non-draft version.
"""
if allow_restricted:
return self._with_drafts(allow_restricted=allow_restricted).filter(Q(draft=models.Value(1)) | Q(draft_version=None)).filter(**kwargs)
return self._with_drafts().filter(Q(draft=models.Value(1)) | Q(draft_version=None)).filter(**kwargs)

def get_draft(self, **kwargs):
Expand Down

0 comments on commit 88e3459

Please sign in to comment.