AA-234: Switch link in dates widget if Course Home MFE is active
This commit is contained in:
@@ -13,7 +13,7 @@ from django.utils.translation import ugettext as _
|
||||
% for course_date_block in course_date_blocks:
|
||||
<%include file="dates-summary.html" args="course_date=course_date_block" />
|
||||
% endfor
|
||||
% if user_enrolled:
|
||||
% if dates_tab_enabled:
|
||||
<div class="dates-tab-link">
|
||||
<a href="${dates_tab_link}">View all course dates</a>
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,9 @@ from web_fragments.fragment import Fragment
|
||||
|
||||
from lms.djangoapps.courseware.access import has_access
|
||||
from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access
|
||||
from lms.djangoapps.courseware.tabs import DatesTab
|
||||
from lms.djangoapps.course_home_api.toggles import course_home_mfe_dates_tab_is_active
|
||||
from lms.djangoapps.course_home_api.utils import get_microfrontend_url
|
||||
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
|
||||
from student.models import CourseEnrollment
|
||||
|
||||
@@ -29,16 +32,17 @@ class CourseDatesFragmentView(EdxFragmentView):
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=False)
|
||||
course_date_blocks = get_course_date_blocks(course, request.user, request, num_assignments=1)
|
||||
# We will use this boolean to gate if we show a link to the dates tab. This same logic
|
||||
# dictates if we show the tab at all.
|
||||
user_enrolled = (request.user and request.user.is_authenticated and
|
||||
(bool(CourseEnrollment.is_enrolled(request.user, course.id) or
|
||||
has_access(request.user, 'staff', course, course.id))))
|
||||
|
||||
dates_tab_enabled = DatesTab.is_enabled(course, request.user)
|
||||
if course_home_mfe_dates_tab_is_active(course_key):
|
||||
dates_tab_link = get_microfrontend_url(course_key=course.id, view_name='dates')
|
||||
else:
|
||||
dates_tab_link = reverse('dates', args=[course.id])
|
||||
|
||||
context = {
|
||||
'course_date_blocks': [block for block in course_date_blocks if block.title != 'current_datetime'],
|
||||
'dates_tab_link': reverse('dates', args=[course.id]),
|
||||
'user_enrolled': user_enrolled,
|
||||
'dates_tab_link': dates_tab_link,
|
||||
'dates_tab_enabled': dates_tab_enabled,
|
||||
}
|
||||
html = render_to_string(self.template_name, context)
|
||||
dates_fragment = Fragment(html)
|
||||
|
||||
Reference in New Issue
Block a user