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)
        del self.fields["username"]
        self.fields.keyOrder = [
            "email",
            "email_confirm",
            "first_name",
            "last_name",
            "password",
            "password_confirm"
        ]

    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

@@ -1,8 +1,45 @@
+from collections import OrderedDict%0A%0A
 from dja
@@ -55,16 +55,16 @@
 t forms%0A
-
 %0Aimport 
@@ -401,24 +401,13 @@
     
-self.fields.
 key
-O
+_o
 rder
@@ -576,16 +576,77 @@
        %5D
+%0A        self.fields = reorder_fields(self.fields, key_order)
 %0A%0A    de
@@ -961,16 +961,16 @@
 dress%22)%0A
-
         
@@ -990,8 +990,450 @@
 confirm%0A
+%0A%0Adef reorder_fields(fields, order):%0A    %22%22%22Reorder form fields by order, removing items not in order.%0A%0A    %3E%3E%3E reorder_fields(%0A    ...     OrderedDict(%5B('a', 1), ('b', 2), ('c', 3)%5D),%0A    ...     %5B'b', 'c', 'a'%5D)%0A    OrderedDict(%5B('b', 2), ('c', 3), ('a', 1)%5D)%0A    %22%22%22%0A    for key, v in fields.items():%0A        if key not in order:%0A            del fields%5Bkey%5D%0A%0A    return OrderedDict(sorted(fields.items(), key=lambda k: order.index(k%5B0%5D)))%0A

reorder signup fields