Commit 1bd2ec25 by Peter Fogg

Merge pull request #12474 from edx/peter-fogg/date-summary-fixes

Fixes for courseware date formatting/translation.
parents 73806bee 80bfa36d
...@@ -8,6 +8,7 @@ from datetime import datetime ...@@ -8,6 +8,7 @@ from datetime import datetime
from babel.dates import format_timedelta from babel.dates import format_timedelta
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from django.utils.translation import to_locale, get_language from django.utils.translation import to_locale, get_language
from edxmako.shortcuts import render_to_string from edxmako.shortcuts import render_to_string
from lazy import lazy from lazy import lazy
...@@ -51,7 +52,7 @@ class DateSummary(object): ...@@ -51,7 +52,7 @@ class DateSummary(object):
The format to display this date in. By default, displays like Jan The format to display this date in. By default, displays like Jan
01, 2015. 01, 2015.
""" """
return '%b %d, %Y' return u'%b %d, %Y'
@property @property
def link(self): def link(self):
...@@ -107,7 +108,7 @@ class DateSummary(object): ...@@ -107,7 +108,7 @@ class DateSummary(object):
# 'absolute'. For example, 'absolute' might be "Jan 01, 2020", # 'absolute'. For example, 'absolute' might be "Jan 01, 2020",
# and if today were December 5th, 2020, 'relative' would be "1 # and if today were December 5th, 2020, 'relative' would be "1
# month". # month".
date_format = _("{relative} ago - {absolute}") if date_has_passed else _("in {relative} - {absolute}") date_format = _(u"{relative} ago - {absolute}") if date_has_passed else _(u"in {relative} - {absolute}")
return date_format.format( return date_format.format(
relative=relative_date, relative=relative_date,
absolute=self.date.strftime(self.date_format), absolute=self.date.strftime(self.date_format),
...@@ -126,7 +127,7 @@ class DateSummary(object): ...@@ -126,7 +127,7 @@ class DateSummary(object):
return False return False
def __repr__(self): def __repr__(self):
return 'DateSummary: "{title}" {date} is_enabled={is_enabled}'.format( return u'DateSummary: "{title}" {date} is_enabled={is_enabled}'.format(
title=self.title, title=self.title,
date=self.date, date=self.date,
is_enabled=self.is_enabled is_enabled=self.is_enabled
...@@ -139,7 +140,10 @@ class TodaysDate(DateSummary): ...@@ -139,7 +140,10 @@ class TodaysDate(DateSummary):
""" """
css_class = 'todays-date' css_class = 'todays-date'
is_enabled = True is_enabled = True
date_format = '%b %d, %Y (%H:%M {utc})'.format(utc=_('UTC'))
@property
def date_format(self):
return u'%b %d, %Y (%H:%M {utc})'.format(utc=_('UTC'))
# The date is shown in the title, no need to display it again. # The date is shown in the title, no need to display it again.
def get_context(self): def get_context(self):
...@@ -153,7 +157,7 @@ class TodaysDate(DateSummary): ...@@ -153,7 +157,7 @@ class TodaysDate(DateSummary):
@property @property
def title(self): def title(self):
return _('Today is {date}').format(date=datetime.now(pytz.UTC).strftime(self.date_format)) return _(u'Today is {date}').format(date=datetime.now(pytz.UTC).strftime(self.date_format))
class CourseStartDate(DateSummary): class CourseStartDate(DateSummary):
...@@ -161,7 +165,7 @@ class CourseStartDate(DateSummary): ...@@ -161,7 +165,7 @@ class CourseStartDate(DateSummary):
Displays the start date of the course. Displays the start date of the course.
""" """
css_class = 'start-date' css_class = 'start-date'
title = _('Course Starts') title = ugettext_lazy('Course Starts')
@property @property
def date(self): def date(self):
...@@ -173,7 +177,7 @@ class CourseEndDate(DateSummary): ...@@ -173,7 +177,7 @@ class CourseEndDate(DateSummary):
Displays the end date of the course. Displays the end date of the course.
""" """
css_class = 'end-date' css_class = 'end-date'
title = _('Course End') title = ugettext_lazy('Course End')
@property @property
def is_enabled(self): def is_enabled(self):
...@@ -200,12 +204,12 @@ class VerifiedUpgradeDeadlineDate(DateSummary): ...@@ -200,12 +204,12 @@ class VerifiedUpgradeDeadlineDate(DateSummary):
Verified track. Verified track.
""" """
css_class = 'verified-upgrade-deadline' css_class = 'verified-upgrade-deadline'
title = _('Verification Upgrade Deadline') title = ugettext_lazy('Verification Upgrade Deadline')
description = _( description = ugettext_lazy(
'You are still eligible to upgrade to a Verified Certificate! ' 'You are still eligible to upgrade to a Verified Certificate! '
'Pursue it to highlight the knowledge and skills you gain in this course.' 'Pursue it to highlight the knowledge and skills you gain in this course.'
) )
link_text = _('Upgrade to Verified Certificate') link_text = ugettext_lazy('Upgrade to Verified Certificate')
@property @property
def link(self): def link(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment