1 from django import forms |
1 from django import forms |
2 from django.contrib import admin |
2 from django.contrib import admin |
3 from django.contrib.auth.admin import UserAdmin as BaseUserAdmin |
3 from django.contrib.auth.admin import UserAdmin as BaseUserAdmin |
|
4 from django.contrib.auth.forms import UserChangeForm as BaseUserChangeForm |
4 from django.contrib.auth.forms import ReadOnlyPasswordHashField |
5 from django.contrib.auth.forms import ReadOnlyPasswordHashField |
5 from django.utils.translation import ugettext, ugettext_lazy as _ |
6 from django.utils.translation import ugettext, ugettext_lazy as _ |
6 |
7 |
7 from .models import User |
8 from .models import User |
8 |
9 |
32 if commit: |
33 if commit: |
33 user.save() |
34 user.save() |
34 return user |
35 return user |
35 |
36 |
36 |
37 |
37 class UserChangeForm(forms.ModelForm): |
38 class UserChangeForm(BaseUserChangeForm): |
38 """A form for updating users. Includes all the fields on |
39 """A form for updating users. Includes all the fields on |
39 the user, but replaces the password field with admin's |
40 the user, but replaces the password field with admin's |
40 password hash display field. |
41 password hash display field. |
41 """ |
42 """ |
42 password = ReadOnlyPasswordHashField() |
|
43 |
43 |
44 class Meta: |
44 class Meta(BaseUserChangeForm.Meta): |
45 model = User |
45 model = User |
46 fields = ('external_id', 'username', 'uai', 'first_name', 'last_name', 'password', 'is_active', 'is_staff') |
46 # fields = ('external_id', 'username', 'uai', 'first_name', 'last_name', 'password', 'is_active', 'is_staff') |
47 |
47 |
48 |
48 |
49 class UserAdmin(BaseUserAdmin): |
49 class UserAdmin(BaseUserAdmin): |
50 # The forms to add and change user instances |
50 # The forms to add and change user instances |
51 form = UserChangeForm |
51 form = UserChangeForm |
52 add_form = UserCreationForm |
52 add_form = UserCreationForm |
53 |
53 |
54 # The fields to be used in displaying the User model. |
54 # The fields to be used in displaying the User model. |
55 # These override the definitions on the base UserAdmin |
55 # These override the definitions on the base UserAdmin |
56 # that reference specific fields on auth.User. |
56 # that reference specific fields on auth.User. |
57 list_display = ('external_id', 'username', 'uai', 'first_name', 'last_name', 'password', 'is_staff') |
57 list_display = ('external_id', 'username', 'uai', 'first_name', 'last_name') |
58 list_filter = ('is_staff',) |
58 list_filter = ('is_staff',) |
59 fieldsets = ( |
59 fieldsets = ( |
60 (None, {'fields': ('external_id', 'username')}), |
60 (None, {'fields': ('external_id', 'username', 'password')}), |
61 (_('Personal info'), {'fields': ('username', 'uai', 'first_name', 'last_name')}), |
61 (_('Personal info'), {'fields': ('uai', 'first_name', 'last_name')}), |
62 (_('Permissions'), {'fields': ('is_staff',)}), |
|
63 (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', |
62 (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', |
64 'groups', 'user_permissions')}), |
63 'groups', 'user_permissions')}), |
65 (_('Important dates'), {'fields': ('last_login', 'date_joined')}), |
64 (_('Important dates'), {'fields': ('last_login', 'date_joined')}), |
66 ) |
65 ) |
67 # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin |
66 # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin |