Files
@ b5cf9f1541f2
Branch filter:
Location: symposion_app/symposion/forms.py - annotation
b5cf9f1541f2
1.6 KiB
text/x-python
Update README.rst
c22bcf9cf464 c22bcf9cf464 c22bcf9cf464 c22bcf9cf464 6f3115aee8a9 d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 36ab6d599ffc d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 6f3115aee8a9 d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 6f3115aee8a9 36ab6d599ffc d31953b54450 d31953b54450 d31953b54450 d31953b54450 d31953b54450 36ab6d599ffc 36ab6d599ffc d31953b54450 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 6f3115aee8a9 c22bcf9cf464 fa66316f8aca fa66316f8aca fa66316f8aca fa66316f8aca fa66316f8aca fa66316f8aca | try:
from collections import OrderedDict
except ImportError:
OrderedDict = None
from django import forms
import account.forms
class SignupForm(account.forms.SignupForm):
first_name = forms.CharField()
last_name = forms.CharField()
email_confirm = forms.EmailField(label="Confirm Email")
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(*args, **kwargs)
key_order = [
"email",
"email_confirm",
"first_name",
"last_name",
"password",
"password_confirm"
]
self.fields = reorder_fields(self.fields, key_order)
def clean_email_confirm(self):
email = self.cleaned_data.get("email")
email_confirm = self.cleaned_data["email_confirm"]
if email:
if email != email_confirm:
raise forms.ValidationError(
"Email address must match previously typed email address")
return email_confirm
def reorder_fields(fields, order):
"""Reorder form fields by order, removing items not in order.
>>> reorder_fields(
... OrderedDict([('a', 1), ('b', 2), ('c', 3)]),
... ['b', 'c', 'a'])
OrderedDict([('b', 2), ('c', 3), ('a', 1)])
"""
for key, v in fields.items():
if key not in order:
del fields[key]
if not OrderedDict or hasattr(fields, "keyOrder"):
# fields is SortedDict
fields.keyOrder.sort(key=lambda k: order.index(k[0]))
return fields
else:
# fields is OrderedDict
return OrderedDict(sorted(fields.items(), key=lambda k: order.index(k[0])))
|