Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Apr 29, 2024
1 parent 6b5b931 commit 3ebf5c1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions course_discovery/apps/course_metadata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ class CourseRunAdmin(SimpleHistoryAdmin):
search_fields = ('uuid', 'key', 'title_override', 'course__title', 'slug', 'external_key', 'variant_id')
save_error = False
form = CourseRunAdminForm

def get_queryset(self, request):
"""
Override the default queryset to show all course runs, including restricted ones.
"""
return self.model.everything_with_restricted_runs.all();

def get_readonly_fields(self, request, obj=None):
"""
Expand Down
9 changes: 9 additions & 0 deletions course_discovery/apps/course_metadata/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ def get_queryset(self):
class CourseRunObjectsManager(DraftManager.from_queryset(CourseRunQuerySet)):
def get_queryset(self):
return super().get_queryset().filter(restricted_run__isnull=True)

class CourseRunEverythingAllManager(BaseManager.from_queryset(CourseRunQuerySet)):
def get_queryset(self):
return super().get_queryset()


class CourseRunObjectsAllManager(DraftManager.from_queryset(CourseRunQuerySet)):
def get_queryset(self):
return super().get_queryset()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-04-29 20:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('course_metadata', '0341_restrictedcourserun'),
]

operations = [
migrations.AlterField(
model_name='restrictedcourserun',
name='restriction_type',
field=models.CharField(blank=True, choices=[('custom-b2b-enterprise', 'Custom B2B Enterprise'), ('custom-b2c', 'Custom B2C')], help_text='The type of restriction for the course run', max_length=255, null=True),
),
]
4 changes: 3 additions & 1 deletion course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
)
from course_discovery.apps.course_metadata.constants import SUBDIRECTORY_SLUG_FORMAT_REGEX, PathwayType
from course_discovery.apps.course_metadata.fields import AutoSlugWithSlashesField, HtmlField, NullHtmlField
from course_discovery.apps.course_metadata.managers import DraftManager, CourseRunObjectsManager, CourseRunEverythingManager
from course_discovery.apps.course_metadata.managers import DraftManager, CourseRunObjectsManager, CourseRunEverythingManager, CourseRunEverythingAllManager, CourseRunObjectsAllManager
from course_discovery.apps.course_metadata.people import MarketingSitePeople
from course_discovery.apps.course_metadata.publishers import (
CourseRunMarketingSitePublisher, ProgramMarketingSitePublisher
Expand Down Expand Up @@ -2192,6 +2192,8 @@ class CourseRun(ManageHistoryMixin, DraftModelMixin, CachedMixin, TimeStampedMod

everything = CourseRunEverythingManager()
objects = CourseRunObjectsManager()
everything_with_restricted_runs = CourseRunEverythingAllManager()
objects_with_restricted_runs = CourseRunObjectsAllManager()

# Do not record the slug field in the history table because AutoSlugField is not compatible with
# django-simple-history. Background: https://github.com/openedx/course-discovery/pull/332
Expand Down

0 comments on commit 3ebf5c1

Please sign in to comment.