Anpassungen für das Hosting bei Djangoeurope und damit verbundenen Versionen Django 1.8 und Python 2.7
This commit is contained in:
committed by
Christian Berg
parent
cb4b15b3c6
commit
b96b485b61
37
src/maistar_ranking/forms.py
Normal file
37
src/maistar_ranking/forms.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
__author__ = 'christian'
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
class GameForm(forms.ModelForm):
|
||||
error_css_class = 'error'
|
||||
required_css_class = 'required'
|
||||
|
||||
class Meta(object):
|
||||
fields = [
|
||||
'player1', 'player1_score',
|
||||
'player2', 'player2_score',
|
||||
'player3', 'player3_score',
|
||||
'player4', 'player4_score',
|
||||
'player5', 'player5_score',
|
||||
'player6', 'player6_score',
|
||||
'comment'
|
||||
]
|
||||
model = models.Game
|
||||
|
||||
def clean(self):
|
||||
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)
|
||||
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]
|
||||
players_in_game.add(current_player)
|
||||
return cleaned_data
|
||||
Reference in New Issue
Block a user