src/ldt/ldt/user/admin.py
author ymh <ymh.work@gmail.com>
Wed, 16 Jan 2013 05:09:22 +0100
changeset 1065 1bee39cbd1ea
parent 854 e4be64dd42af
child 1187 73403060f297
permissions -rw-r--r--
add authentication to roject resource
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
1065
1bee39cbd1ea add authentication to roject resource
ymh <ymh.work@gmail.com>
parents: 854
diff changeset
     9
from tastypie.admin import ApiKeyInline
1bee39cbd1ea add authentication to roject resource
ymh <ymh.work@gmail.com>
parents: 854
diff changeset
    10
from tastypie.models import ApiAccess, ApiKey
1bee39cbd1ea add authentication to roject resource
ymh <ymh.work@gmail.com>
parents: 854
diff changeset
    11
393
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
    12
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
    13
class GroupProfileInline(admin.StackedInline):
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
    14
    model = GroupProfile
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    15
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    16
class GroupAdmin(GuardedModelAdmin):
393
fa07a599883c GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents: 257
diff changeset
    17
    inlines = [GroupProfileInline, ]
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    18
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
    19
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
    20
    model = UserProfile
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    21
    
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    22
class UserProfileAdmin(UserAdmin):
854
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    23
    def add_view(self, *args, **kwargs):
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    24
        self.inlines = []
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    25
        return super(UserProfileAdmin, self).add_view(*args, **kwargs)
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    26
    
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    27
    def change_view(self, *args, **kwargs):
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    28
        self.inlines = [UserProfileInline]
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    29
        return super(UserAdmin, self).change_view(*args, **kwargs)
e4be64dd42af correct admin.
ymh <ymh.work@gmail.com>
parents: 393
diff changeset
    30
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    31
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    32
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
    33
    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
    34
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    35
    fieldsets = [
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    36
        (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
    37
        (_('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
    38
        (_('Groups'), {'fields': ('groups',)}),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    39
        (_('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
    40
    ]    
156
c4b5d188d111 Corrected class names in forms #11
verrierj
parents: 155
diff changeset
    41
    form = LdtForm
155
73ce005c4727 Changed name of class user.models.ldt to user.Ldt
verrierj
parents: 130
diff changeset
    42
    model = Ldt
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    43
    filter_horizontal = ('user_permissions',)
1065
1bee39cbd1ea add authentication to roject resource
ymh <ymh.work@gmail.com>
parents: 854
diff changeset
    44
    inlines = [UserProfileInline, ApiKeyInline]
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    45
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    46
    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
    47
        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
    48
        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
    49
            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
    50
            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
    51
        return fieldsets
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    52
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
    53
    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
    54
        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
    55
    
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    56
    
249
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    57
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    58
admin.site.unregister(Group)
5c5fab6d8ae8 Add admin permission panel to Group, Media, Author
verrierj
parents: 156
diff changeset
    59
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
    60
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
    61
admin.site.unregister(Ldt) 
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    62
admin.site.register(Ldt, LdtAdmin)
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    63
1065
1bee39cbd1ea add authentication to roject resource
ymh <ymh.work@gmail.com>
parents: 854
diff changeset
    64
admin.site.register(ApiKey)
1bee39cbd1ea add authentication to roject resource
ymh <ymh.work@gmail.com>
parents: 854
diff changeset
    65
admin.site.register(ApiAccess)
1bee39cbd1ea add authentication to roject resource
ymh <ymh.work@gmail.com>
parents: 854
diff changeset
    66
257
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    67
admin.site.unregister(User)
c00d78bca464 Profile can be accessed through iriusers and users
verrierj
parents: 252
diff changeset
    68
admin.site.register(User, UserProfileAdmin)