From 72ca257bc3c3d8665095ac77025ad9a7b021bb69 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 5 May 2020 13:51:47 +0200 Subject: [PATCH] datetime are time-zoned --- apps/member/views.py | 4 ++-- apps/tournament/models.py | 10 +++++----- apps/tournament/views.py | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 6e088fe..be6de1c 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -1,5 +1,5 @@ import random -from datetime import datetime +from datetime import timezone from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.models import AnonymousUser @@ -157,7 +157,7 @@ class DocumentView(LoginRequiredMixin, View): if isinstance(doc, Solution): for pool in doc.pools.all(): - if pool.round == 2 and datetime.now() < doc.tournament.date_solutions_2: + if pool.round == 2 and timezone.now() < doc.tournament.date_solutions_2: continue if self.request.user.team in pool.teams.all(): grant = True diff --git a/apps/tournament/models.py b/apps/tournament/models.py index 2a32b80..6880cd5 100644 --- a/apps/tournament/models.py +++ b/apps/tournament/models.py @@ -46,27 +46,27 @@ class Tournament(models.Model): ) date_inscription = models.DateTimeField( - default=datetime.now, + default=timezone.now, verbose_name=_("date of registration closing"), ) date_solutions = models.DateTimeField( - default=datetime.now, + default=timezone.now, verbose_name=_("date of maximal solution submission"), ) date_syntheses = models.DateTimeField( - default=datetime.now, + default=timezone.now, verbose_name=_("date of maximal syntheses submission for the first round"), ) date_solutions_2 = models.DateTimeField( - default=datetime.now, + default=timezone.now, verbose_name=_("date when solutions of round 2 are available"), ) date_syntheses_2 = models.DateTimeField( - default=datetime.now, + default=timezone.now, verbose_name=_("date of maximal syntheses submission for the second round"), ) diff --git a/apps/tournament/views.py b/apps/tournament/views.py index 9a50449..cc6d6e2 100644 --- a/apps/tournament/views.py +++ b/apps/tournament/views.py @@ -1,6 +1,6 @@ import random import zipfile -from datetime import datetime +from datetime import timezone from io import BytesIO from django.contrib.auth.mixins import LoginRequiredMixin @@ -237,7 +237,7 @@ class SolutionsView(TeamMixin, BaseFormView, SingleTableView): solution.team = self.request.user.team solution.final = solution.team.selected_for_final - if datetime.now() > solution.tournament.date_solutions: + if timezone.now() > solution.tournament.date_solutions: form.add_error('file', _("You can't publish your solution anymore. Deadline: {date:%m-%d-%Y %h:%M}.") .format(date=solution.tournament.date_solutions)) return super().form_invalid(form) @@ -341,13 +341,13 @@ class SynthesesView(TeamMixin, BaseFormView, SingleTableView): synthesis.team = self.request.user.team synthesis.final = synthesis.team.selected_for_final - if synthesis.round == '1' and datetime.now() > synthesis.tournament.date_syntheses: + if synthesis.round == '1' and timezone.now() > synthesis.tournament.date_syntheses: form.add_error('file', _("You can't publish your synthesis anymore for the first round." " Deadline: {date:%m-%d-%Y %h:%M}.") .format(date=synthesis.tournament.date_syntheses)) return super().form_invalid(form) - if synthesis.round == '2' and datetime.now() > synthesis.tournament.date_syntheses_2: + if synthesis.round == '2' and timezone.now() > synthesis.tournament.date_syntheses_2: form.add_error('file', _("You can't publish your synthesis anymore for the second round." " Deadline: {date:%m-%d-%Y %h:%M}.") .format(date=synthesis.tournament.date_syntheses_2))