mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-05-04 05:24:45 +00:00
replace django.contrib.admin introduced in last pull request with our own native form
This commit is contained in:
parent
fd6c0a57b3
commit
bf1657990a
2 changed files with 38 additions and 2 deletions
|
|
@ -1,9 +1,14 @@
|
|||
import floppyforms
|
||||
from __future__ import unicode_literals
|
||||
from copy import deepcopy
|
||||
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
import django.forms
|
||||
import django.forms.models
|
||||
import django.forms.extras.widgets
|
||||
from django.utils.translation import ugettext_lazy
|
||||
|
||||
import floppyforms
|
||||
|
||||
|
||||
_WIDGET_COMMON_ATTRIBUTES = (
|
||||
|
|
@ -225,3 +230,34 @@ def modelform_factory(model, form=django.forms.models.ModelForm, fields=None,
|
|||
formfield_callback=formfield_callback,
|
||||
widgets=widgets)
|
||||
return floppify_form(form_class)
|
||||
|
||||
|
||||
ERROR_MESSAGE = ugettext_lazy("Please enter the correct %(username)s and password "
|
||||
"for a staff account. Note that both fields may be case-sensitive.")
|
||||
|
||||
|
||||
class AdminAuthenticationForm(AuthenticationForm):
|
||||
"""
|
||||
A custom authentication form used in the admin app.
|
||||
Liberally copied from django.contrib.admin.forms.AdminAuthenticationForm
|
||||
|
||||
"""
|
||||
this_is_the_login_form = django.forms.BooleanField(widget=floppyforms.HiddenInput, initial=1,
|
||||
error_messages={'required': ugettext_lazy("Please log in again, because your session has expired.")})
|
||||
|
||||
def clean(self):
|
||||
username = self.cleaned_data.get('username')
|
||||
password = self.cleaned_data.get('password')
|
||||
message = ERROR_MESSAGE
|
||||
|
||||
if username and password:
|
||||
self.user_cache = authenticate(username=username, password=password)
|
||||
if self.user_cache is None:
|
||||
raise floppyforms.ValidationError(message % {
|
||||
'username': self.username_field.verbose_name
|
||||
})
|
||||
elif not self.user_cache.is_active or not self.user_cache.is_staff:
|
||||
raise floppyforms.ValidationError(message % {
|
||||
'username': self.username_field.verbose_name
|
||||
})
|
||||
return self.cleaned_data
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from django.contrib.admin.forms import AdminAuthenticationForm
|
||||
from django.contrib.auth.forms import (PasswordChangeForm,
|
||||
AdminPasswordChangeForm)
|
||||
from django.contrib.auth.views import (logout as auth_logout,
|
||||
|
|
@ -13,6 +12,7 @@ from django.views import generic
|
|||
import extra_views
|
||||
|
||||
from . import permissions, utils
|
||||
from .forms import AdminAuthenticationForm
|
||||
from .viewmixins import Admin2Mixin, AdminModel2Mixin, Admin2ModelFormMixin
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue