Skip to content

Commit

Permalink
test: add some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Apr 29, 2024
1 parent dc21391 commit 0895d1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
26 changes: 18 additions & 8 deletions course_discovery/apps/course_metadata/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@
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 filter_drafts(self, **kwargs):
def get_queryset(self, allow_restricted=False):
if not allow_restricted:
return super().get_queryset().filter(draft=models.Value(0), restricted_run__isnull=True)
else:
return super().get_queryset().filter(draft=models.Value(0))

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

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.
"""
return self._with_drafts().filter(Q(draft=models.Value(1)) | Q(draft_version=None)).filter(**kwargs)
if allow_restricted:
return self._with_drafts(allow_restricted=True).filter(Q(draft=models.Value(1)) | Q(draft_version=None)).filter(**kwargs)
else:
return self._with_drafts().filter(Q(draft=models.Value(1)) | Q(draft_version=None)).filter(**kwargs)


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

This file was deleted.

0 comments on commit 0895d1b

Please sign in to comment.