Add new course dates fragment.
Also add it to the course home page.
This commit is contained in:
committed by
Andy Armstrong
parent
97c084514f
commit
e12a704cea
@@ -17,7 +17,6 @@ FROZEN_TIME = '2015-01-01'
|
||||
VERIFY_STUDENT = {'DAYS_GOOD_FOR': 365}
|
||||
|
||||
|
||||
@freezegun.freeze_time(FROZEN_TIME)
|
||||
@override_settings(VERIFY_STUDENT=VERIFY_STUDENT)
|
||||
class PhotoVerificationStatusViewTests(TestCase):
|
||||
""" Tests for the PhotoVerificationStatusView endpoint. """
|
||||
@@ -25,6 +24,10 @@ class PhotoVerificationStatusViewTests(TestCase):
|
||||
PASSWORD = 'test'
|
||||
|
||||
def setUp(self):
|
||||
freezer = freezegun.freeze_time(FROZEN_TIME)
|
||||
freezer.start()
|
||||
self.addCleanup(freezer.stop)
|
||||
|
||||
super(PhotoVerificationStatusViewTests, self).setUp()
|
||||
self.user = UserFactory(password=self.PASSWORD)
|
||||
self.staff = UserFactory(is_staff=True, password=self.PASSWORD)
|
||||
|
||||
@@ -44,38 +44,38 @@ class TestTimeZoneUtils(TestCase):
|
||||
self.assertEqual(display_tz_info['abbr'], expected_abbr)
|
||||
self.assertEqual(display_tz_info['offset'], expected_offset)
|
||||
|
||||
@freeze_time("2015-02-09")
|
||||
def test_display_time_zone_without_dst(self):
|
||||
"""
|
||||
Test to ensure get_display_time_zone() returns full display string when no kwargs specified
|
||||
and returns just abbreviation or offset when specified
|
||||
"""
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PST', '-0800')
|
||||
with freeze_time("2015-02-09"):
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PST', '-0800')
|
||||
|
||||
@freeze_time("2015-04-02")
|
||||
def test_display_time_zone_with_dst(self):
|
||||
"""
|
||||
Test to ensure get_display_time_zone() returns modified abbreviations and
|
||||
offsets during daylight savings time.
|
||||
"""
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PDT', '-0700')
|
||||
with freeze_time("2015-04-02"):
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PDT', '-0700')
|
||||
|
||||
@freeze_time("2015-11-01 08:59:00")
|
||||
def test_display_time_zone_ambiguous_before(self):
|
||||
"""
|
||||
Test to ensure get_display_time_zone() returns correct abbreviations and offsets
|
||||
during ambiguous time periods (e.g. when DST is about to start/end) before the change
|
||||
"""
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PDT', '-0700')
|
||||
with freeze_time("2015-11-01 08:59:00"):
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PDT', '-0700')
|
||||
|
||||
@freeze_time("2015-11-01 09:00:00")
|
||||
def test_display_time_zone_ambiguous_after(self):
|
||||
"""
|
||||
Test to ensure get_display_time_zone() returns correct abbreviations and offsets
|
||||
during ambiguous time periods (e.g. when DST is about to start/end) after the change
|
||||
"""
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PST', '-0800')
|
||||
with freeze_time("2015-11-01 09:00:00"):
|
||||
tz_info = self._display_time_zone_helper('America/Los_Angeles')
|
||||
self._assert_time_zone_info_equal(tz_info, 'America/Los Angeles', 'PST', '-0800')
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
## mako
|
||||
|
||||
<%page expression_filter="h"/>
|
||||
|
||||
<%namespace name='static' file='../static_content.html'/>
|
||||
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
%>
|
||||
<h3 class="hd hd-6 handouts-header">${_("Important Course Dates")}</h3>
|
||||
## Should be organized by date, last date appearing at the bottom
|
||||
|
||||
% for course_date in course_date_blocks:
|
||||
<div class="date-summary-container">
|
||||
<div class="date-summary date-summary-${course_date.css_class}">
|
||||
% if course_date.title:
|
||||
% if course_date.title == 'current_datetime':
|
||||
<span class="hd hd-6 heading localized-datetime" data-datetime="${course_date.date}" data-string="${_(u'Today is {date}')}" data-timezone="${user_timezone}" data-language="${user_language}"></span>
|
||||
% else:
|
||||
<span class="hd hd-6 heading">${course_date.title}</span>
|
||||
% endif
|
||||
% endif
|
||||
% if course_date.date and course_date.title != 'current_datetime':
|
||||
<p class="hd hd-6 date localized-datetime" data-format="shortDate" data-datetime="${course_date.date}" data-timezone="${user_timezone}" data-language="${user_language}" data-string="${_(course_date.relative_datestring)}"></p>
|
||||
% endif
|
||||
% if course_date.description:
|
||||
<p class="description">${course_date.description}</p>
|
||||
% endif
|
||||
% if course_date.link and course_date.link_text:
|
||||
<span class="date-summary-link">
|
||||
<a href="${course_date.link}">${course_date.link_text}</a>
|
||||
</span>
|
||||
% endif
|
||||
</div>
|
||||
</div>
|
||||
% endfor
|
||||
@@ -90,6 +90,9 @@ from openedx.features.course_experience import UNIFIED_COURSE_EXPERIENCE_FLAG
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section section-dates">
|
||||
${HTML(dates_fragment.body_html())}
|
||||
</div>
|
||||
% if handouts_html:
|
||||
<div class="section section-handouts">
|
||||
<h3 class="hd-6">${_("Course Handouts")}</h3>
|
||||
|
||||
@@ -65,7 +65,7 @@ class TestCourseHomePage(SharedModuleStoreTestCase):
|
||||
get_course_in_cache(self.course.id)
|
||||
|
||||
# Fetch the view and verify the query counts
|
||||
with self.assertNumQueries(35):
|
||||
with self.assertNumQueries(37):
|
||||
with check_mongo_calls(3):
|
||||
url = course_home_url(self.course)
|
||||
self.client.get(url)
|
||||
|
||||
27
openedx/features/course_experience/views/course_dates.py
Normal file
27
openedx/features/course_experience/views/course_dates.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
Fragment for rendering the course dates sidebar.
|
||||
"""
|
||||
from django.template.loader import render_to_string
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from web_fragments.fragment import Fragment
|
||||
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
|
||||
from courseware.courses import get_course_with_access, get_course_date_blocks
|
||||
|
||||
|
||||
class CourseDatesFragmentView(EdxFragmentView):
|
||||
"""
|
||||
A fragment to important dates within a course.
|
||||
"""
|
||||
def render_to_fragment(self, request, course_id=None, **kwargs):
|
||||
"""
|
||||
Render the course dates fragment.
|
||||
"""
|
||||
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)
|
||||
|
||||
context = {
|
||||
'course_date_blocks': course_date_blocks
|
||||
}
|
||||
html = render_to_string('course_experience/course-dates-fragment.html', context)
|
||||
return Fragment(html)
|
||||
@@ -17,6 +17,7 @@ from util.views import ensure_valid_course_key
|
||||
from web_fragments.fragment import Fragment
|
||||
|
||||
from .course_outline import CourseOutlineFragmentView
|
||||
from .course_dates import CourseDatesFragmentView
|
||||
from ..utils import get_course_outline_block_tree
|
||||
|
||||
|
||||
@@ -92,6 +93,9 @@ class CourseHomeFragmentView(EdxFragmentView):
|
||||
# Get resume course information
|
||||
has_visited_course, resume_course_url = self._get_resume_course_info(request, course_id)
|
||||
|
||||
# Render the course dates as a fragment
|
||||
dates_fragment = CourseDatesFragmentView().render_to_fragment(request, course_id=course_id, **kwargs)
|
||||
|
||||
# Get the handouts
|
||||
# TODO: Use get_course_overview_with_access and blocks api
|
||||
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
|
||||
@@ -101,10 +105,12 @@ class CourseHomeFragmentView(EdxFragmentView):
|
||||
context = {
|
||||
'csrf': csrf(request)['csrf_token'],
|
||||
'course_key': course_key,
|
||||
'course': course,
|
||||
'outline_fragment': outline_fragment,
|
||||
'handouts_html': handouts_html,
|
||||
'has_visited_course': has_visited_course,
|
||||
'resume_course_url': resume_course_url,
|
||||
'dates_fragment': dates_fragment,
|
||||
'disable_courseware_js': True,
|
||||
'uses_pattern_library': True,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user