From 1aff229007cbc39bbc4854a96b3d80f192c5bd26 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 17 Nov 2016 16:19:43 -0500 Subject: [PATCH] Localize Times in verify_student Now using the DateUtils javascript to handle this more correctly in webpages. TNL-5959 --- .../verify_student/tests/test_views.py | 8 ++--- lms/djangoapps/verify_student/views.py | 10 ++---- .../make_payment_step_view_spec.js | 19 ++++++----- .../js/verify_student/pay_and_verify.js | 2 ++ .../views/make_payment_step_view.js | 2 ++ .../make_payment_step.underscore | 11 +++--- .../make_payment_step_ab_testing.underscore | 11 +++--- .../verify_student/missed_deadline.html | 34 +++++++++++++------ .../verify_student/pay_and_verify.html | 5 +++ 9 files changed, 62 insertions(+), 40 deletions(-) diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index c665f07891..36fb41caa5 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -725,7 +725,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin): # Expect that the expiration date is set response = self._get_page(payment_flow, course.id) data = self._get_page_data(response) - self.assertEqual(data['verification_deadline'], deadline.strftime("%b %d, %Y at %H:%M UTC")) + self.assertEqual(data['verification_deadline'], unicode(deadline)) def test_course_mode_expired(self): deadline = datetime.now(tz=pytz.UTC) + timedelta(days=-360) @@ -743,7 +743,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin): # to the student that the deadline has passed response = self._get_page("verify_student_verify_now", course.id) self.assertContains(response, "verification deadline") - self.assertContains(response, deadline.strftime("%b %d, %Y at %H:%M UTC")) + self.assertContains(response, deadline) @ddt.data(datetime.now(tz=pytz.UTC) + timedelta(days=360), None) def test_course_mode_expired_verification_deadline_in_future(self, verification_deadline): @@ -792,7 +792,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin): # Check that the verification deadline (rather than the upgrade deadline) is displayed if verification_deadline is not None: - self.assertEqual(data["verification_deadline"], verification_deadline.strftime("%b %d, %Y at %H:%M UTC")) + self.assertEqual(data["verification_deadline"], unicode(verification_deadline)) else: self.assertEqual(data["verification_deadline"], "") @@ -821,7 +821,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin): # message when we go to verify. response = self._get_page("verify_student_verify_now", course.id) self.assertContains(response, "verification deadline") - self.assertContains(response, verification_deadline_in_past.strftime("%b %d, %Y at %H:%M UTC")) + self.assertContains(response, verification_deadline_in_past) @mock.patch.dict(settings.FEATURES, {'EMBARGO': True}) @ddt.data("verify_student_start_flow", "verify_student_begin_flow") diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 05889e5475..2366c3ebfe 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -424,10 +424,7 @@ class PayAndVerifyView(View): 'processors': processors, 'requirements': requirements, 'user_full_name': full_name, - 'verification_deadline': ( - get_default_time_display(verification_deadline) - if verification_deadline else "" - ), + 'verification_deadline': verification_deadline or "", 'already_verified': already_verified, 'verification_good_until': verification_good_until, 'capture_sound': staticfiles_storage.url("audio/camera_capture.wav"), @@ -697,10 +694,7 @@ class PayAndVerifyView(View): context = { 'course': course, 'deadline_name': deadline_name, - 'deadline': ( - get_default_time_display(deadline_datetime) - if deadline_datetime else "" - ) + 'deadline': deadline_datetime } return render_to_response("verify_student/missed_deadline.html", context) diff --git a/lms/static/js/spec/verify_student/make_payment_step_view_spec.js b/lms/static/js/spec/verify_student/make_payment_step_view_spec.js index aea5720205..4f9fa9504c 100644 --- a/lms/static/js/spec/verify_student/make_payment_step_view_spec.js +++ b/lms/static/js/spec/verify_student/make_payment_step_view_spec.js @@ -142,25 +142,26 @@ define([ }); it('view containing verification msg when verification deadline is set and user is active', function() { - var verificationDeadlineDateFormat = 'Aug 14, 2016 at 23:59 UTC'; + var verificationDeadline = '2016-08-14 23:59:00+00:00'; createView({ userEmail: 'test@example.com', + userTimezone: 'PDT', + userLanguage: 'es-ES', requirements: { isVisible: true }, - verificationDeadline: verificationDeadlineDateFormat, + verificationDeadline: verificationDeadline, isActive: true }); // Verify user does not get user activation message when he is already activated. expect($('p.instruction-info:contains("test@example.com")').length).toEqual(0); // Verify user gets verification message. - expect( - $( - 'p.instruction-info:contains("You can pay now even if you don\'t have ' + - 'the following items available, but you will need to have these by ' + - verificationDeadlineDateFormat + ' to qualify to earn a Verified Certificate.")' - ).length - ).toEqual(1); + expect($('p.localized-datetime').attr('data-string')).toEqual( + 'You can pay now even if you don\'t have the following items available,' + + ' but you will need to have these by {date} to qualify to earn a Verified Certificate.' + ); + expect($('p.localized-datetime').attr('data-timezone')).toEqual('PDT'); + expect($('p.localized-datetime').attr('data-language')).toEqual('es-ES'); }); it('view containing user email when verification deadline is set and user is not active', function() { diff --git a/lms/static/js/verify_student/pay_and_verify.js b/lms/static/js/verify_student/pay_and_verify.js index 19b97b23de..fed1aa72cf 100644 --- a/lms/static/js/verify_student/pay_and_verify.js +++ b/lms/static/js/verify_student/pay_and_verify.js @@ -50,6 +50,8 @@ var edx = edx || {}; courseKey: el.data('course-key'), courseName: el.data('course-name'), userEmail: el.data('user-email'), + userLanguage: el.data('user-language'), + userTimezone: el.data('user-timezone'), hasVisibleReqs: _.some( el.data('requirements'), function(isVisible) { return isVisible; } diff --git a/lms/static/js/verify_student/views/make_payment_step_view.js b/lms/static/js/verify_student/views/make_payment_step_view.js index 3e9eb7e532..d05058576a 100644 --- a/lms/static/js/verify_student/views/make_payment_step_view.js +++ b/lms/static/js/verify_student/views/make_payment_step_view.js @@ -30,6 +30,8 @@ var edx = edx || {}; currency: 'usd', upgrade: false, verificationDeadline: '', + userTimezone: 'UTC', + userLanguage: 'en-US', courseName: '', requirements: {}, hasVisibleReqs: false, diff --git a/lms/templates/verify_student/make_payment_step.underscore b/lms/templates/verify_student/make_payment_step.underscore index e0ec692e42..65896a5971 100644 --- a/lms/templates/verify_student/make_payment_step.underscore +++ b/lms/templates/verify_student/make_payment_step.underscore @@ -31,10 +31,13 @@ <% if ( _.some( requirements, function( isVisible ) { return isVisible; } ) ) { %>

<% if ( verificationDeadline && isActive) { %> - <%- _.sprintf( - gettext( "You can pay now even if you don't have the following items available, but you will need to have these by %(date)s to qualify to earn a Verified Certificate." ), - { date: verificationDeadline } - ) %> +

" + data-timezone="<%-userTimezone%>" + data-language="<%-userLanguage%>" + > <% } else if ( !isActive ) { %> <%= HtmlUtils.interpolateHtml( diff --git a/lms/templates/verify_student/make_payment_step_ab_testing.underscore b/lms/templates/verify_student/make_payment_step_ab_testing.underscore index 70c461d691..f8cc961a54 100644 --- a/lms/templates/verify_student/make_payment_step_ab_testing.underscore +++ b/lms/templates/verify_student/make_payment_step_ab_testing.underscore @@ -74,10 +74,13 @@ <% if ( _.some( requirements, function( isVisible ) { return isVisible; } ) ) { %>

<% if ( verificationDeadline ) { %> - <%- _.sprintf( - gettext( "To receive a certificate, you must also verify your identity before %(date)s." ), - { date: verificationDeadline } - ) %> +

" + data-timezone="<%-userTimezone%>" + data-language="<%-userLanguage%>" + > <% } else { %> <%- gettext( "To receive a certificate, you must also verify your identity." ) %> <% } %> diff --git a/lms/templates/verify_student/missed_deadline.html b/lms/templates/verify_student/missed_deadline.html index 4c2f7f950b..f9272a53bd 100644 --- a/lms/templates/verify_student/missed_deadline.html +++ b/lms/templates/verify_student/missed_deadline.html @@ -16,15 +16,27 @@ from lms.djangoapps.verify_student.views import PayAndVerifyView <%block name="content"> -

-

- - % if deadline_name == PayAndVerifyView.VERIFICATION_DEADLINE: - ${_(u"The verification deadline for {course_name} was {date}. Verification is no longer available.").format( - course_name=course.display_name, date=deadline)} - % elif deadline_name == PayAndVerifyView.UPGRADE_DEADLINE: - ${_(u"The deadline to upgrade to a verified certificate for this course has passed.")} - % endif -

-
+
+

+

+
+<%static:require_module_async module_name="js/dateutil_factory" class_name="DateUtilFactory"> + DateUtilFactory.transform(iterationKey=".localized-datetime"); + diff --git a/lms/templates/verify_student/pay_and_verify.html b/lms/templates/verify_student/pay_and_verify.html index 5e497cec57..a60f7a4ae6 100644 --- a/lms/templates/verify_student/pay_and_verify.html +++ b/lms/templates/verify_student/pay_and_verify.html @@ -82,6 +82,8 @@ from lms.djangoapps.verify_student.views import PayAndVerifyView data-msg-key='${message_key}' data-is-active='${is_active}' data-user-email='${user_email}' + data-user-language='${user_language}' + data-user-timezone='${user_timezone}' data-already-verified='${already_verified}' data-verification-good-until='${verification_good_until}' data-capture-sound='${capture_sound}' @@ -122,3 +124,6 @@ from lms.djangoapps.verify_student.views import PayAndVerifyView +<%static:require_module_async module_name="js/dateutil_factory" class_name="DateUtilFactory"> + DateUtilFactory.transform(iterationKey=".localized-datetime"); +