diff --git a/oioioi/statistics/tests.py b/oioioi/statistics/tests.py index ea29d62be..78efb2ac3 100644 --- a/oioioi/statistics/tests.py +++ b/oioioi/statistics/tests.py @@ -262,7 +262,7 @@ def test_round_info(self): self.assertTrue(ri['start_relative'] == 'Started') self.assertTrue(ri['end_relative'] == 'Finished') if ri['name'] == 'Future round': - self.assertTrue(ri['start_relative'] == '360 days, 20:27:58') + self.assertTrue(ri['start_relative'] == '11 months') def test_questions_info(self): contest = Contest.objects.get() diff --git a/oioioi/statistics/views.py b/oioioi/statistics/views.py index 8b39cd5d8..7d95e6d14 100644 --- a/oioioi/statistics/views.py +++ b/oioioi/statistics/views.py @@ -9,6 +9,7 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.db.models import F +from humanize import naturaldelta from oioioi.base.menu import menu_registry from oioioi.base.permissions import enforce_condition @@ -198,13 +199,13 @@ def get_rounds_info(request): for round_, rt in rounds_times(request, request.contest).items(): round_time_info = {'name': str(round_), 'start': rt.start or _("Not set")} if rt.start: - round_time_info['start_relative'] = str(rt.start - request.timestamp)[:-7] if rt.is_future( + round_time_info['start_relative'] = naturaldelta(rt.start - request.timestamp) if rt.is_future( request.timestamp) else _("Started") else: round_time_info['start_relative'] = _("Not set") round_time_info['end'] = rt.end or _("Not set") if rt.end: - round_time_info['end_relative'] = str(rt.end - request.timestamp)[:-7] if not rt.is_past( + round_time_info['end_relative'] = naturaldelta(rt.end - request.timestamp) if not rt.is_past( request.timestamp) else _("Finished") else: round_time_info['end_relative'] = _("Not set") @@ -217,7 +218,7 @@ def get_attachments_info(request): for attachment in attachments: pub_date_relative = None if attachment.pub_date: - pub_date_relative = str(attachment.pub_date - request.timestamp)[:-7] \ + pub_date_relative = naturaldelta(attachment.pub_date - request.timestamp) \ if attachment.pub_date > request.timestamp else _("Published") setattr(attachment, 'pub_date_relative', pub_date_relative) return attachments diff --git a/setup.py b/setup.py index b1697aec0..02d360688 100644 --- a/setup.py +++ b/setup.py @@ -63,6 +63,8 @@ # A library allowing to nest inlines in django admin. # Used in quizzes module for adding new quizzes. "django-nested-admin>=4.0,<4.1", + # Library for parsing dates and timedelta + "humanize<=4.9.0", # SIO2 dependencies: "filetracker>=2.1,<3.0", "django-simple-captcha>=0.5,<=0.5.18",