|
8 | 8 | from django.contrib.auth.models import Group |
9 | 9 | from django.db import models |
10 | 10 | from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField |
| 11 | +from opaque_keys.edx.keys import CourseKey |
11 | 12 | from opaque_keys.edx.locator import LibraryLocatorV2 |
12 | 13 |
|
13 | 14 |
|
@@ -94,103 +95,33 @@ class CourseOverview(models.Model): |
94 | 95 | """ |
95 | 96 | Model for storing and caching basic information about a course. |
96 | 97 |
|
97 | | - This model contains basic course metadata such as an ID, display name, |
98 | | - image URL, and any other information that would be necessary to display |
99 | | - a course as part of: |
100 | | - user dashboard (enrolled courses) |
101 | | - course catalog (courses to enroll in) |
102 | | - course about (meta data about the course) |
| 98 | + This model contains basic course metadata such as an ID, display name, and organization. |
| 99 | + It is used to link CourseScope instances to actual courses in the system. |
103 | 100 |
|
104 | 101 | .. no_pii: |
105 | 102 | """ |
106 | 103 |
|
107 | | - class Meta: |
108 | | - app_label = "course_overviews" |
109 | | - |
110 | | - # IMPORTANT: Bump this whenever you modify this model and/or add a migration. |
111 | | - VERSION = 19 |
112 | | - |
113 | | - # Cache entry versioning. |
114 | | - version = models.IntegerField() |
115 | | - |
116 | 104 | # Course identification |
117 | 105 | id = CourseKeyField(db_index=True, primary_key=True, max_length=255) |
118 | 106 | _location = UsageKeyField(max_length=255) |
119 | 107 | org = models.TextField(max_length=255, default="outdated_entry") |
120 | 108 | display_name = models.TextField(null=True) |
121 | | - display_number_with_default = models.TextField() |
122 | | - display_org_with_default = models.TextField() |
123 | | - |
124 | | - start = models.DateTimeField(null=True) |
125 | | - end = models.DateTimeField(null=True) |
126 | | - |
127 | | - # These are deprecated and unused, but cannot be dropped via simple migration due to the size of the downstream |
128 | | - # history table. See DENG-19 for details. |
129 | | - # Please use start and end above for these values. |
130 | | - start_date = models.DateTimeField(null=True) |
131 | | - end_date = models.DateTimeField(null=True) |
132 | | - |
133 | | - advertised_start = models.TextField(null=True) |
134 | | - announcement = models.DateTimeField(null=True) |
135 | | - |
136 | | - # URLs |
137 | | - # Not allowing null per django convention; not sure why many TextFields in this model do allow null |
138 | | - banner_image_url = models.TextField() |
139 | | - course_image_url = models.TextField() |
140 | | - social_sharing_url = models.TextField(null=True) |
141 | | - end_of_course_survey_url = models.TextField(null=True) |
142 | | - |
143 | | - # Certification data |
144 | | - certificates_display_behavior = models.TextField(null=True) |
145 | | - certificates_show_before_end = models.BooleanField(default=False) |
146 | | - cert_html_view_enabled = models.BooleanField(default=False) |
147 | | - has_any_active_web_certificate = models.BooleanField(default=False) |
148 | | - cert_name_short = models.TextField() |
149 | | - cert_name_long = models.TextField() |
150 | | - certificate_available_date = models.DateTimeField(default=None, null=True) |
151 | | - |
152 | | - # Grading |
153 | | - lowest_passing_grade = models.DecimalField(max_digits=5, decimal_places=2, null=True) |
154 | | - |
155 | | - # Access parameters |
156 | | - days_early_for_beta = models.FloatField(null=True) |
157 | | - mobile_available = models.BooleanField(default=False) |
158 | | - visible_to_staff_only = models.BooleanField(default=False) |
159 | | - _pre_requisite_courses_json = models.TextField() # JSON representation of list of CourseKey strings |
160 | | - |
161 | | - # Enrollment details |
162 | | - enrollment_start = models.DateTimeField(null=True) |
163 | | - enrollment_end = models.DateTimeField(null=True) |
164 | | - enrollment_domain = models.TextField(null=True) |
165 | | - invitation_only = models.BooleanField(default=False) |
166 | | - max_student_enrollments_allowed = models.IntegerField(null=True) |
167 | | - |
168 | | - # Catalog information |
169 | | - catalog_visibility = models.TextField(null=True) |
170 | | - short_description = models.TextField(null=True) |
171 | | - course_video_url = models.TextField(null=True) |
172 | | - effort = models.TextField(null=True) |
173 | | - self_paced = models.BooleanField(default=False) |
174 | | - marketing_url = models.TextField(null=True) |
175 | | - eligible_for_financial_aid = models.BooleanField(default=True) |
176 | | - |
177 | | - # Course highlight info, used to guide course update emails |
178 | | - has_highlights = models.BooleanField(null=True, default=None) # if None, you have to look up the answer yourself |
179 | | - |
180 | | - # Proctoring |
181 | | - enable_proctored_exams = models.BooleanField(default=False) |
182 | | - proctoring_provider = models.TextField(null=True) |
183 | | - proctoring_escalation_email = models.TextField(null=True) |
184 | | - allow_proctoring_opt_out = models.BooleanField(default=False) |
185 | | - |
186 | | - # Entrance Exam information |
187 | | - entrance_exam_enabled = models.BooleanField(default=False) |
188 | | - entrance_exam_id = models.CharField(max_length=255, blank=True) |
189 | | - entrance_exam_minimum_score_pct = models.FloatField(default=0.65) |
190 | | - |
191 | | - # Open Response Assessment configuration |
192 | | - force_on_flexible_peer_openassessments = models.BooleanField(default=False) |
193 | | - |
194 | | - external_id = models.CharField(max_length=128, null=True, blank=True) |
195 | | - |
196 | | - language = models.TextField(null=True) |
| 109 | + |
| 110 | + @classmethod |
| 111 | + def get_from_id(cls, course_key): |
| 112 | + """Get a CourseOverview by its course key. |
| 113 | +
|
| 114 | + Args: |
| 115 | + course_key: The course key to look up. |
| 116 | +
|
| 117 | + Returns: |
| 118 | + CourseOverview: The course overview instance. |
| 119 | + """ |
| 120 | + if course_key is None: |
| 121 | + raise ValueError("course_key must not be None") |
| 122 | + try: |
| 123 | + key = str(CourseKey.from_string(str(course_key))) |
| 124 | + except Exception: # pylint: disable=broad-exception-caught |
| 125 | + key = str(course_key) |
| 126 | + obj, _ = cls.objects.get_or_create(id=key) |
| 127 | + return obj |
0 commit comments