Commits

Casey Greene committed 2654921

add crispy reset form

Comments (0)

Files changed (2)

registration/auth_urls.py

 
 from django.contrib.auth import views as auth_views
 
-from registration.forms import CrispyAuthForm
+from registration.forms import CrispyAuthForm, CrispyResetForm
 
 urlpatterns = patterns('',
                        url(r'^login/$',
                            name='auth_password_change_done'),
                        url(r'^password/reset/$',
                            auth_views.password_reset,
+                           {'password_reset_form': CrispyResetForm},
                            name='auth_password_reset'),
                        url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
                            auth_views.password_reset_confirm,

registration/forms.py

 
 
 from django.contrib.auth.models import User
-from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm
 from django import forms
 from django.utils.translation import ugettext_lazy as _
 
 from crispy_forms.helper import FormHelper
-from crispy_forms.layout import Submit, Layout, Field, HTML, ButtonHolder
+from crispy_forms.layout import Submit, Layout, Field, HTML, ButtonHolder, Fieldset
 
 # I put this on all required fields, because it's easier to pick up
 # on them with CSS or JavaScript if they have a class of "required"
 # lands in trunk, this will no longer be necessary.
 attrs_dict = {'class': 'required'}
 
+class CrispyResetForm(PasswordResetForm):
+    def __init__(self, *args, **kwargs):
+        super(CrispyResetForm, self).__init__(*args, **kwargs)
+        self.helper = FormHelper()
+        self.helper.form_method = 'post'
+        self.helper.form_action = 'auth_password_reset'
+        self.helper.layout = Layout(
+            Field('email'),
+            HTML("""
+                <a href="{% url registration_register %}">Register for an Account</a>
+            """),
+            ButtonHolder(
+                Submit('submit', 'Reset password', css_class='btn btn-primary')
+            )
+        )
 
 class CrispyAuthForm(AuthenticationForm):
     def __init__(self, *args, **kwargs):
+        super(CrispyAuthForm, self).__init__(*args, **kwargs)
         self.helper = FormHelper()
         self.helper.form_method = 'post'
         self.helper.form_action = 'auth_login'
             )
         )
 
-        super(CrispyAuthForm, self).__init__(*args, **kwargs)
-
 class RegistrationForm(forms.Form):
     """
     Form for registering a new user account.