src/ldt/ldt/user/admin.py
author cavaliet
Fri, 30 Dec 2011 18:16:44 +0100
changeset 314 1a8620e5ebb0
parent 257 c00d78bca464
child 393 fa07a599883c
permissions -rw-r--r--
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
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
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
     8
from models import Ldt, UserProfile
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
     9
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    10
class GroupAdmin(GuardedModelAdmin):
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    11
    pass
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    12
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
    13
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
    14
    model = UserProfile
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    15
    
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    16
class UserProfileAdmin(UserAdmin):
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    17
    inlines = [UserProfileInline, ]
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    18
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    19
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
    20
    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
    21
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    22
    fieldsets = [
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    23
        (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
    24
        (_('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
    25
        (_('Groups'), {'fields': ('groups',)}),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    26
        (_('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
    27
    ]    
156
c4b5d188d111 Corrected class names in forms #11
verrierj
parents: 155
diff changeset
    28
    form = LdtForm
155
73ce005c4727 Changed name of class user.models.ldt to user.Ldt
verrierj
parents: 130
diff changeset
    29
    model = Ldt
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    30
    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
    31
    inlines = [UserProfileInline, ]
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    32
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    33
    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
    34
        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
    35
        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
    36
            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
    37
            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
    38
        return fieldsets
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    39
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    40
    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
    41
        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
    42
    
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    43
    
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    44
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    45
admin.site.unregister(Group)
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    46
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
    47
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
    48
admin.site.unregister(Ldt) 
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    49
admin.site.register(Ldt, LdtAdmin)
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    50
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    51
admin.site.unregister(User)
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    52
admin.site.register(User, UserProfileAdmin)