-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforms.py
More file actions
110 lines (97 loc) · 4.19 KB
/
forms.py
File metadata and controls
110 lines (97 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: UTF-8 -*-
from __future__ import unicode_literals
from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from rudi.models import Team
LABEL_STREET = _("Straße")
LABEL_POSTAL_CODE = _("PLZ")
LABEL_CITY = _("Stadt")
LABEL_DOORBELL = _("Klingelinfo")
LABEL_FIRSTNAME = _("Vorname")
LABEL_LASTNAME = _("Nachname")
LABEL_EMAIL = _("E-Mail")
LABEL_PHONE = _("Handynummer")
LABEL_ALLERGIES = _("Allergien/ Unverträglichkeiten")
LABEL_LIKE = _("Wir würden am liebsten diesen Gang/ einen dieser Gänge "
"zubereiten")
LABEL_DISLIKE = _("Wir würden diesen Gang/ einen dieser Gänge lieber "
"nicht zubereiten")
LABEL_AGREE_TERMS = _("Teilnahmebedingungen")
INFO_NAME = _("Seid kreativ!")
INFO_DOORBELL = _("Gebt an, wo eure Gäste klingeln müssen und "
"in welches Stockwerk sie müssen")
INFO_AGREE_TERMS = _("Hiermit erklärt ihr euch einverstanden, dass wir "
"eure Handynummern an die Teams weiterleiten dürfen, "
"mit denen ihr gemeinsam essen werdet.")
ERROR_AGREE_TERMS =\
_('Du musst mit der weitergabe deiner/ eurer Handynummern '
'einverstanden sein.')
ERROR_PREFERENCES = _('Du kannst den selben Kurs nicht in beiden Listen haben')
class RegistrationForm(forms.ModelForm):
agree_terms = forms.BooleanField(
label=LABEL_AGREE_TERMS,
help_text=INFO_AGREE_TERMS,
error_messages={
'required': ERROR_AGREE_TERMS
})
class Meta:
model = Team
exclude = ("event",)
labels = {
"street": LABEL_STREET,
"postal_code": LABEL_POSTAL_CODE,
"city": LABEL_CITY,
"doorbell": LABEL_DOORBELL,
"participant_1_firstname": LABEL_FIRSTNAME,
"participant_2_firstname": LABEL_FIRSTNAME,
"participant_1_lastname": LABEL_LASTNAME,
"participant_2_lastname": LABEL_LASTNAME,
"participant_1_email": LABEL_EMAIL,
"participant_2_email": LABEL_EMAIL,
"participant_1_phone": LABEL_PHONE,
"participant_2_phone": LABEL_PHONE,
"allergies": LABEL_ALLERGIES,
"like": LABEL_LIKE,
"dislike": LABEL_DISLIKE,
}
help_texts = {
"name": INFO_NAME,
"doorbell": INFO_DOORBELL,
}
widgets = {
"name": forms.TextInput(attrs={'class': 'form-control'}),
"street": forms.TextInput(attrs={'class': 'form-control'}),
"city": forms.TextInput(attrs={'class': 'form-control'}),
"postal_code": forms.TextInput(attrs={'class': 'form-control'}),
"doorbell": forms.TextInput(attrs={'class': 'form-control'}),
"participant_1_firstname": forms.TextInput(
attrs={'class': 'form-control'}),
"participant_1_lastname": forms.TextInput(
attrs={'class': 'form-control'}),
"participant_1_email": forms.EmailInput(
attrs={'class': 'form-control'}),
"participant_1_phone": forms.TextInput(
attrs={'class': 'form-control'}),
"participant_2_firstname": forms.TextInput(
attrs={'class': 'form-control'}),
"participant_2_lastname": forms.TextInput(
attrs={'class': 'form-control'}),
"participant_2_email": forms.EmailInput(
attrs={'class': 'form-control'}),
"participant_2_phone": forms.TextInput(
attrs={'class': 'form-control'}),
"allergies": forms.Textarea(attrs={'class': 'form-control'}),
"like": forms.CheckboxSelectMultiple(),
"dislike": forms.CheckboxSelectMultiple(),
}
def clean(self):
cleaned_data = super(RegistrationForm, self).clean()
like = set(cleaned_data.get("like"))
dislike = set(cleaned_data.get("dislike"))
intersect = like & dislike
if intersect:
raise ValidationError(ERROR_PREFERENCES)
class CustomMailForm(forms.Form):
subject = forms.CharField(label="Subject")
body = forms.CharField(label="Body", widget=forms.Textarea)