Fixed: ugettext has been deprecated

Fixed: Deprecatios for Django 4.0
Changed: path instead of url_path
Added: fiaxateranking command
This commit is contained in:
2023-07-20 22:56:13 +02:00
parent fbfabb982f
commit ef00fc25f7
32 changed files with 266 additions and 252 deletions

View File

@@ -14,6 +14,7 @@ from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext as _
from events.models import Event
from . import DAN_RANKS_DICT, LOGGER, set_dirty
from . import managers
@@ -349,6 +350,7 @@ class KyuDanRanking(models.Model):
legacy_date = models.DateField(blank=True, null=True)
legacy_dan = models.PositiveSmallIntegerField(blank=True, null=True)
legacy_dan_points = models.PositiveIntegerField(blank=True, null=True)
legacy_max_dan_points = models.PositiveIntegerField(default=0)
legacy_kyu = models.PositiveSmallIntegerField(blank=True, null=True)
legacy_kyu_points = models.PositiveIntegerField(blank=True, null=True)
legacy_hanchan_count = models.PositiveIntegerField(blank=True, null=True)
@@ -359,7 +361,10 @@ class KyuDanRanking(models.Model):
objects = managers.KyuDanRankingManager()
class Meta(object):
ordering = ('-dan_points', 'dan', '-kyu_points')
ordering = (models.F("dan").desc(nulls_last=True),
'-dan_points', '-kyu_points',
'-won_hanchans', '-good_hanchans',
'-last_hanchan_date')
verbose_name = _(u'Kyū/Dan Ranking')
verbose_name_plural = _(u'Kyū/Dan Rankings')
@@ -474,7 +479,7 @@ class KyuDanRanking(models.Model):
# Setze alles auf die legacy Werte und berechne alles von neuem.
self.dan = self.legacy_dan
self.dan_points = self.legacy_dan_points or 0
self.max_dan_points = self.dan_points
self.max_dan_points = self.legacy_max_dan_points or 0
self.kyu = self.legacy_kyu
self.kyu_points = self.legacy_kyu_points or 0
self.hanchan_count = self.legacy_hanchan_count or 0
@@ -491,19 +496,24 @@ class KyuDanRanking(models.Model):
since = timezone.make_aware(
datetime.combine(self.legacy_date, time(0, 0, 0))
)
LOGGER.info(
"recalculating Kyu/Dan points for %(user)s since %(since)s...",
{'user': self.user, 'since': str(since)}
)
if since:
valid_hanchans = valid_hanchans.filter(start__gt=since)
else:
since = valid_hanchans.aggregate(since=models.Min("start"))["since"]
if until:
valid_hanchans = valid_hanchans.filter(start__lte=until)
else:
until = valid_hanchans.aggregate(until=models.Max("start"))["until"]
if valid_hanchans.count() > 0:
LOGGER.info(f"recalculating Kyu/Dan points for {self.user} ({since:%Y-%m-%d} - {until:%Y-%m-%d})...")
else:
LOGGER.info(f"No new valid Hanchans for {self.user}...")
for hanchan in valid_hanchans:
self.hanchan_count += 1
LOGGER.info(f"{self.user} Hanchan no. {self.hanchan_count} from {hanchan.start}")
hanchan.get_playerdata(self.user)
if since and hanchan.start < since:
LOGGER.debug(hanchan, "<", since, "no recalc")
LOGGER.info(hanchan, "<", since, "no recalc")
self.dan_points += hanchan.dan_points or 0
self.kyu_points += hanchan.kyu_points or 0
self.update_rank()