Code cleanup some small changes in the formatting.
This commit is contained in:
@@ -39,7 +39,7 @@ class HanchanManager(models.Manager):
|
||||
models.Q(player4=user, player4_dan_points__isnull=False)
|
||||
).filter(confirmed=True, **filter_args)
|
||||
queryset = queryset.select_related().order_by('-start')
|
||||
[ hanchan.get_playerdata(user) for hanchan in queryset ]
|
||||
[hanchan.get_playerdata(user) for hanchan in queryset]
|
||||
return queryset
|
||||
|
||||
def kyu_hanchans(self, user, **filter_args):
|
||||
@@ -57,7 +57,7 @@ class HanchanManager(models.Manager):
|
||||
models.Q(player4=user, player4_kyu_points__isnull=False)
|
||||
).filter(confirmed=True, **filter_args)
|
||||
queryset = queryset.select_related().order_by('-start')
|
||||
[ hanchan.get_playerdata(user) for hanchan in queryset ]
|
||||
[hanchan.get_playerdata(user) for hanchan in queryset]
|
||||
return queryset
|
||||
|
||||
def season_hanchans(self, user=None, season=None):
|
||||
@@ -87,7 +87,7 @@ class HanchanManager(models.Manager):
|
||||
else:
|
||||
queryset = queryset.filter(**filter_args)
|
||||
queryset = queryset.select_related().order_by('-start')
|
||||
[ hanchan.get_playerdata(user) for hanchan in queryset ]
|
||||
[hanchan.get_playerdata(user) for hanchan in queryset]
|
||||
return queryset
|
||||
|
||||
def unconfirmed_hanchans(self, user=None, **filter_args):
|
||||
|
||||
@@ -5,10 +5,10 @@ from mahjong_ranking import models
|
||||
from . import LOGGER, MIN_HANCHANS_FOR_LADDER
|
||||
|
||||
|
||||
class DenormalizationUpdateMiddleware(object): # Ignore PyLintBear (R0903)
|
||||
class DenormalizationUpdateMiddleware(object):
|
||||
"""To recalculate everything in the queues at the end of a POST request."""
|
||||
|
||||
def process_response(self, request, response): # Ignore PyLintBear (R0201)
|
||||
def process_response(self, request, response):
|
||||
"""Check and process the recalculation queues on each POST request.
|
||||
|
||||
:param request: the django HttpRequest object
|
||||
|
||||
@@ -4,7 +4,9 @@ import logging
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_delete, post_save
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.dispatch import receiver
|
||||
|
||||
from events.models import Event
|
||||
from . import settings, managers
|
||||
@@ -197,9 +199,14 @@ class Ranking(models.Model):
|
||||
self.save()
|
||||
|
||||
|
||||
def update_maistar_ranking(sender, instance, **kwargs):
|
||||
"""A Django signal hook to trigger a recalculation of the rankings as soon
|
||||
as a Mai-Star game has been added, deleted, or modified."""
|
||||
@receiver([post_delete, post_save], sender=Game)
|
||||
def update_maistar_ranking(sender, **kwargs):
|
||||
"""
|
||||
A Django signal hook to trigger a recalculation of the rankings as soon
|
||||
as a Mai-Star game has been added, deleted, or modified.
|
||||
:param sender: The callback function which will be connected to this signal. See Receiver functions for more information.
|
||||
:param kwargs: """
|
||||
instance = kwargs['instance']
|
||||
for player in instance.player_list:
|
||||
ranking, created = Ranking.objects.get_or_create(
|
||||
user=player['user'],
|
||||
@@ -213,7 +220,3 @@ def update_maistar_ranking(sender, instance, **kwargs):
|
||||
player['user'].username, instance.season)
|
||||
ranking.recalculate()
|
||||
Ranking.objects.calculate_rankings(instance.season)
|
||||
|
||||
|
||||
models.signals.post_delete.connect(update_maistar_ranking, sender=Game)
|
||||
models.signals.post_save.connect(update_maistar_ranking, sender=Game)
|
||||
|
||||
@@ -9,19 +9,26 @@ from easy_thumbnails import fields, widgets
|
||||
from membership.models import Membership, ActivationRequest
|
||||
|
||||
|
||||
def activate_user(modeladmin, request, queryset): # Ignore PyLintBear (W0613)
|
||||
"""Triggers activation of the selects actication requests by hand."""
|
||||
for activation in queryset:
|
||||
membership = Membership.objects.get(username=activation.user.username)
|
||||
membership.save()
|
||||
activation.activate()
|
||||
def activate_user(modeladmin, request, queryset):
|
||||
"""Triggers activation of the selects actication requests by hand.
|
||||
|
||||
:param modeladmin: The ModelAdmin that triggered this action.
|
||||
:param request: An HttpRequest representing the current request.
|
||||
:param queryset: A QuerySet containing the objects selected by the user.
|
||||
"""
|
||||
[activation.activate() for activation in queryset ]
|
||||
|
||||
|
||||
activate_user.short_description = _('Activate selected User')
|
||||
|
||||
|
||||
def cleanup_activation(modeladmin, request, queryset): # Ignore PyLintBear (W0613)
|
||||
"""Delete every selected activation request that has been expired."""
|
||||
"""Delete every selected activation request that has been expired.
|
||||
|
||||
:param modeladmin: The ModelAdmin that triggered this action.
|
||||
:param request: An HttpRequest representing the current request.
|
||||
:param queryset: A QuerySet containing the objects selected by the user.
|
||||
"""
|
||||
for activation in queryset:
|
||||
if activation.expired:
|
||||
activation.user.delete()
|
||||
|
||||
@@ -56,8 +56,8 @@ class ActivationManager(models.Manager):
|
||||
"""Creates a PendingActivation instance with an random activation key.
|
||||
@param user: the user that requests activation.
|
||||
"""
|
||||
salt = str(user.pk * random.random()) + \
|
||||
user.registration_date.isoformat()
|
||||
salt = str(user.pk * random.random())
|
||||
salt += user.registration_date.isoformat()
|
||||
activation_key = hashlib.sha1(salt.encode()).hexdigest()
|
||||
return self.create(user=user, activation_key=activation_key)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user