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 8f4bdec701
commit 6e2240ed5f
229 changed files with 1915 additions and 15175 deletions

View File

@@ -15,11 +15,13 @@ USER_MODEL = get_user_model()
class HanchanForm(forms.ModelForm):
""" Form to add/edit mahjong hanchans, grouped with formsets. """
error_css_class = 'error'
required_css_class = 'required'
start = forms.SplitDateTimeField(label=_('start'), required=True)
class Meta(object):
""" Medadata for better usability of the HanchanForm """
model = models.Hanchan
fields = ('start',
'player1', 'player1_input_score',
@@ -30,12 +32,14 @@ class HanchanForm(forms.ModelForm):
widgets = {
'event': forms.HiddenInput(),
'comment': forms.widgets.Textarea(attrs={'rows': 4, 'cols': 40})
}
}
def __init__(self, *args, **kwargs):
""" Overwrites some standard widgets for better usability. """
super(HanchanForm, self).__init__(*args, **kwargs)
player_queryset = USER_MODEL.objects.filter(is_active=True,
membership=True)
player_queryset = USER_MODEL.objects.filter(
is_active=True,
membership=True)
for i in range(1, 4):
player = 'player%d' % i
player_input_score = 'player%d_input_score' % i
@@ -45,18 +49,12 @@ class HanchanForm(forms.ModelForm):
class HanchanAdminForm(HanchanForm):
""" Extends the HanchanForm for users with admin privileges.
They are allowed to confirm/unconfirm Hanchans, this could be userful if
one games smells fishy and needs the opinion of an referee."""
class Meta(object):
""" Extend the formfields to add the confirmed checkbox. """
model = models.Hanchan
fields = HanchanForm.Meta.fields + ('confirmed',)
class SeasonSelectForm(forms.Form):
season = forms.ChoiceField(label='', choices=('a', 'b', 'c'))
def __init__(self, user, *args, **kwargs):
super(SeasonSelectForm, self).__init__(args, kwargs)
season_list = models.LadderRanking.objects.filter(user=user)
season_list = season_list.select_related('user')
season_list = season_list.values_list('season__id', 'season__name')
self.fields['season'] = forms.ChoiceField(choices=season_list)