blob: 85c3ebddc55bdfc9ea94d95f4d2c5af185e1a6bd [file] [log] [blame]
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001from django.contrib import admin
2
3from syndicate.models import *
4from django import forms
5from django.utils.safestring import mark_safe
6from django.contrib.auth.admin import UserAdmin
7from django.contrib.admin.widgets import FilteredSelectMultiple
8from django.contrib.auth.forms import ReadOnlyPasswordHashField
9from django.contrib.auth.signals import user_logged_in
10from django.utils import timezone
11from django.contrib.contenttypes import generic
12from suit.widgets import LinkedSelect
13from core.admin import ReadOnlyTabularInline,ReadOnlyAwareAdmin,SingletonAdmin,SliceInline,ServiceAttrAsTabInline,PlanetStackBaseAdmin, PlStackTabularInline,SliceROInline,ServiceAttrAsTabROInline
14from suit.widgets import LinkedSelect
15from bitfield import BitField
16from bitfield.forms import BitFieldCheckboxSelectMultiple
17
18class SyndicateServiceAdmin(SingletonAdmin,ReadOnlyAwareAdmin):
19 model = SyndicateService
20 verbose_name = "Syndicate Service"
21 verbose_name_plural = "Syndicate Service"
22 list_display = ("name","enabled")
23 fieldsets = [(None, {'fields': ['name','enabled','versionNumber', 'description',], 'classes':['suit-tab suit-tab-general']})]
24 inlines = [SliceInline,ServiceAttrAsTabInline]
25
26 user_readonly_fields = ['name','enabled','versionNumber','description']
27 user_readonly_inlines = [SliceROInline, ServiceAttrAsTabROInline]
28
29 suit_form_tabs =(('general', 'Syndicate Service Details'),
30 ('slices','Slices'),
31 ('serviceattrs','Additional Attributes'),
32 )
33
34class VolumeAccessRightForUserROInline(ReadOnlyTabularInline):
35 model = VolumeAccessRight
36 extra = 0
37 suit_classes = 'suit-tab suit-tab-volumeAccessRights'
38 fields = ['volume','gateway_caps']
39
40class VolumeAccessRightROInline(ReadOnlyTabularInline):
41 model = VolumeAccessRight
42 extra = 0
43 suit_classes = 'suit-tab suit-tab-volumeAccessRights'
44 fields = ['owner_id','gateway_caps']
45
46class VolumeAccessRightInline(PlStackTabularInline):
47 model = VolumeAccessRight
48 extra = 0
49 suit_classes = 'suit-tab suit-tab-volumeAccessRights'
50
51class VolumeAccessRightAdmin(ReadOnlyAwareAdmin):
52 model = VolumeAccessRight
53
54 formfield_overrides = { BitField: {'widget': BitFieldCheckboxSelectMultiple},}
55 list_display = ['owner_id', 'volume']
56 user_readonly_fields = ['owner_id','volume','gateway_caps']
57 user_readonly_inlines = []
58
59class VolumeAccessRequestForUserROInline(ReadOnlyTabularInline):
60 model = VolumeAccessRequest
61 extra = 0
62 suit_classes = 'suit-tab suit-tab-volumeAccessRequests'
63 fields = ['volume', 'message']
64
65class VolumeAccessRequestROInline(ReadOnlyTabularInline):
66 model = VolumeAccessRequest
67 extra = 0
68 suit_classes = 'suit-tab suit-tab-volumeAccessRequests'
69 fields = ['owner_id', 'message']
70
71class VolumeAccessRequestInline(PlStackTabularInline):
72 model = VolumeAccessRequest
73 extra = 0
74 suit_classes = 'suit-tab suit-tab-volumeAccessRequests'
75 fields = ['owner_id', 'message']
76
77class VolumeAccessRequestAdmin(ReadOnlyAwareAdmin):
78 model = VolumeAccessRequest
79
80 formfield_overrides = { BitField: {'widget': BitFieldCheckboxSelectMultiple},}
81 list_display = ['owner_id', 'volume', 'message']
82 user_readonly_fields = ['volume','owner_id','message','message', 'gateway_caps']
83 user_readonly_inlines = []
84
85class VolumeInline(PlStackTabularInline):
86 model = Volume
87 extra = 0
88 suit_classes = 'suit-tab suit-tab-volumes'
89 fields = ['name', 'owner_id']
90
91class VolumeROInline(ReadOnlyTabularInline):
92 model = Volume
93 extra = 0
94 suit_classes = 'suit-tab suit-tab-volumes'
95 fields = ['name', 'owner_id']
96
97class VolumeAdmin(ReadOnlyAwareAdmin):
98 model = Volume
99 read_only_fields = ['blockSize']
100 list_display = ['name', 'owner_id']
101
102 formfield_overrides = { BitField: {'widget': BitFieldCheckboxSelectMultiple},}
103
104 detailsFieldList = ['name', 'owner_id', 'description','file_quota','blocksize', 'private','archive', 'default_gateway_caps' ]
105 keyList = ['metadata_public_key','metadata_private_key','api_public_key']
106
107 fieldsets = [
108 (None, {'fields': detailsFieldList, 'classes':['suit-tab suit-tab-general']}),
109 (None, {'fields': keyList, 'classes':['suit-tab suit-tab-volumeKeys']}),
110 ]
111
112 inlines = [VolumeAccessRightInline, VolumeAccessRequestInline]
113
114 user_readonly_fields = ['name','owner_id','description','blocksize','private','metadata_public_key','metadata_private_key','api_public_key','file_quota','default_gateway_caps']
115 user_readonly_inlines = [VolumeAccessRightROInline, VolumeAccessRequestROInline]
116
117 suit_form_tabs =(('general', 'Volume Details'),
118 ('volumeKeys', 'Access Keys'),
119 ('volumeAccessRequests', 'Volume Access Requests'),
120 ('volumeAccessRights', 'Volume Access Rights'),
121 )
122
123
124
125class SyndicateUserAdmin(ReadOnlyAwareAdmin):
126 model = SyndicateUser
127 verbose_name = "Users"
128 verbose_name = "Users"
129 list_display = ['user','is_admin', 'max_volumes']
130 inlines = [VolumeInline,VolumeAccessRequestInline,VolumeAccessRightInline]
131 user_readonly_fields = ['user','is_admin','max_volumes','max_UGs','max_RGs','max_AGs']
132 user_readonly_inlines = [VolumeROInline,VolumeAccessRequestForUserROInline,VolumeAccessRightForUserROInline]
133
134 fieldsets = [
135 (None, {'fields': ['user','is_admin','max_volumes','max_UGs','max_RGs','max_AGs'], 'classes':['suit-tab suit-tab-general']}),
136 ]
137
138 suit_form_tabs =(('general', 'Volume Details'),
139 ('volumes', 'Volumes'),
140 ('volumeAccessRequests', 'Volume Access Requests'),
141 ('volumeAccessRights', 'Volume Access Rights'),
142 )
143
144admin.site.register(SyndicateService, SyndicateServiceAdmin)
145admin.site.register(VolumeAccessRight, VolumeAccessRightAdmin)
146admin.site.register(VolumeAccessRequest, VolumeAccessRequestAdmin)
147admin.site.register(Volume, VolumeAdmin)
148admin.site.register(SyndicateUser, SyndicateUserAdmin)
149