resolve warnings

This commit is contained in:
thomas girod 2024-06-26 12:28:00 +02:00
parent 75bb3f992c
commit cd58d5a357
6 changed files with 27 additions and 25 deletions

View File

@ -69,9 +69,7 @@ class ClubTest(TestCase):
unix_name="fake-club", unix_name="fake-club",
address="5 rue de la République, 90000 Belfort", address="5 rue de la République, 90000 Belfort",
) )
cls.members_url = reverse( cls.members_url = reverse("club:club_members", kwargs={"club_id": cls.club.id})
"club:club_members", kwargs={"club_id": cls.club.id}
)
a_month_ago = now() - timedelta(days=30) a_month_ago = now() - timedelta(days=30)
yesterday = now() - timedelta(days=1) yesterday = now() - timedelta(days=1)
Membership.objects.create( Membership.objects.create(
@ -174,14 +172,11 @@ class MembershipQuerySetTest(ClubTest):
# should delete the subscriptions of skia and comptable # should delete the subscriptions of skia and comptable
self.club.members.ongoing().board().delete() self.club.members.ongoing().board().delete()
assert ( for membership in (mem_skia, mem_comptable):
cache.get(f"membership_{mem_skia.club_id}_{mem_skia.user_id}") cached_mem = cache.get(
== "not_member" f"membership_{membership.club_id}_{membership.user_id}"
)
assert (
cache.get(f"membership_{mem_comptable.club_id}_{mem_comptable.user_id}")
== "not_member",
) )
assert cached_mem == "not_member"
class ClubModelTest(ClubTest): class ClubModelTest(ClubTest):

View File

@ -28,6 +28,7 @@ from django.conf import settings
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.utils import timezone from django.utils import timezone
from PIL import ExifTags from PIL import ExifTags
from PIL.Image import Resampling
def get_git_revision_short_hash() -> str: def get_git_revision_short_hash() -> str:
@ -109,7 +110,8 @@ def resize_image(im, edge, format):
(w, h) = im.size (w, h) = im.size
(width, height) = scale_dimension(w, h, long_edge=edge) (width, height) = scale_dimension(w, h, long_edge=edge)
content = BytesIO() content = BytesIO()
im = im.resize((width, height), PIL.Image.ANTIALIAS) # use the lanczos filter for antialiasing
im = im.resize((width, height), Resampling.LANCZOS)
try: try:
im.save( im.save(
fp=content, fp=content,

View File

@ -2,9 +2,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime import datetime
from datetime import timezone
from django.db import migrations, models from django.db import migrations, models
from django.utils.timezone import utc
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -17,7 +17,9 @@ class Migration(migrations.Migration):
field=models.DateTimeField( field=models.DateTimeField(
verbose_name="activity time", verbose_name="activity time",
auto_now=True, 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, preserve_default=False,
) )

View File

@ -19,8 +19,8 @@ import base64
import os import os
import random import random
import string import string
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta, timezone
from typing import Optional, Tuple from typing import Tuple
from dict2xml import dict2xml from dict2xml import dict2xml
from django.conf import settings from django.conf import settings
@ -534,7 +534,7 @@ class Counter(models.Model):
.order_by("-perm_sum") .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 Return a QuerySet querying the money spent by customers of this counter
since the specified date, ordered by descending amount of money spent. 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 full name (first name + last name) of the customer
- the nickname of the customer - the nickname of the customer
- the amount of money spent by the customer - the amount of money spent by the customer
:param since: timestamp from which to perform the calculation
""" """
if since is None: if since is None:
since = get_start_of_semester() since = get_start_of_semester()
if isinstance(since, date):
since = datetime(since.year, since.month, since.day, tzinfo=timezone.utc)
return ( return (
self.sellings.filter(date__gte=since) self.sellings.filter(date__gte=since)
.annotate( .annotate(
@ -568,19 +572,18 @@ class Counter(models.Model):
.order_by("-selling_sum") .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 Compute and return the total turnover of this counter
since the date specified in parameter (by default, since the start of the current since the date specified in parameter (by default, since the start of the current
semester) semester)
:param since: timestamp from which to perform the calculation :param since: timestamp from which to perform the calculation
:type since: datetime | date | None
:return: Total revenue earned at this counter :return: Total revenue earned at this counter
""" """
if since is None: if since is None:
since = get_start_of_semester() since = get_start_of_semester()
if isinstance(since, date): 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 = self.sellings.filter(date__gte=since).aggregate(
total=Sum(F("quantity") * F("unit_price"), output_field=CurrencyField()) total=Sum(F("quantity") * F("unit_price"), output_field=CurrencyField())
)["total"] )["total"]

View File

@ -2,12 +2,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime import datetime
from datetime import timezone
import django.db.models.deletion import django.db.models.deletion
import django.utils.timezone import django.utils.timezone
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
from django.utils.timezone import utc
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -226,7 +226,9 @@ class Migration(migrations.Migration):
"last_read_date", "last_read_date",
models.DateTimeField( models.DateTimeField(
verbose_name="last read date", 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
),
), ),
), ),
( (

View File

@ -187,6 +187,7 @@ TEMPLATES = [
}, },
}, },
] ]
FORM_RENDERER = "django.forms.renderers.DjangoDivFormRenderer"
HAYSTACK_CONNECTIONS = { HAYSTACK_CONNECTIONS = {
"default": { "default": {
@ -248,8 +249,6 @@ TIME_ZONE = "Europe/Paris"
USE_I18N = True USE_I18N = True
USE_L10N = True
USE_TZ = True USE_TZ = True
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),) LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
@ -690,7 +689,6 @@ if DEBUG:
"sith.toolbar_debug.TemplatesPanel", "sith.toolbar_debug.TemplatesPanel",
"debug_toolbar.panels.cache.CachePanel", "debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel", "debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.logging.LoggingPanel",
"debug_toolbar.panels.redirects.RedirectsPanel", "debug_toolbar.panels.redirects.RedirectsPanel",
] ]
SASS_INCLUDE_FOLDERS = ["core/static/"] SASS_INCLUDE_FOLDERS = ["core/static/"]