|
8 | 8 | from opaque_keys.edx.keys import CourseKey |
9 | 9 |
|
10 | 10 | from xmodule.modulestore.django import modulestore |
| 11 | +from xmodule.tabs import CourseTabList |
| 12 | + |
| 13 | +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview, CourseTab |
11 | 14 |
|
12 | | -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview |
13 | 15 | from openedx.core.djangoapps.course_apps.plugins import CourseApp |
14 | 16 | from openedx.core.lib.courses import get_course_by_id |
15 | 17 |
|
@@ -65,6 +67,58 @@ def get_allowed_operations(cls, course_key: CourseKey, user: Optional[User] = No |
65 | 67 | } |
66 | 68 |
|
67 | 69 |
|
| 70 | +class DatesCourseApp(CourseApp): |
| 71 | + """Course app stub for course dates.""" |
| 72 | + |
| 73 | + app_id = "dates" |
| 74 | + name = _("Dates") |
| 75 | + description = _("Provide learners a summary of important course dates.") |
| 76 | + documentation_links = { |
| 77 | + "learn_more_configuration": getattr(settings, "DATES_HELP_URL", ""), |
| 78 | + } |
| 79 | + |
| 80 | + @classmethod |
| 81 | + def is_available(cls, course_key: CourseKey) -> bool: # pylint: disable=unused-argument |
| 82 | + """ |
| 83 | + Dates app is available when explicitly enabled via settings. |
| 84 | + """ |
| 85 | + return settings.ENABLE_DATES_COURSE_APP |
| 86 | + |
| 87 | + @classmethod |
| 88 | + def is_enabled(cls, course_key: CourseKey) -> bool: |
| 89 | + """ |
| 90 | + The dates course status is stored in the course block. |
| 91 | + """ |
| 92 | + course = get_course_by_id(course_key) |
| 93 | + dates_tab = CourseTabList.get_tab_by_id(course.tabs, 'dates') |
| 94 | + return bool(dates_tab and not dates_tab.is_hidden) |
| 95 | + |
| 96 | + @classmethod |
| 97 | + def set_enabled(cls, course_key: CourseKey, enabled: bool, user: 'User') -> bool: |
| 98 | + """ |
| 99 | + The dates course enabled/disabled status is stored in the course block. |
| 100 | + """ |
| 101 | + course = get_course_by_id(course_key) |
| 102 | + dates_tab = CourseTabList.get_tab_by_id(course.tabs, 'dates') |
| 103 | + if enabled and dates_tab is None: |
| 104 | + dates_tab = CourseTab.load("dates") |
| 105 | + course.tabs.append(dates_tab) |
| 106 | + if dates_tab is not None: |
| 107 | + dates_tab.is_hidden = not enabled |
| 108 | + modulestore().update_item(course, user.id) |
| 109 | + return enabled |
| 110 | + |
| 111 | + @classmethod |
| 112 | + def get_allowed_operations(cls, course_key: CourseKey, user: Optional[User] = None) -> Dict[str, bool]: # pylint: disable=unused-argument |
| 113 | + """ |
| 114 | + Returns the allowed operations for the app. |
| 115 | + """ |
| 116 | + return { |
| 117 | + "enable": True, |
| 118 | + "configure": True, |
| 119 | + } |
| 120 | + |
| 121 | + |
68 | 122 | class TextbooksCourseApp(CourseApp): |
69 | 123 | """ |
70 | 124 | Course app config for textbooks app. |
|
0 commit comments