Replace timezone.now().date() by date.today()

This commit is contained in:
Yohann D'ANELLO 2020-08-16 00:35:13 +02:00
parent da23df05cb
commit b8c3dda95b
8 changed files with 46 additions and 42 deletions

View File

@ -1,9 +1,10 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import date
import django_tables2 as tables
from django.contrib.auth.models import User
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.urls import reverse_lazy
from django.utils.html import format_html
@ -106,8 +107,8 @@ class MembershipTable(tables.Table):
empty_membership = Membership(
club=record.club,
user=record.user,
date_start=timezone.now().date(),
date_end=timezone.now().date(),
date_start=date.today(),
date_end=date.today(),
fee=0,
)
if PermissionBackend.check_perm(get_current_authenticated_user(),

View File

@ -1,6 +1,8 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import date
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.contenttypes.models import ContentType
@ -43,7 +45,7 @@ class PermissionBackend(ModelBackend):
for role in membership.roles.all():
for perm in role.permissions.filter(type=t, mask__rank__lte=get_current_session().get("permission_mask", -1)).all():
if not perm.permanent:
if membership.date_start > timezone.now().date() or membership.date_end < timezone.now().date():
if membership.date_start > date.today() or membership.date_end < date.today():
continue
perm.membership = membership
perms.append(perm)
@ -80,7 +82,7 @@ class PermissionBackend(ModelBackend):
F=F,
Q=Q,
now=timezone.now(),
today=timezone.now().date(),
today=date.today(),
)
yield permission

View File

@ -1,7 +1,7 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import timedelta
from datetime import timedelta, date
from django.contrib.auth.models import User
from django.test import TestCase
@ -84,18 +84,18 @@ class TestPermissionDenied(TestCase):
def test_create_wei_bus(self):
wei = WEIClub.objects.create(
membership_start=timezone.now().date(),
date_start=timezone.now().date() + timedelta(days=1),
date_end=timezone.now().date() + timedelta(days=1),
membership_start=date.today(),
date_start=date.today() + timedelta(days=1),
date_end=date.today() + timedelta(days=1),
)
response = self.client.get(reverse("wei:add_bus", kwargs=dict(pk=wei.pk)))
self.assertEqual(response.status_code, 403)
def test_create_wei_team(self):
wei = WEIClub.objects.create(
membership_start=timezone.now().date(),
date_start=timezone.now().date() + timedelta(days=1),
date_end=timezone.now().date() + timedelta(days=1),
membership_start=date.today(),
date_start=date.today() + timedelta(days=1),
date_end=date.today() + timedelta(days=1),
)
bus = Bus.objects.create(wei=wei)
response = self.client.get(reverse("wei:add_team", kwargs=dict(pk=bus.pk)))
@ -103,27 +103,27 @@ class TestPermissionDenied(TestCase):
def test_create_1a_weiregistration(self):
wei = WEIClub.objects.create(
membership_start=timezone.now().date(),
date_start=timezone.now().date() + timedelta(days=1),
date_end=timezone.now().date() + timedelta(days=1),
membership_start=date.today(),
date_start=date.today() + timedelta(days=1),
date_end=date.today() + timedelta(days=1),
)
response = self.client.get(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=wei.pk)))
self.assertEqual(response.status_code, 403)
def test_create_old_weiregistration(self):
wei = WEIClub.objects.create(
membership_start=timezone.now().date(),
date_start=timezone.now().date() + timedelta(days=1),
date_end=timezone.now().date() + timedelta(days=1),
membership_start=date.today(),
date_start=date.today() + timedelta(days=1),
date_end=date.today() + timedelta(days=1),
)
response = self.client.get(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=wei.pk)))
self.assertEqual(response.status_code, 403)
def test_validate_weiregistration(self):
wei = WEIClub.objects.create(
membership_start=timezone.now().date(),
date_start=timezone.now().date() + timedelta(days=1),
date_end=timezone.now().date() + timedelta(days=1),
membership_start=date.today(),
date_start=date.today() + timedelta(days=1),
date_end=date.today() + timedelta(days=1),
)
registration = WEIRegistration.objects.create(wei=wei, user=self.user, birth_date="2000-01-01")
response = self.client.get(reverse("wei:validate_registration", kwargs=dict(pk=registration.pk)))

View File

@ -1,6 +1,8 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import date
from django.contrib.auth.models import User
from django.core.exceptions import FieldError
from django.db.models import F, Q
@ -22,14 +24,14 @@ class PermissionQueryTestCase(TestCase):
NoteUser.objects.create(user=user)
wei = WEIClub.objects.create(
name="wei",
date_start=timezone.now().date(),
date_end=timezone.now().date(),
date_start=date.today(),
date_end=date.today(),
)
NoteClub.objects.create(club=wei)
weiregistration = WEIRegistration.objects.create(
user=user,
wei=wei,
birth_date=timezone.now().date(),
birth_date=date.today(),
)
bus = Bus.objects.create(
name="bus",
@ -68,7 +70,7 @@ class PermissionQueryTestCase(TestCase):
F=F,
Q=Q,
now=timezone.now(),
today=timezone.now().date(),
today=date.today(),
)
try:
instanced.update_query()

View File

@ -7,7 +7,6 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.forms import HiddenInput
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.views.generic import UpdateView, TemplateView, CreateView
from member.models import Membership
@ -95,8 +94,8 @@ class RightsView(TemplateView):
if self.request.user.is_authenticated:
special_memberships = Membership.objects.filter(
date_start__lte=timezone.now().date(),
date_end__gte=timezone.now().date(),
date_start__lte=date.today(),
date_end__gte=date.today(),
).filter(roles__in=Role.objects.filter(~(Q(name="Adhérent BDE")
| Q(name="Adhérent Kfet")
| Q(name="Membre de club")

View File

@ -1,9 +1,10 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import date
import django_tables2 as tables
from django.urls import reverse_lazy
from django.utils import timezone
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from django_tables2 import A
@ -89,8 +90,8 @@ class WEIRegistrationTable(tables.Table):
get_current_authenticated_user(), "wei.add_weimembership", WEIMembership(
club=record.wei,
user=record.user,
date_start=timezone.now().date(),
date_end=timezone.now().date(),
date_start=date.today(),
date_end=date.today(),
fee=0,
registration=record,
)

View File

@ -72,7 +72,7 @@ class TestWEIRegistration(TestCase):
membership_start=date(self.year, 1, 1),
membership_end=date(self.year, 12, 31),
year=self.year,
date_start=timezone.now().date() + timedelta(days=2),
date_start=date.today() + timedelta(days=2),
date_end=date(self.year, 12, 31),
)
NoteClub.objects.create(club=self.wei)
@ -772,7 +772,7 @@ class TestWEISurveyAlgorithm(TestCase):
membership_start=date(self.year, 1, 1),
membership_end=date(self.year, 12, 31),
year=self.year,
date_start=timezone.now().date() + timedelta(days=2),
date_start=date.today() + timedelta(days=2),
date_end=date(self.year, 12, 31),
)
NoteClub.objects.create(club=self.wei)

View File

@ -17,7 +17,6 @@ from django.http import HttpResponse
from django.shortcuts import redirect
from django.template.loader import render_to_string
from django.urls import reverse_lazy
from django.utils import timezone
from django.views import View
from django.views.generic import DetailView, UpdateView, RedirectView, TemplateView
from django.utils.translation import gettext_lazy as _
@ -61,8 +60,8 @@ class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
name="",
email="weiclub@example.com",
year=0,
date_start=timezone.now().date(),
date_end=timezone.now().date(),
date_start=date.today(),
date_end=date.today(),
))
return context
@ -81,8 +80,8 @@ class WEICreateView(ProtectQuerysetMixin, ProtectedCreateView):
name="",
email="weiclub@example.com",
year=0,
date_start=timezone.now().date(),
date_end=timezone.now().date(),
date_start=date.today(),
date_end=date.today(),
)
def form_valid(self, form):
@ -723,8 +722,8 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
if PermissionBackend.check_perm(self.request.user, "wei.add_weimembership", WEIMembership(
club=self.object.wei,
user=self.object.user,
date_start=timezone.now().date(),
date_end=timezone.now().date(),
date_start=date.today(),
date_end=date.today(),
fee=0,
registration=self.object,
)):
@ -774,8 +773,8 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
return WEIMembership(
club=registration.wei,
user=registration.user,
date_start=timezone.now().date(),
date_end=timezone.now().date() + timedelta(days=1),
date_start=date.today(),
date_end=date.today() + timedelta(days=1),
fee=0,
registration=registration,
)