Skip to content

Commit

Permalink
Use humanize module
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Jacniacki committed Jul 4, 2024
1 parent 36b4f1a commit c259d1c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion oioioi/statistics/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions oioioi/statistics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c259d1c

Please sign in to comment.