Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8b3e8b

Browse files
committed
validate user has first/last name in user profile when self nominating
1 parentd3247b9 commitf8b3e8b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

‎nominations/forms.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fromdjangoimportforms
2+
fromdjango.utils.safestringimportmark_safe
23

34
frommarkupfield.widgetsimportMarkupTextarea
45

@@ -30,7 +31,23 @@ class Meta:
3031

3132

3233
classNominationCreateForm(NominationForm):
34+
def__init__(self,*args,**kwargs):
35+
self.request=kwargs.pop("request",None)
36+
super(NominationCreateForm,self).__init__(*args,**kwargs)
37+
3338
self_nomination=forms.BooleanField(
3439
required=False,
3540
help_text="If you are nominating yourself, we will automatically associate the nomination with your python.org user.",
3641
)
42+
43+
defclean_self_nomination(self):
44+
data=self.cleaned_data["self_nomination"]
45+
ifdata:
46+
ifnotself.request.user.first_nameornotself.request.user.last_name:
47+
raiseforms.ValidationError(
48+
mark_safe(
49+
'You must set your First and Last name in your <a href="/users/edit/">User Profile</a> to self nominate.'
50+
)
51+
)
52+
53+
returndata

‎nominations/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class NominationCreate(LoginRequiredMixin, NominationMixin, CreateView):
5959

6060
login_message="Please login to make a nomination."
6161

62+
defget_form_kwargs(self):
63+
kwargs=super(NominationCreate,self).get_form_kwargs()
64+
kwargs.update({"request":self.request})
65+
returnkwargs
66+
6267
defget_form_class(self):
6368
election=Election.objects.get(slug=self.kwargs["election"])
6469
ifelection.nominations_complete:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp