Merge pull request #19460 from edx/REVE-186

localize datetime for banner
This commit is contained in:
Matthew Piatetsky
2018-12-18 16:12:58 -05:00
committed by GitHub
3 changed files with 31 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ from django.test import TestCase
from django.test.client import Client, RequestFactory
from django.urls import reverse
from django.utils.timezone import now
from django.utils.translation import get_language
from six import text_type
from courseware.access import has_access
@@ -21,6 +22,7 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOvervi
from openedx.core.lib.url_utils import quote_slashes
from student.models import Registration, CourseEnrollment
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from util.date_utils import strftime_localized
from xblock.field_data import DictFieldData
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, ModuleStoreTestCase
@@ -358,7 +360,7 @@ def get_expiration_banner_text(user, course):
Get text for banner that messages user course expiration date
for different tests that depend on it.
"""
expiration_date = (now() + timedelta(weeks=4)).strftime('%b. %-d, %Y')
expiration_date = now() + timedelta(weeks=4)
upgrade_link = verified_upgrade_deadline_link(user=user, course=course)
enrollment = CourseEnrollment.get_enrollment(user, course.id)
upgrade_deadline = enrollment.upgrade_deadline
@@ -366,13 +368,22 @@ def get_expiration_banner_text(user, course):
return
if now() < upgrade_deadline:
upgrade_deadline = enrollment.course_upgrade_deadline
language = get_language()
if language and language.split('-')[0].lower() == 'es':
formatted_expiration_date = strftime_localized(expiration_date, '%-d de %b. de %Y').lower()
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%-d de %b. de %Y').lower()
else:
formatted_expiration_date = strftime_localized(expiration_date, '%b. %-d, %Y')
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%b. %-d, %Y')
bannerText = '<strong>Audit Access Expires {expiration_date}</strong><br>\
You lose all access to this course, including your progress, on {expiration_date}.<br>\
Upgrade by {upgrade_deadline} to get unlimited access to the course as long as it exists on the site.\
<a href="{upgrade_link}">Upgrade now<span class="sr-only"> to retain access past {expiration_date}\
</span></a>'.format(
expiration_date=expiration_date,
expiration_date=formatted_expiration_date,
upgrade_link=upgrade_link,
upgrade_deadline=upgrade_deadline.strftime('%b. %-d, %Y')
upgrade_deadline=formatted_upgrade_deadline
)
return bannerText

View File

@@ -7,7 +7,7 @@ from datetime import timedelta
from django.apps import apps
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import get_language, ugettext as _
from student.models import CourseEnrollment
from util.date_utils import DEFAULT_SHORT_DATE_FORMAT, strftime_localized
@@ -34,7 +34,11 @@ class AuditExpiredError(AccessError):
def __init__(self, user, course, expiration_date):
error_code = "audit_expired"
developer_message = "User {} had access to {} until {}".format(user, course, expiration_date)
expiration_date = strftime_localized(expiration_date, DEFAULT_SHORT_DATE_FORMAT)
language = get_language()
if language and language.split('-')[0].lower() == 'es':
expiration_date = strftime_localized(expiration_date, '%-d de %b. de %Y').lower()
else:
expiration_date = strftime_localized(expiration_date, '%b. %-d, %Y')
user_message = _("Access expired on {expiration_date}").format(expiration_date=expiration_date)
try:
course_name = CourseOverview.get_from_id(course.id).display_name_with_default
@@ -152,6 +156,14 @@ def register_course_expired_message(request, course):
if now < course_upgrade_deadline:
full_message += upgrade_deadline_message
language = get_language()
if language and language.split('-')[0].lower() == 'es':
formatted_expiration_date = strftime_localized(expiration_date, '%-d de %b. de %Y').lower()
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%-d de %b. de %Y').lower()
else:
formatted_expiration_date = strftime_localized(expiration_date, '%b. %-d, %Y')
formatted_upgrade_deadline = strftime_localized(upgrade_deadline, '%b. %-d, %Y')
PageLevelMessages.register_info_message(
request,
Text(full_message).format(
@@ -162,10 +174,10 @@ def register_course_expired_message(request, course):
sighted_only_span_open=HTML('<span aria-hidden="true">'),
span_close=HTML('</span>'),
a_close=HTML('</a>'),
expiration_date=strftime_localized(expiration_date, '%b. %-d, %Y'),
expiration_date=formatted_expiration_date,
strong_open=HTML('<strong>'),
strong_close=HTML('</strong>'),
line_break=HTML('<br>'),
upgrade_deadline=strftime_localized(upgrade_deadline, '%b. %-d, %Y')
upgrade_deadline=formatted_upgrade_deadline
)
)

View File

@@ -525,7 +525,7 @@ class TestCourseHomePageAccess(CourseHomePageTestCase):
response = self.client.get(url)
expiration_date = strftime_localized(course.start + timedelta(weeks=4), 'SHORT_DATE')
expiration_date = strftime_localized(course.start + timedelta(weeks=4), '%b. %-d, %Y')
expected_params = QueryDict(mutable=True)
course_name = CourseOverview.get_from_id(course.id).display_name_with_default
expected_params['access_response_error'] = 'Access to {run} expired on {expiration_date}'.format(