summaryrefslogtreecommitdiff
path: root/devel/views.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-29 13:53:55 -0500
committerDan McGee <dan@archlinux.org>2011-03-29 13:53:55 -0500
commit36f8649c36c0fa6af02247e0a796b79df8b1eb2b (patch)
tree157de0c3bb7e6438d793bfbf5cd91bd6703592d8 /devel/views.py
parent6fa773bcabe64f1f413fb2796078380fd3abf895 (diff)
Show important fields first on new user form
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'devel/views.py')
-rw-r--r--devel/views.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/devel/views.py b/devel/views.py
index 5b8965d8..b774e0e2 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -119,14 +119,25 @@ def change_profile(request):
{'form': form, 'profile_form': profile_form})
class NewUserForm(forms.ModelForm):
- class Meta:
- model = UserProfile
- exclude = ('picture', 'user')
username = forms.CharField(max_length=30)
- email = forms.EmailField()
+ private_email = forms.EmailField()
first_name = forms.CharField(required=False)
last_name = forms.CharField(required=False)
+ class Meta:
+ model = UserProfile
+ exclude = ('picture', 'user')
+
+ def __init__(self, *args, **kwargs):
+ super(NewUserForm, self).__init__(*args, **kwargs)
+ # Hack ourself so certain fields appear first. self.fields is a
+ # SortedDict object where we can manipulate the keyOrder list.
+ order = self.fields.keyOrder
+ keys = ('username', 'private_email', 'first_name', 'last_name')
+ for key in reversed(keys):
+ order.remove(key)
+ order.insert(0, key)
+
def clean_username(self):
username = self.cleaned_data['username']
if User.objects.filter(username=username).exists():
@@ -139,7 +150,7 @@ class NewUserForm(forms.ModelForm):
pwletters = ascii_letters + digits
password = ''.join([random.choice(pwletters) for i in xrange(8)])
user = User.objects.create_user(username=self.cleaned_data['username'],
- email=self.cleaned_data['email'], password=password)
+ email=self.cleaned_data['private_email'], password=password)
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.save()