src/ldt/ldt/user/admin.py
author ymh <ymh.work@gmail.com>
Fri, 25 May 2012 19:14:21 +0200
changeset 647 7c2ef57a1bc5
parent 393 fa07a599883c
child 854 e4be64dd42af
permissions -rw-r--r--
correct virtualenv install, remove ref to uwsgi and memcached
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     1
from copy import deepcopy #@UnresolvedImport
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     2
from django.contrib import admin
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     3
from django.contrib.auth.admin import UserAdmin
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
     4
from django.contrib.auth.models import Group, User
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     5
from django.utils.translation import ugettext as _
156
c4b5d188d111 Corrected class names in forms #11
verrierj
parents: 155
diff changeset
     6
from forms import LdtForm
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
     7
from guardian.admin import GuardedModelAdmin
393
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
     8
from models import Ldt, UserProfile, GroupProfile
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
     9
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
    10
class GroupProfileInline(admin.StackedInline):
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
    11
    model = GroupProfile
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    12
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    13
class GroupAdmin(GuardedModelAdmin):
393
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
    14
    inlines = [GroupProfileInline, ]
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    15
252
83eea387fe59 Field is_regular can be changed in admin pages, non regular users cann not change, edit or create groups
verrierj
parents: 249
diff changeset
    16
class UserProfileInline(admin.StackedInline):
83eea387fe59 Field is_regular can be changed in admin pages, non regular users cann not change, edit or create groups
verrierj
parents: 249
diff changeset
    17
    model = UserProfile
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    18
    
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    19
class UserProfileAdmin(UserAdmin):
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    20
    inlines = [UserProfileInline, ]
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    21
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    22
class LdtAdmin(UserProfileAdmin):    
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    23
    list_display = ('username', 'email', 'first_name', 'last_name')
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    24
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    25
    fieldsets = [
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    26
        (None, {'fields': ('username', ('password1', 'password2'))}),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    27
        (_('User details'), {'fields': (('first_name', 'last_name'), 'email')}),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    28
        (_('Groups'), {'fields': ('groups',)}),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    29
        (_('Permissions'), {'fields': ('is_staff', 'user_permissions')}),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    30
    ]    
156
c4b5d188d111 Corrected class names in forms #11
verrierj
parents: 155
diff changeset
    31
    form = LdtForm
155
73ce005c4727 Changed name of class user.models.ldt to user.Ldt
verrierj
parents: 130
diff changeset
    32
    model = Ldt
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    33
    filter_horizontal = ('user_permissions',)
252
83eea387fe59 Field is_regular can be changed in admin pages, non regular users cann not change, edit or create groups
verrierj
parents: 249
diff changeset
    34
    inlines = [UserProfileInline, ]
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    35
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    36
    def get_fieldsets(self, request, obj=None): 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    37
        fieldsets = deepcopy(self.fieldsets)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    38
        if not '/add' in request.path:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    39
            fieldsets[0] = (None, {'fields': ('username',)})
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    40
            fieldsets.append((_('Password'), {'fields': ('password1', 'password2'), 'classes': ('collapse',)}))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    41
        return fieldsets
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    42
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    43
    def add_view(self, request):
252
83eea387fe59 Field is_regular can be changed in admin pages, non regular users cann not change, edit or create groups
verrierj
parents: 249
diff changeset
    44
        return super(UserAdmin, self).add_view(request)  
83eea387fe59 Field is_regular can be changed in admin pages, non regular users cann not change, edit or create groups
verrierj
parents: 249
diff changeset
    45
    
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    46
    
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    47
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    48
admin.site.unregister(Group)
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    49
admin.site.register(Group, GroupAdmin)
252
83eea387fe59 Field is_regular can be changed in admin pages, non regular users cann not change, edit or create groups
verrierj
parents: 249
diff changeset
    50
83eea387fe59 Field is_regular can be changed in admin pages, non regular users cann not change, edit or create groups
verrierj
parents: 249
diff changeset
    51
admin.site.unregister(Ldt) 
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    52
admin.site.register(Ldt, LdtAdmin)
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    53
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    54
admin.site.unregister(User)
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    55
admin.site.register(User, UserProfileAdmin)