Another Step in the Quest to clean up the code base.

This commit is contained in:
2017-09-08 07:19:50 +02:00
parent ce218080b2
commit b3ab9798b5
229 changed files with 1915 additions and 15175 deletions

View File

@@ -1,5 +1,4 @@
# -*- encoding: utf-8 -*-
__author__ = 'christian'
"""Django Forms to add and edit Mai-Star games."""
from django import forms
from django.utils.translation import ugettext as _
@@ -8,10 +7,12 @@ from . import models
class GameForm(forms.ModelForm):
"""To add/edit a Mai-Star game for the ladder ranking."""
error_css_class = 'error'
required_css_class = 'required'
class Meta(object):
"""hide the metadata in the form."""
fields = [
'player1', 'player1_score',
'player2', 'player2_score',
@@ -24,14 +25,15 @@ class GameForm(forms.ModelForm):
model = models.Game
def clean(self):
"""Check that every player occours only once per game."""
cleaned_data = super(GameForm, self).clean()
players_in_game = set()
for player_nr in (
'player1', 'player2', 'player3', 'player4', 'player5', 'player6'):
current_player = cleaned_data.get(player_nr)
for player_no in range(1, 6):
player = 'player{nr}'.format(nr=player_no)
current_player = cleaned_data.get('player')
if current_player and current_player in players_in_game:
msg = _("%s may only participate once." % current_player)
self._errors[player_nr] = self.error_class([msg])
del cleaned_data[player_nr]
self._errors[player] = self.error_class([msg])
del cleaned_data[player]
players_in_game.add(current_player)
return cleaned_data