1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 07:02:22 +00:00

datetime are time-zoned

This commit is contained in:
Yohann D'ANELLO 2020-05-05 13:51:47 +02:00
parent ecbbe46420
commit 72ca257bc3
3 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import random import random
from datetime import datetime from datetime import timezone
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
@ -157,7 +157,7 @@ class DocumentView(LoginRequiredMixin, View):
if isinstance(doc, Solution): if isinstance(doc, Solution):
for pool in doc.pools.all(): 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 continue
if self.request.user.team in pool.teams.all(): if self.request.user.team in pool.teams.all():
grant = True grant = True

View File

@ -46,27 +46,27 @@ class Tournament(models.Model):
) )
date_inscription = models.DateTimeField( date_inscription = models.DateTimeField(
default=datetime.now, default=timezone.now,
verbose_name=_("date of registration closing"), verbose_name=_("date of registration closing"),
) )
date_solutions = models.DateTimeField( date_solutions = models.DateTimeField(
default=datetime.now, default=timezone.now,
verbose_name=_("date of maximal solution submission"), verbose_name=_("date of maximal solution submission"),
) )
date_syntheses = models.DateTimeField( date_syntheses = models.DateTimeField(
default=datetime.now, default=timezone.now,
verbose_name=_("date of maximal syntheses submission for the first round"), verbose_name=_("date of maximal syntheses submission for the first round"),
) )
date_solutions_2 = models.DateTimeField( date_solutions_2 = models.DateTimeField(
default=datetime.now, default=timezone.now,
verbose_name=_("date when solutions of round 2 are available"), verbose_name=_("date when solutions of round 2 are available"),
) )
date_syntheses_2 = models.DateTimeField( date_syntheses_2 = models.DateTimeField(
default=datetime.now, default=timezone.now,
verbose_name=_("date of maximal syntheses submission for the second round"), verbose_name=_("date of maximal syntheses submission for the second round"),
) )

View File

@ -1,6 +1,6 @@
import random import random
import zipfile import zipfile
from datetime import datetime from datetime import timezone
from io import BytesIO from io import BytesIO
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
@ -237,7 +237,7 @@ class SolutionsView(TeamMixin, BaseFormView, SingleTableView):
solution.team = self.request.user.team solution.team = self.request.user.team
solution.final = solution.team.selected_for_final 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}.") form.add_error('file', _("You can't publish your solution anymore. Deadline: {date:%m-%d-%Y %h:%M}.")
.format(date=solution.tournament.date_solutions)) .format(date=solution.tournament.date_solutions))
return super().form_invalid(form) return super().form_invalid(form)
@ -341,13 +341,13 @@ class SynthesesView(TeamMixin, BaseFormView, SingleTableView):
synthesis.team = self.request.user.team synthesis.team = self.request.user.team
synthesis.final = synthesis.team.selected_for_final 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." form.add_error('file', _("You can't publish your synthesis anymore for the first round."
" Deadline: {date:%m-%d-%Y %h:%M}.") " Deadline: {date:%m-%d-%Y %h:%M}.")
.format(date=synthesis.tournament.date_syntheses)) .format(date=synthesis.tournament.date_syntheses))
return super().form_invalid(form) 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." form.add_error('file', _("You can't publish your synthesis anymore for the second round."
" Deadline: {date:%m-%d-%Y %h:%M}.") " Deadline: {date:%m-%d-%Y %h:%M}.")
.format(date=synthesis.tournament.date_syntheses_2)) .format(date=synthesis.tournament.date_syntheses_2))