-
Notifications
You must be signed in to change notification settings - Fork 619
/
Copy pathforms.py
64 lines (53 loc) · 2.17 KB
/
forms.py
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
from django import forms
from django.utils.safestring import mark_safe
from markupfield.widgets import MarkupTextarea
from .models import Nomination
class NominationForm(forms.ModelForm):
class Meta:
model = Nomination
fields = (
"name",
"email",
"previous_board_service",
"employer",
"other_affiliations",
"nomination_statement",
)
widgets = {
"nomination_statement": MarkupTextarea()
} # , "self_nomination": forms.CheckboxInput()}
help_texts = {
"name": "Name of the person you are nominating.",
"email": "Email address for the person you are nominating.",
"previous_board_service": "Has the person previously served on the PSF Board? If so what year(s)? Otherwise 'New board member'.",
"employer": "Nominee's current employer.",
"other_affiliations": "Any other relevant affiliations the Nominee has.",
"nomination_statement": "Markdown syntax supported.",
}
class NominationCreateForm(NominationForm):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request", None)
super().__init__(*args, **kwargs)
self_nomination = forms.BooleanField(
required=False,
help_text="If you are nominating yourself, we will automatically associate the nomination with your python.org user.",
)
def clean_self_nomination(self):
data = self.cleaned_data["self_nomination"]
if data:
if not self.request.user.first_name or not self.request.user.last_name:
raise forms.ValidationError(
mark_safe(
'You must set your First and Last name in your <a href="/users/edit/">User Profile</a> to self nominate.'
)
)
return data
class NominationAcceptForm(forms.ModelForm):
class Meta:
model = Nomination
fields = (
"accepted",
)
help_texts = {
"accepted": "If selected, this nomination will be considered accepted and displayed once nominations are public.",
}