Last active
May 3, 2024 23:10
-
-
Save ambivalentno/9d6828fe8b5d894a6f2d to your computer and use it in GitHub Desktop.
django-crispy-form with bootstrap for django-allauth login. Note: now (2014-08-05) you have to install master allauth from github to override forms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load crispy_forms_tags %} | |
{% block content %} | |
{% crispy form %} | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACCOUNT_FORMS = { | |
"login": "users.forms.CustomLoginForm" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.urlresolvers import reverse | |
from django.utils.translation import ugettext as _ | |
from allauth.account.forms import LoginForm | |
from crispy_forms.helper import FormHelper | |
from crispy_forms.layout import HTML | |
class CustomLoginForm(LoginForm): | |
def __init__(self, *args, **kwargs): | |
super(CustomLoginForm, self).__init__(*args, **kwargs) | |
self.helper = FormHelper(self) | |
# Add magic stuff to redirect back. | |
self.helper.layout.append( | |
HTML( | |
"{% if redirect_field_value %}" | |
"<input type='hidden' name='{{ redirect_field_name }}'" | |
" value='{{ redirect_field_value }}' />" | |
"{% endif %}" | |
) | |
) | |
# Add password reset link. | |
self.helper.layout.append( | |
HTML( | |
"<p><a class='button secondaryAction' href={url}>{text}</a></p>".format( | |
url=reverse('account_reset_password'), | |
text=_('Forgot Password?') | |
) | |
) | |
) | |
# Add submit button like in original form. | |
self.helper.layout.append( | |
HTML( | |
'<button class="btn btn-primary btn-block" type="submit">' | |
'%s</button>' % _('Sign In') | |
) | |
) | |
self.helper.form_class = 'form-horizontal' | |
self.helper.label_class = 'col-xs-2 hide' | |
self.helper.field_class = 'col-xs-8' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment