From cd58d5a357989c3468ddc263edf3bb0bc161f496 Mon Sep 17 00:00:00 2001 From: thomas girod Date: Wed, 26 Jun 2024 12:28:00 +0200 Subject: [PATCH] resolve warnings --- club/tests.py | 17 ++++++----------- core/utils.py | 4 +++- counter/migrations/0003_permanency_activity.py | 6 ++++-- counter/models.py | 15 +++++++++------ forum/migrations/0001_initial.py | 6 ++++-- sith/settings.py | 4 +--- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/club/tests.py b/club/tests.py index 99172a16..78fb8665 100644 --- a/club/tests.py +++ b/club/tests.py @@ -69,9 +69,7 @@ class ClubTest(TestCase): unix_name="fake-club", address="5 rue de la République, 90000 Belfort", ) - cls.members_url = reverse( - "club:club_members", kwargs={"club_id": cls.club.id} - ) + cls.members_url = reverse("club:club_members", kwargs={"club_id": cls.club.id}) a_month_ago = now() - timedelta(days=30) yesterday = now() - timedelta(days=1) Membership.objects.create( @@ -174,14 +172,11 @@ class MembershipQuerySetTest(ClubTest): # should delete the subscriptions of skia and comptable self.club.members.ongoing().board().delete() - assert ( - cache.get(f"membership_{mem_skia.club_id}_{mem_skia.user_id}") - == "not_member" - ) - assert ( - cache.get(f"membership_{mem_comptable.club_id}_{mem_comptable.user_id}") - == "not_member", - ) + for membership in (mem_skia, mem_comptable): + cached_mem = cache.get( + f"membership_{membership.club_id}_{membership.user_id}" + ) + assert cached_mem == "not_member" class ClubModelTest(ClubTest): diff --git a/core/utils.py b/core/utils.py index 62cf04bb..427786fe 100644 --- a/core/utils.py +++ b/core/utils.py @@ -28,6 +28,7 @@ from django.conf import settings from django.core.files.base import ContentFile from django.utils import timezone from PIL import ExifTags +from PIL.Image import Resampling def get_git_revision_short_hash() -> str: @@ -109,7 +110,8 @@ def resize_image(im, edge, format): (w, h) = im.size (width, height) = scale_dimension(w, h, long_edge=edge) content = BytesIO() - im = im.resize((width, height), PIL.Image.ANTIALIAS) + # use the lanczos filter for antialiasing + im = im.resize((width, height), Resampling.LANCZOS) try: im.save( fp=content, diff --git a/counter/migrations/0003_permanency_activity.py b/counter/migrations/0003_permanency_activity.py index 929d8308..915be8fc 100644 --- a/counter/migrations/0003_permanency_activity.py +++ b/counter/migrations/0003_permanency_activity.py @@ -2,9 +2,9 @@ from __future__ import unicode_literals import datetime +from datetime import timezone from django.db import migrations, models -from django.utils.timezone import utc class Migration(migrations.Migration): @@ -17,7 +17,9 @@ class Migration(migrations.Migration): field=models.DateTimeField( verbose_name="activity time", auto_now=True, - default=datetime.datetime(2016, 8, 26, 17, 5, 31, 202824, tzinfo=utc), + default=datetime.datetime( + 2016, 8, 26, 17, 5, 31, 202824, tzinfo=timezone.utc + ), ), preserve_default=False, ) diff --git a/counter/models.py b/counter/models.py index 6c6dd27c..29dfb92d 100644 --- a/counter/models.py +++ b/counter/models.py @@ -19,8 +19,8 @@ import base64 import os import random import string -from datetime import date, datetime, timedelta -from typing import Optional, Tuple +from datetime import date, datetime, timedelta, timezone +from typing import Tuple from dict2xml import dict2xml from django.conf import settings @@ -534,7 +534,7 @@ class Counter(models.Model): .order_by("-perm_sum") ) - def get_top_customers(self, since: Optional[date] = None) -> QuerySet: + def get_top_customers(self, since: datetime | date | None = None) -> QuerySet: """ Return a QuerySet querying the money spent by customers of this counter since the specified date, ordered by descending amount of money spent. @@ -543,9 +543,13 @@ class Counter(models.Model): - the full name (first name + last name) of the customer - the nickname of the customer - the amount of money spent by the customer + + :param since: timestamp from which to perform the calculation """ if since is None: since = get_start_of_semester() + if isinstance(since, date): + since = datetime(since.year, since.month, since.day, tzinfo=timezone.utc) return ( self.sellings.filter(date__gte=since) .annotate( @@ -568,19 +572,18 @@ class Counter(models.Model): .order_by("-selling_sum") ) - def get_total_sales(self, since=None) -> CurrencyField: + def get_total_sales(self, since: datetime | date | None = None) -> CurrencyField: """ Compute and return the total turnover of this counter since the date specified in parameter (by default, since the start of the current semester) :param since: timestamp from which to perform the calculation - :type since: datetime | date | None :return: Total revenue earned at this counter """ if since is None: since = get_start_of_semester() if isinstance(since, date): - since = datetime.combine(since, datetime.min.time()) + since = datetime(since.year, since.month, since.day, tzinfo=timezone.utc) total = self.sellings.filter(date__gte=since).aggregate( total=Sum(F("quantity") * F("unit_price"), output_field=CurrencyField()) )["total"] diff --git a/forum/migrations/0001_initial.py b/forum/migrations/0001_initial.py index 4ad137d6..3d3440db 100644 --- a/forum/migrations/0001_initial.py +++ b/forum/migrations/0001_initial.py @@ -2,12 +2,12 @@ from __future__ import unicode_literals import datetime +from datetime import timezone import django.db.models.deletion import django.utils.timezone from django.conf import settings from django.db import migrations, models -from django.utils.timezone import utc class Migration(migrations.Migration): @@ -226,7 +226,9 @@ class Migration(migrations.Migration): "last_read_date", models.DateTimeField( verbose_name="last read date", - default=datetime.datetime(1999, 1, 1, 0, 0, tzinfo=utc), + default=datetime.datetime( + 1999, 1, 1, 0, 0, tzinfo=timezone.utc + ), ), ), ( diff --git a/sith/settings.py b/sith/settings.py index 8680be2a..0489a8b1 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -187,6 +187,7 @@ TEMPLATES = [ }, }, ] +FORM_RENDERER = "django.forms.renderers.DjangoDivFormRenderer" HAYSTACK_CONNECTIONS = { "default": { @@ -248,8 +249,6 @@ TIME_ZONE = "Europe/Paris" USE_I18N = True -USE_L10N = True - USE_TZ = True LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),) @@ -690,7 +689,6 @@ if DEBUG: "sith.toolbar_debug.TemplatesPanel", "debug_toolbar.panels.cache.CachePanel", "debug_toolbar.panels.signals.SignalsPanel", - "debug_toolbar.panels.logging.LoggingPanel", "debug_toolbar.panels.redirects.RedirectsPanel", ] SASS_INCLUDE_FOLDERS = ["core/static/"]