diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index da6e88153c..4d3a84c6ee 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -294,18 +294,7 @@ def get_course_info_section(request, user, course, section_key): return html -def get_course_date_summary(course, user): - """ - Return the snippet of HTML to be included on the course info page - in the 'Date Summary' section. - """ - blocks = _get_course_date_summary_blocks(course, user) - return '\n'.join( - b.render() for b in blocks - ) - - -def _get_course_date_summary_blocks(course, user): +def get_course_date_blocks(course, user): """ Return the list of blocks to display on the course info page, sorted by date. diff --git a/lms/djangoapps/courseware/date_summary.py b/lms/djangoapps/courseware/date_summary.py index e6aaf5524f..c0f92b92a8 100644 --- a/lms/djangoapps/courseware/date_summary.py +++ b/lms/djangoapps/courseware/date_summary.py @@ -11,14 +11,12 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy from django.utils.translation import to_locale, get_language -from edxmako.shortcuts import render_to_string from lazy import lazy from course_modes.models import CourseMode from lms.djangoapps.commerce.utils import EcommerceService from lms.djangoapps.verify_student.models import VerificationDeadline, SoftwareSecurePhotoVerification from student.models import CourseEnrollment -from openedx.core.lib.time_zone_utils import get_time_zone_abbr class DateSummary(object): @@ -78,24 +76,8 @@ class DateSummary(object): self.course = course self.user = user - def get_context(self): - """Return the template context used to render this summary block.""" - return { - 'title': self.title, - 'date': self._format_date(), - 'description': self.description, - 'css_class': self.css_class, - 'link': self.link, - 'link_text': self.link_text, - } - - def render(self): - """ - Return an HTML representation of this summary block. - """ - return render_to_string('courseware/date_summary.html', self.get_context()) - - def _format_date(self): + @property + def relative_datestring(self): """ Return this block's date in a human-readable format. If the date is None, returns the empty string. @@ -121,7 +103,7 @@ class DateSummary(object): date_format = _(u"{relative} ago - {absolute}") if date_has_passed else _(u"in {relative} - {absolute}") return date_format.format( relative=relative_date, - absolute=self.date.astimezone(self.time_zone).strftime(self.date_format.encode('utf-8')).decode('utf-8'), + absolute='{date}', ) @property @@ -151,10 +133,6 @@ class TodaysDate(DateSummary): css_class = 'todays-date' is_enabled = True - @property - def date_format(self): - return u'%b %d, %Y (%H:%M {tz_abbr})'.format(tz_abbr=get_time_zone_abbr(self.time_zone)) - # The date is shown in the title, no need to display it again. def get_context(self): context = super(TodaysDate, self).get_context() @@ -167,9 +145,7 @@ class TodaysDate(DateSummary): @property def title(self): - return _(u'Today is {date}').format( - date=self.date.astimezone(self.time_zone).strftime(self.date_format.encode('utf-8')).decode('utf-8') - ) + return 'current_datetime' class CourseStartDate(DateSummary): diff --git a/lms/djangoapps/courseware/tests/test_date_summary.py b/lms/djangoapps/courseware/tests/test_date_summary.py index 7676a9367b..ec123683b4 100644 --- a/lms/djangoapps/courseware/tests/test_date_summary.py +++ b/lms/djangoapps/courseware/tests/test_date_summary.py @@ -11,7 +11,7 @@ from pytz import utc from commerce.models import CommerceConfiguration from course_modes.tests.factories import CourseModeFactory from course_modes.models import CourseMode -from courseware.courses import _get_course_date_summary_blocks +from courseware.courses import get_course_date_blocks from courseware.date_summary import ( CourseEndDate, CourseStartDate, @@ -55,7 +55,7 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase): self.course = CourseFactory.create( # pylint: disable=attribute-defined-outside-init start=now + timedelta(days=days_till_start) ) - self.user = UserFactory.create() # pylint: disable=attribute-defined-outside-init + self.user = UserFactory.create(username='mrrobot', password='test') # pylint: disable=attribute-defined-outside-init if days_till_end is not None: self.course.end = now + timedelta(days=days_till_end) @@ -92,10 +92,9 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase): self.assertNotIn('date-summary', response.content) # Tests for which blocks are enabled - def assert_block_types(self, expected_blocks): """Assert that the enabled block types for this course are as expected.""" - blocks = _get_course_date_summary_blocks(self.course, self.user) + blocks = get_course_date_blocks(self.course, self.user) self.assertEqual(len(blocks), len(expected_blocks)) self.assertEqual(set(type(b) for b in blocks), set(expected_blocks)) @@ -163,64 +162,58 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase): self.setup_course_and_user(**course_options) self.assert_block_types(expected_blocks) - # Specific block type tests - - ## Base DateSummary -- test empty defaults - - def test_date_summary(self): - self.setup_course_and_user() - block = DateSummary(self.course, self.user) - html = '
${description}
- % endif - % if link and link_text: - - ${link_text} - - % endif -${course_date.description}
+ % endif + % if course_date.link and course_date.link_text: + + ${course_date.link_text} + + % endif +