Commit 1aff2290 by Eric Fischer

Localize Times in verify_student

Now using the DateUtils javascript to handle this more correctly in webpages.

TNL-5959
parent fa705d83
......@@ -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")
......
......@@ -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)
......
......@@ -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() {
......
......@@ -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; }
......
......@@ -30,6 +30,8 @@ var edx = edx || {};
currency: 'usd',
upgrade: false,
verificationDeadline: '',
userTimezone: 'UTC',
userLanguage: 'en-US',
courseName: '',
requirements: {},
hasVisibleReqs: false,
......
......@@ -31,10 +31,13 @@
<% if ( _.some( requirements, function( isVisible ) { return isVisible; } ) ) { %>
<p class="instruction-info">
<% 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 }
) %>
<p
class="localized-datetime"
data-datetime="<%-verificationDeadline%>"
data-string="<%-gettext( "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." )%>"
data-timezone="<%-userTimezone%>"
data-language="<%-userLanguage%>"
>
<% } else if ( !isActive ) { %>
<i class="fa fa-envelope-o" aria-hidden="true"></i>
<%= HtmlUtils.interpolateHtml(
......
......@@ -74,10 +74,13 @@
<% if ( _.some( requirements, function( isVisible ) { return isVisible; } ) ) { %>
<p>
<% if ( verificationDeadline ) { %>
<%- _.sprintf(
gettext( "To receive a certificate, you must also verify your identity before %(date)s." ),
{ date: verificationDeadline }
) %>
<p
class="localized-datetime"
data-datetime="<%-verificationDeadline%>"
data-string="<%-gettext( "To receive a certificate, you must also verify your identity before {date}." )%>"
data-timezone="<%-userTimezone%>"
data-language="<%-userLanguage%>"
>
<% } else { %>
<%- gettext( "To receive a certificate, you must also verify your identity." ) %>
<% } %>
......
......@@ -16,15 +16,27 @@ from lms.djangoapps.verify_student.views import PayAndVerifyView
</%block>
<%block name="content">
<section class="outside-app">
<p>
% 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
</p>
</section>
<section class="outside-app">
<p
class="localized-datetime"
data-datetime="${deadline}"
data-timezone="${user_timezone}"
data-language="${user_language}"
% if deadline_name == PayAndVerifyView.VERIFICATION_DEADLINE:
data-string="${
_(
u'The verification deadline for {course_name} was {{date}}. Verification is no longer available.'
).format(
course_name=course.display_name
)
}"
% elif deadline_name == PayAndVerifyView.UPGRADE_DEADLINE:
data-string="${_(u'The deadline to upgrade to a verified certificate for this course has passed.')}"
% endif
>
</p>
</section>
</%block>
<%static:require_module_async module_name="js/dateutil_factory" class_name="DateUtilFactory">
DateUtilFactory.transform(iterationKey=".localized-datetime");
</%static:require_module_async>
......@@ -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
</section>
</div>
</%block>
<%static:require_module_async module_name="js/dateutil_factory" class_name="DateUtilFactory">
DateUtilFactory.transform(iterationKey=".localized-datetime");
</%static:require_module_async>
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