Code cleanup some small changes in the formatting.

This commit is contained in:
2017-11-03 07:49:21 +01:00
parent 002eb40ea5
commit 34d327f183
5 changed files with 31 additions and 21 deletions

View File

@@ -5,10 +5,10 @@ from mahjong_ranking import models
from . import LOGGER, MIN_HANCHANS_FOR_LADDER 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.""" """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. """Check and process the recalculation queues on each POST request.
:param request: the django HttpRequest object :param request: the django HttpRequest object

View File

@@ -4,7 +4,9 @@ import logging
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models from django.db import models
from django.db.models.signals import post_delete, post_save
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.dispatch import receiver
from events.models import Event from events.models import Event
from . import settings, managers from . import settings, managers
@@ -197,9 +199,14 @@ class Ranking(models.Model):
self.save() self.save()
def update_maistar_ranking(sender, instance, **kwargs): @receiver([post_delete, post_save], sender=Game)
"""A Django signal hook to trigger a recalculation of the rankings as soon def update_maistar_ranking(sender, **kwargs):
as a Mai-Star game has been added, deleted, or modified.""" """
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: for player in instance.player_list:
ranking, created = Ranking.objects.get_or_create( ranking, created = Ranking.objects.get_or_create(
user=player['user'], user=player['user'],
@@ -213,7 +220,3 @@ def update_maistar_ranking(sender, instance, **kwargs):
player['user'].username, instance.season) player['user'].username, instance.season)
ranking.recalculate() ranking.recalculate()
Ranking.objects.calculate_rankings(instance.season) 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)

View File

@@ -9,19 +9,26 @@ from easy_thumbnails import fields, widgets
from membership.models import Membership, ActivationRequest from membership.models import Membership, ActivationRequest
def activate_user(modeladmin, request, queryset): # Ignore PyLintBear (W0613) def activate_user(modeladmin, request, queryset):
"""Triggers activation of the selects actication requests by hand.""" """Triggers activation of the selects actication requests by hand.
for activation in queryset:
membership = Membership.objects.get(username=activation.user.username) :param modeladmin: The ModelAdmin that triggered this action.
membership.save() :param request: An HttpRequest representing the current request.
activation.activate() :param queryset: A QuerySet containing the objects selected by the user.
"""
[activation.activate() for activation in queryset ]
activate_user.short_description = _('Activate selected User') activate_user.short_description = _('Activate selected User')
def cleanup_activation(modeladmin, request, queryset): # Ignore PyLintBear (W0613) 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: for activation in queryset:
if activation.expired: if activation.expired:
activation.user.delete() activation.user.delete()

View File

@@ -56,8 +56,8 @@ class ActivationManager(models.Manager):
"""Creates a PendingActivation instance with an random activation key. """Creates a PendingActivation instance with an random activation key.
@param user: the user that requests activation. @param user: the user that requests activation.
""" """
salt = str(user.pk * random.random()) + \ salt = str(user.pk * random.random())
user.registration_date.isoformat() salt += user.registration_date.isoformat()
activation_key = hashlib.sha1(salt.encode()).hexdigest() activation_key = hashlib.sha1(salt.encode()).hexdigest()
return self.create(user=user, activation_key=activation_key) return self.create(user=user, activation_key=activation_key)