Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
| 3 | from syndicate.models import * |
| 4 | from django import forms |
| 5 | from django.utils.safestring import mark_safe |
| 6 | from django.contrib.auth.admin import UserAdmin |
| 7 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 8 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 9 | from django.contrib.auth.signals import user_logged_in |
| 10 | from django.utils import timezone |
| 11 | from django.contrib.contenttypes import generic |
| 12 | from suit.widgets import LinkedSelect |
| 13 | from core.admin import ReadOnlyTabularInline,ReadOnlyAwareAdmin,SingletonAdmin,SliceInline,ServiceAttrAsTabInline,PlanetStackBaseAdmin, PlStackTabularInline,SliceROInline,ServiceAttrAsTabROInline |
| 14 | from suit.widgets import LinkedSelect |
| 15 | from bitfield import BitField |
| 16 | from bitfield.forms import BitFieldCheckboxSelectMultiple |
| 17 | |
| 18 | class 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 | |
| 34 | class VolumeAccessRightForUserROInline(ReadOnlyTabularInline): |
| 35 | model = VolumeAccessRight |
| 36 | extra = 0 |
| 37 | suit_classes = 'suit-tab suit-tab-volumeAccessRights' |
| 38 | fields = ['volume','gateway_caps'] |
| 39 | |
| 40 | class VolumeAccessRightROInline(ReadOnlyTabularInline): |
| 41 | model = VolumeAccessRight |
| 42 | extra = 0 |
| 43 | suit_classes = 'suit-tab suit-tab-volumeAccessRights' |
| 44 | fields = ['owner_id','gateway_caps'] |
| 45 | |
| 46 | class VolumeAccessRightInline(PlStackTabularInline): |
| 47 | model = VolumeAccessRight |
| 48 | extra = 0 |
| 49 | suit_classes = 'suit-tab suit-tab-volumeAccessRights' |
| 50 | |
| 51 | class 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 | |
| 59 | class VolumeAccessRequestForUserROInline(ReadOnlyTabularInline): |
| 60 | model = VolumeAccessRequest |
| 61 | extra = 0 |
| 62 | suit_classes = 'suit-tab suit-tab-volumeAccessRequests' |
| 63 | fields = ['volume', 'message'] |
| 64 | |
| 65 | class VolumeAccessRequestROInline(ReadOnlyTabularInline): |
| 66 | model = VolumeAccessRequest |
| 67 | extra = 0 |
| 68 | suit_classes = 'suit-tab suit-tab-volumeAccessRequests' |
| 69 | fields = ['owner_id', 'message'] |
| 70 | |
| 71 | class VolumeAccessRequestInline(PlStackTabularInline): |
| 72 | model = VolumeAccessRequest |
| 73 | extra = 0 |
| 74 | suit_classes = 'suit-tab suit-tab-volumeAccessRequests' |
| 75 | fields = ['owner_id', 'message'] |
| 76 | |
| 77 | class 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 | |
| 85 | class VolumeInline(PlStackTabularInline): |
| 86 | model = Volume |
| 87 | extra = 0 |
| 88 | suit_classes = 'suit-tab suit-tab-volumes' |
| 89 | fields = ['name', 'owner_id'] |
| 90 | |
| 91 | class VolumeROInline(ReadOnlyTabularInline): |
| 92 | model = Volume |
| 93 | extra = 0 |
| 94 | suit_classes = 'suit-tab suit-tab-volumes' |
| 95 | fields = ['name', 'owner_id'] |
| 96 | |
| 97 | class 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 | |
| 125 | class 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 | |
| 144 | admin.site.register(SyndicateService, SyndicateServiceAdmin) |
| 145 | admin.site.register(VolumeAccessRight, VolumeAccessRightAdmin) |
| 146 | admin.site.register(VolumeAccessRequest, VolumeAccessRequestAdmin) |
| 147 | admin.site.register(Volume, VolumeAdmin) |
| 148 | admin.site.register(SyndicateUser, SyndicateUserAdmin) |
| 149 | |