Gabe Black | 4c040b7 | 2016-11-17 22:35:04 +0000 | [diff] [blame] | 1 | # admin.py - ActiveTest Django Admin |
| 2 | |
| 3 | from core.admin import ReadOnlyAwareAdmin, SliceInline |
| 4 | from core.middleware import get_request |
| 5 | from core.models import User |
| 6 | |
| 7 | from django import forms |
| 8 | from django.contrib import admin |
| 9 | |
| 10 | from services.activetest.models import * |
| 11 | |
| 12 | class ActiveTestForm(forms.ModelForm): |
| 13 | |
| 14 | class Meta: |
| 15 | model = ActiveTestService |
| 16 | fields = '__all__' |
| 17 | |
| 18 | class ActiveTestAdmin(ReadOnlyAwareAdmin): |
| 19 | |
| 20 | model = ActiveTestService |
| 21 | verbose_name = ACTIVETEST_SERVICE_NAME_VERBOSE |
| 22 | verbose_name_plural = ACTIVETEST_SERVICE_NAME_VERBOSE_PLURAL |
| 23 | form = ActiveTestForm |
| 24 | inlines = [SliceInline] |
| 25 | |
| 26 | list_display = ('backend_status_icon', 'name', 'enabled') |
| 27 | list_display_links = ('backend_status_icon', 'name' ) |
| 28 | |
| 29 | fieldsets = [(None, { |
| 30 | 'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'description',], |
| 31 | 'classes':['suit-tab suit-tab-general',], |
| 32 | })] |
| 33 | |
| 34 | readonly_fields = ('backend_status_text', ) |
| 35 | user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',] |
| 36 | |
| 37 | extracontext_registered_admins = True |
| 38 | |
| 39 | suit_form_tabs = ( |
| 40 | ('general', 'ActiveTest Details', ), |
| 41 | ('slices', 'Slices',), |
| 42 | ) |
| 43 | |
| 44 | suit_form_includes = (( |
| 45 | 'top', |
| 46 | 'administration'), |
| 47 | ) |
| 48 | |
| 49 | def get_queryset(self, request): |
| 50 | return ActiveTestService.get_service_objects_by_user(request.user) |
| 51 | |
| 52 | admin.site.register(ActiveTestService, ActiveTestAdmin) |
| 53 | |
| 54 | class ActiveTestTenantForm(forms.ModelForm): |
| 55 | |
| 56 | class Meta: |
| 57 | model = ActiveTestTenant |
| 58 | fields = '__all__' |
| 59 | |
| 60 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
| 61 | |
| 62 | def __init__(self, *args, **kwargs): |
| 63 | super(ActiveTestTenantForm, self).__init__(*args, **kwargs) |
| 64 | |
| 65 | self.fields['kind'].widget.attrs['readonly'] = True |
| 66 | self.fields['kind'].initial = ACTIVETEST_KIND |
| 67 | |
| 68 | self.fields['provider_service'].queryset = ActiveTestService.get_service_objects().all() |
| 69 | |
| 70 | if self.instance: |
| 71 | self.fields['creator'].initial = self.instance.creator |
| 72 | |
| 73 | if (not self.instance) or (not self.instance.pk): |
| 74 | self.fields['creator'].initial = get_request().user |
| 75 | if ActiveTestService.get_service_objects().exists(): |
| 76 | self.fields['provider_service'].initial = ActiveTestService.get_service_objects().all()[0] |
| 77 | |
| 78 | def save(self, commit=True): |
| 79 | self.instance.creator = self.cleaned_data.get('creator') |
| 80 | return super(ActiveTestTenantForm, self).save(commit=commit) |
| 81 | |
| 82 | |
| 83 | class ActiveTestTenantAdmin(ReadOnlyAwareAdmin): |
| 84 | |
| 85 | verbose_name = ACTIVETEST_TENANT_NAME_VERBOSE |
| 86 | verbose_name_plural = ACTIVETEST_TENANT_NAME_VERBOSE_PLURAL |
| 87 | |
| 88 | list_display = ('id', 'backend_status_icon', 'instance') |
| 89 | list_display_links = ('backend_status_icon', 'instance', 'id') |
| 90 | |
| 91 | fieldsets = [(None, { |
| 92 | 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator'], |
| 93 | 'classes': ['suit-tab suit-tab-general'], |
| 94 | })] |
| 95 | |
| 96 | readonly_fields = ('backend_status_text', 'instance',) |
| 97 | |
| 98 | form = ActiveTestTenantForm |
| 99 | |
| 100 | suit_form_tabs = (('general', 'Details'),) |
| 101 | |
| 102 | def get_queryset(self, request): |
| 103 | return ActiveTestTenant.get_tenant_objects_by_user(request.user) |
| 104 | |
| 105 | admin.site.register(ActiveTestTenant, ActiveTestTenantAdmin) |
| 106 | |
| 107 | ######################################################################################## |
| 108 | """ |
| 109 | class VpmaForm(forms.ModelForm): |
| 110 | |
| 111 | class Meta: |
| 112 | model = VpmaService |
| 113 | fields = '__all__' |
| 114 | |
| 115 | class VpmaAdmin(ReadOnlyAwareAdmin): |
| 116 | |
| 117 | model = VpmaService |
| 118 | verbose_name = VPMA_SERVICE_NAME_VERBOSE |
| 119 | verbose_name_plural = VPMA_SERVICE_NAME_VERBOSE_PLURAL |
| 120 | form = VpmaForm |
| 121 | inlines = [SliceInline] |
| 122 | |
| 123 | list_display = ('backend_status_icon', 'name', 'enabled') |
| 124 | list_display_links = ('backend_status_icon', 'name' ) |
| 125 | |
| 126 | fieldsets = [(None, { |
| 127 | 'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'description',], |
| 128 | 'classes':['suit-tab suit-tab-general',], |
| 129 | })] |
| 130 | |
| 131 | readonly_fields = ('backend_status_text', ) |
| 132 | user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',] |
| 133 | |
| 134 | extracontext_registered_admins = True |
| 135 | |
| 136 | suit_form_tabs = ( |
| 137 | ('general', 'Vpma Details', ), |
| 138 | ('slices', 'Slices',), |
| 139 | ) |
| 140 | |
| 141 | suit_form_includes = (( |
| 142 | 'top', |
| 143 | 'administration'), |
| 144 | ) |
| 145 | |
| 146 | def get_queryset(self, request): |
| 147 | return VpmaService.get_service_objects_by_user(request.user) |
| 148 | |
| 149 | admin.site.register(VpmaService, VpmaAdmin) |
| 150 | """ |
| 151 | class Qt600TenantForm(forms.ModelForm): |
| 152 | |
| 153 | class Meta: |
| 154 | model = Qt600Tenant |
| 155 | fields = '__all__' |
| 156 | |
| 157 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
| 158 | |
| 159 | def __init__(self, *args, **kwargs): |
| 160 | super(Qt600TenantForm, self).__init__(*args, **kwargs) |
| 161 | |
| 162 | self.fields['kind'].widget.attrs['readonly'] = True |
| 163 | self.fields['kind'].initial = ACTIVETEST_KIND |
| 164 | |
| 165 | self.fields['provider_service'].queryset = Qt600Service.get_service_objects().all() |
| 166 | |
| 167 | if self.instance: |
| 168 | self.fields['creator'].initial = self.instance.creator |
| 169 | self.fields['is_reflector'].initial = self.instance.is_reflector |
| 170 | self.fields['is_initiator'].initial = self.instance.is_initiator |
| 171 | self.fields['reflector'].initial = self.instance.reflector |
| 172 | |
| 173 | if (not self.instance) or (not self.instance.pk): |
| 174 | self.fields['creator'].initial = get_request().user |
| 175 | if Qt600Service.get_service_objects().exists(): |
| 176 | self.fields['provider_service'].initial = Qt600Service.get_service_objects().all()[0] |
| 177 | |
| 178 | def save(self, commit=True): |
| 179 | self.instance.creator = self.cleaned_data.get('creator') |
| 180 | self.instance.is_reflector = self.cleaned_data.get('is_reflector') |
| 181 | self.instance.is_initiator = self.cleaned_data.get('is_initiator') |
| 182 | self.instance.reflector = self.cleaned_data.get('reflector') |
| 183 | return super(Qt600TenantForm, self).save(commit=commit) |
| 184 | |
| 185 | class Qt600TenantAdmin(ReadOnlyAwareAdmin): |
| 186 | |
| 187 | verbose_name = QT600_TENANT_NAME_VERBOSE |
| 188 | verbose_name_plural = QT600_TENANT_NAME_VERBOSE_PLURAL |
| 189 | |
| 190 | list_display = ('id', 'backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector') |
| 191 | list_display_links = ('backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector', 'id') |
| 192 | |
| 193 | fieldsets = [(None, { |
| 194 | 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'is_reflector', 'is_initiator', 'reflector'], |
| 195 | 'classes': ['suit-tab suit-tab-general'], |
| 196 | })] |
| 197 | |
| 198 | readonly_fields = ('backend_status_text', 'instance',) |
| 199 | |
| 200 | form = Qt600TenantForm |
| 201 | |
| 202 | suit_form_tabs = (('general', 'Details'),) |
| 203 | |
| 204 | def get_queryset(self, request): |
| 205 | return Qt600Tenant.get_tenant_objects_by_user(request.user) |
| 206 | |
| 207 | admin.site.register(Qt600Tenant, Qt600TenantAdmin) |
| 208 | |
| 209 | class VpmaTenantForm(forms.ModelForm): |
| 210 | |
| 211 | class Meta: |
| 212 | model = VpmaTenant |
| 213 | fields = '__all__' |
| 214 | |
| 215 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
| 216 | |
| 217 | def __init__(self, *args, **kwargs): |
| 218 | super(VpmaTenantForm, self).__init__(*args, **kwargs) |
| 219 | |
| 220 | self.fields['kind'].widget.attrs['readonly'] = True |
| 221 | self.fields['kind'].initial = ACTIVETEST_KIND |
| 222 | |
| 223 | self.fields['provider_service'].queryset = VpmaService.get_service_objects().all() |
| 224 | |
| 225 | if self.instance: |
| 226 | self.fields['creator'].initial = self.instance.creator |
| 227 | self.fields['is_reflector'].initial = self.instance.is_reflector |
| 228 | self.fields['is_initiator'].initial = self.instance.is_initiator |
| 229 | self.fields['reflector'].initial = self.instance.reflector |
| 230 | |
| 231 | if (not self.instance) or (not self.instance.pk): |
| 232 | self.fields['creator'].initial = get_request().user |
| 233 | if VpmaService.get_service_objects().exists(): |
| 234 | self.fields['provider_service'].initial = VpmaService.get_service_objects().all()[0] |
| 235 | |
| 236 | def save(self, commit=True): |
| 237 | self.instance.creator = self.cleaned_data.get('creator') |
| 238 | self.instance.is_reflector = self.cleaned_data.get('is_reflector') |
| 239 | self.instance.is_initiator = self.cleaned_data.get('is_initiator') |
| 240 | self.instance.reflector = self.cleaned_data.get('reflector') |
| 241 | return super(VpmaTenantForm, self).save(commit=commit) |
| 242 | |
| 243 | |
| 244 | class VpmaTenantAdmin(ReadOnlyAwareAdmin): |
| 245 | |
| 246 | verbose_name = VPMA_TENANT_NAME_VERBOSE |
| 247 | verbose_name_plural = VPMA_TENANT_NAME_VERBOSE_PLURAL |
| 248 | |
| 249 | list_display = ('id', 'backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector') |
| 250 | list_display_links = ('backend_status_icon', 'instance', 'is_reflector', 'is_initiator', 'reflector', 'id') |
| 251 | |
| 252 | fieldsets = [(None, { |
| 253 | 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'is_reflector', 'is_initiator', 'reflector'], |
| 254 | 'classes': ['suit-tab suit-tab-general'], |
| 255 | })] |
| 256 | |
| 257 | readonly_fields = ('backend_status_text', 'instance',) |
| 258 | |
| 259 | form = VpmaTenantForm |
| 260 | |
| 261 | suit_form_tabs = (('general', 'Details'),) |
| 262 | |
| 263 | def get_queryset(self, request): |
| 264 | return VpmaTenant.get_tenant_objects_by_user(request.user) |
| 265 | |
| 266 | admin.site.register(VpmaTenant, VpmaTenantAdmin) |