|
34 | 34 | from django.utils.translation import gettext as _ |
35 | 35 | from django.views.decorators.csrf import ensure_csrf_cookie |
36 | 36 | from django.views.decorators.http import require_http_methods |
| 37 | +from common.djangoapps.course_modes.models import CourseMode |
37 | 38 | from eventtracking import tracker |
38 | 39 | from opaque_keys import InvalidKeyError |
39 | 40 | from opaque_keys.edx.keys import AssetKey, CourseKey |
@@ -271,6 +272,28 @@ def get_certificates(course, only_active=False): |
271 | 272 | certificates = [certificate for certificate in certificates if certificate.get('is_active', False)] |
272 | 273 | return certificates |
273 | 274 |
|
| 275 | + @staticmethod |
| 276 | + def get_course_modes(course): |
| 277 | + """ |
| 278 | + Retrieve certificate modes for the given course, |
| 279 | + including expired modes but excluding audit mode. |
| 280 | + """ |
| 281 | + course_modes = [ |
| 282 | + mode.slug for mode in CourseMode.modes_for_course( |
| 283 | + course=course, include_expired=True |
| 284 | + ) if mode.slug != CourseMode.AUDIT |
| 285 | + ] |
| 286 | + return course_modes |
| 287 | + |
| 288 | + @staticmethod |
| 289 | + def is_enabled(course): |
| 290 | + """ |
| 291 | + Is enabled when there is at least one course mode for the given course, |
| 292 | + including expired modes but excluding audit mode |
| 293 | + """ |
| 294 | + course_modes = CertificateManager.get_course_modes(course) |
| 295 | + return len(course_modes) > 0 |
| 296 | + |
274 | 297 | @staticmethod |
275 | 298 | def remove_certificate(request, store, course, certificate_id): |
276 | 299 | """ |
|
0 commit comments