Files
edx-platform/openedx/features/course_experience/plugins.py
stvn 43698fff0a refactor: Move get_course_by_id helper from LMS to core
This helper is used by the LMS, CMS, _and_ `openedx.core`,
so let's move it to `openedx.core` to reduce import complexity.

The following files no longer import from LMS:
- cms/djangoapps/contentstore/management/commands/edit_course_tabs.py
- lms/djangoapps/ccx/migrations/0006_set_display_name_as_override.py
- openedx/core/djangoapps/ccxcon/api.py
- openedx/core/djangoapps/verified_track_content/models.py
- openedx/features/course_experience/plugins.py

Note: The LTI XBlock has a dependency on this import path (!?);
a fix can be found here [1].

- [1] https://github.com/edx/xblock-lti-consumer/pull/154
2021-04-13 23:25:48 -07:00

62 lines
1.8 KiB
Python

"""
Platform plugins to support the course experience.
This includes any locally defined CourseTools.
"""
from django.urls import reverse
from django.utils.translation import ugettext as _
from common.djangoapps.student.models import CourseEnrollment
from openedx.core.lib.courses import get_course_by_id
from . import DISABLE_UNIFIED_COURSE_TAB_FLAG
from .course_tools import CourseTool
from .views.course_updates import CourseUpdatesFragmentView
class CourseUpdatesTool(CourseTool):
"""
The course updates tool.
"""
@classmethod
def analytics_id(cls):
"""
Returns an analytics id for this tool, used for eventing.
"""
return 'edx.updates'
@classmethod
def title(cls): # lint-amnesty, pylint: disable=arguments-differ
"""
Returns the title of this tool.
"""
return _('Updates')
@classmethod
def icon_classes(cls): # lint-amnesty, pylint: disable=arguments-differ
"""
Returns icon classes needed to represent this tool.
"""
return 'fa fa-newspaper-o'
@classmethod
def is_enabled(cls, request, course_key):
"""
Returns True if the user should be shown course updates for this course.
"""
if DISABLE_UNIFIED_COURSE_TAB_FLAG.is_enabled(course_key):
return False
if not CourseEnrollment.is_enrolled(request.user, course_key):
return False
course = get_course_by_id(course_key)
return CourseUpdatesFragmentView.has_updates(request, course)
@classmethod
def url(cls, course_key):
"""
Returns the URL for this tool for the specified course key.
"""
return reverse('openedx.course_experience.course_updates', args=[course_key])