Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Hide confusing password field from user change form

  • Loading branch information...
commit 497c7975ec06a0ad9df5224e5b82f14aa3c890df 1 parent e2d3509
@yumike yumike authored
Showing with 27 additions and 2 deletions.
  1. +1 −0  HISTORY.rst
  2. +3 −2 lemon/admin.py
  3. +23 −0 lemon/forms.py
View
1  HISTORY.rst
@@ -4,6 +4,7 @@ History
next release
------------
+* Hide confusing password field from user change form
* Custom admin menu items can be added now using project settings
0.7.2
View
5 lemon/admin.py
@@ -6,7 +6,7 @@
from .options import TabularInline, ModelAdmin
from .sites import site
-from .forms import MenuItemForm
+from .forms import UserChangeForm, MenuItemForm
from .forms import contenttype_inlineformset_factory
from .models import MenuSection, MenuItem
@@ -49,7 +49,7 @@ class MenuSectionAdmin(ModelAdmin):
class UserExtrAdmin(ModelAdmin, UserAdmin):
fieldsets = (
- (None, {'fields': ('username', 'password')}),
+ (None, {'fields': ('username',)}),
(_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions')}),
@@ -64,6 +64,7 @@ class UserExtrAdmin(ModelAdmin, UserAdmin):
u"Then, you'll be able to edit more user options.")}
),
)
+ form = UserChangeForm
string_overrides = {
'add_title': _(u'Add user'),
'change_title': _(u'Change user'),
View
23 lemon/forms.py
@@ -1,4 +1,5 @@
from django import forms
+from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.forms.formsets import formset_factory
from django.forms.models import BaseInlineFormSet
@@ -8,6 +9,28 @@
from .fields import ContentTypeChoiceField
+class UserChangeForm(forms.ModelForm):
+
+ username = forms.RegexField(
+ label=_('Username'),
+ max_length=30,
+ regex=r'^[\w.@+-]+$',
+ help_text=_(
+ 'Required. 30 characters or fewer. Letters, digits and '
+ '@/./+/-/_ only.'
+ ),
+ error_messages={
+ 'invalid': _(
+ 'This value may contain only letters, numbers and @/./+/-/_ '
+ 'characters.'
+ )
+ }
+ )
+
+ class Meta:
+ model = User
+
+
class MenuItemForm(forms.ModelForm):
admin_site = None

3 comments on commit 497c797

@saippuakauppias
Collaborator

And as we now change the password in the admin interface?

@yumike
Owner

@saippuakauppias This field contained hashed password (and wasn't editable). You still can change user password using dedicated form ('Change password' button).

@saippuakauppias
Collaborator

Hmm... Thanks! I'm upped version in requirements :)

Please sign in to comment.
Something went wrong with that request. Please try again.