From 36873ffc92d9be760dc9f6cfabffbb6b6edeba03 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 23 Jun 2014 20:50:27 -0400 Subject: [PATCH] Datetime localized on gitlog page of sysadmin dashboard --- .../dashboard/tests/test_sysadmin.py | 32 ++++ lms/templates/sysadmin_dashboard_gitlogs.html | 151 +++++++++--------- 2 files changed, 105 insertions(+), 78 deletions(-) diff --git a/lms/djangoapps/dashboard/tests/test_sysadmin.py b/lms/djangoapps/dashboard/tests/test_sysadmin.py index 559c65fe8e..df89c210fe 100644 --- a/lms/djangoapps/dashboard/tests/test_sysadmin.py +++ b/lms/djangoapps/dashboard/tests/test_sysadmin.py @@ -16,6 +16,8 @@ from django.test.client import Client from django.test.utils import override_settings from django.utils.translation import ugettext as _ import mongoengine +from django.utils.timezone import utc as UTC +from util.date_utils import get_time_display, DEFAULT_DATE_TIME_FORMAT from student.roles import CourseStaffRole, GlobalStaff from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE @@ -507,6 +509,36 @@ class TestSysAdminMongoCourseImport(SysadminBaseTestCase): self._rm_edx4edx() + def test_gitlog_date(self): + """ + Make sure the date is timezone-aware and being converted/formatted + properly. + """ + + tz_names = [ + 'America/New_York', # UTC - 5 + 'Asia/Pyongyang', # UTC + 9 + 'Europe/London', # UTC + 'Canada/Yukon', # UTC - 8 + 'Europe/Moscow', # UTC + 4 + ] + tz_format = DEFAULT_DATE_TIME_FORMAT + + self._setstaff_login() + self._mkdir(getattr(settings, 'GIT_REPO_DIR')) + + self._add_edx4edx() + date = CourseImportLog.objects.first().created.replace(tzinfo=UTC) + + for timezone in tz_names: + with (override_settings(TIME_ZONE=timezone)): + date_text = get_time_display(date, tz_format, settings.TIME_ZONE) + response = self.client.get(reverse('gitlogs')) + + self.assertIn(date_text, response.content) + + self._rm_edx4edx() + def test_gitlog_bad_course(self): """ Make sure we gracefully handle courses that don't exist. diff --git a/lms/templates/sysadmin_dashboard_gitlogs.html b/lms/templates/sysadmin_dashboard_gitlogs.html index b4d27d22b8..fbc3ea3b77 100644 --- a/lms/templates/sysadmin_dashboard_gitlogs.html +++ b/lms/templates/sysadmin_dashboard_gitlogs.html @@ -1,6 +1,11 @@ <%inherit file="/main.html" /> -<%! from django.core.urlresolvers import reverse %> -<%! from django.utils.translation import ugettext as _ %> +<%! + from django.core.urlresolvers import reverse + from django.utils.translation import ugettext as _ + from django.utils.timezone import utc as UTC + from util.date_utils import get_time_display, DEFAULT_DATE_TIME_FORMAT + from django.conf import settings +%> <%namespace name='static' file='/static_content.html'/> <%block name="headextra"> @@ -46,87 +51,77 @@ textarea {
-
+
-
-

${_('Sysadmin Dashboard')}

-
-

- ${_('Users')} - ${_('Courses')} - ${_('Staffing and Enrollment')} - ## Translators: refers to http://git-scm.com/docs/git-log - ${_('Git Logs')} -

-
+
+

${_('Sysadmin Dashboard')}

+
+

+ ${_('Users')} + ${_('Courses')} + ${_('Staffing and Enrollment')} + ## Translators: refers to http://git-scm.com/docs/git-log + ${_('Git Logs')} +

+
-
- - + + + +
## Translators: refers to http://git-scm.com/docs/git-log -

${_('Git Logs')}

+

${_('Git Logs')}

-%if course_id is None: - - - - - - ## Translators: Git is a version-control system; see http://git-scm.com/about - - - - - %for cil in cilset[:10]: - <% course_id_string = cil.course_id.to_deprecated_string() if cil.course_id else None %> - - - - - - %endfor - -
${_('Date')}${_('Course ID')}${_('Git Action')}
${cil.created}${course_id_string}${cil.git_log}
+ %if course_id is not None: + ## Translators: Git is a version-control system; see http://git-scm.com/about +

${_('Recent git load activity for {course_id}').format(course_id=course_id)}

+ %if error_msg: +

${_('Error')}:

+

${error_msg}

+ %endif + %endif -%else: + + + + + + ## Translators: Git is a version-control system; see http://git-scm.com/about + + + + + <% + if course_id == None: + logs = cilset[:10] + else: + logs = cilset[:2] + %> + % for cil in logs: + <% + course_id_string = cil.course_id.to_deprecated_string() if cil.course_id else None - ## Translators: Git is a version-control system; see http://git-scm.com/about -

${_('Recent git load activity for')} ${course_id}

- %if error_msg: -

${_('Error')}:

-

${error_msg}

- %endif - -
${_('Date')}${_('Course ID')}${_('Git Action')}
- - - - - ## Translators: Git is a version-control system; see http://git-scm.com/about - - - - - % for cil in cilset[:2]: - <% course_id_string = cil.course_id.to_deprecated_string() if cil.course_id else None %> - - - - - - - - - - % endfor - -
${_('Date')}${_('Course ID')}${_('Git Action')}
${cil.created}${course_id_string}${cil.git_log}
-
${cil.import_log | h}
-
- -% endif - -
-
+ # Appropriate datetime string for current locale and timezone + date = get_time_display(cil.created.replace(tzinfo=UTC), + DEFAULT_DATE_TIME_FORMAT, coerce_tz=settings.TIME_ZONE) + %> + + ${date} + ${course_id_string} + ${cil.git_log} + + %endfor + ## Show the full log if viewing information about a specific course + %if course_id is not None: + + +
${cil.import_log | h}
+ + + %endif + + +
+