blob: 8dc98d9281f98605f90eca8b6144dc462320ed9a [file] [log] [blame]
Murat Parlakisik66fde4d2016-09-22 13:28:13 -07001# admin.py - VSGW Django Admin
2
3from core.admin import ReadOnlyAwareAdmin, SliceInline
4from core.middleware import get_request
5from core.models import User
6from django import forms
7from django.contrib import admin
8from services.vsgw.models import *
9
10class VSGWServiceForm(forms.ModelForm):
11
12 class Meta:
13 model = VSGWService
14 fields = '__all__'
15
16 def __init__(self, *args, **kwargs):
JianHaoce45e042017-01-16 11:06:29 +000017 super(VSGWServiceForm, self).__init__(*args, **kwargs)
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070018
19 if self.instance:
20 self.fields['service_message'].initial = self.instance.service_message
21
22 def save(self, commit=True):
23 self.instance.service_message = self.cleaned_data.get('service_message')
24 return super(VSGWServiceForm, self).save(commit=commit)
25
26class VSGWServiceAdmin(ReadOnlyAwareAdmin):
27
28 model = VSGWService
29 verbose_name = SERVICE_NAME_VERBOSE
30 verbose_name_plural = SERVICE_NAME_VERBOSE_PLURAL
JianHaoce45e042017-01-16 11:06:29 +000031 form = VSGWServiceForm
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070032 inlines = [SliceInline]
33
34 list_display = ('backend_status_icon', 'name', 'service_message', 'enabled')
35 list_display_links = ('backend_status_icon', 'name', 'service_message' )
36
37 fieldsets = [(None, {
38 'fields': ['backend_status_text', 'name', 'enabled', 'versionNumber', 'service_message', 'description',],
39 'classes':['suit-tab suit-tab-general',],
40 })]
41
42 readonly_fields = ('backend_status_text', )
43 user_readonly_fields = ['name', 'enabled', 'versionNumber', 'description',]
44
45 extracontext_registered_admins = True
46
47 suit_form_tabs = (
48 ('general', 'Example Service Details', ),
49 ('slices', 'Slices',),
50 )
51
52 suit_form_includes = ((
53 'top',
54 'administration'),
55 )
56
57 def get_queryset(self, request):
58 return ExampleService.get_service_objects_by_user(request.user)
59
60admin.site.register(VSGWService, VSGWServiceAdmin)
61
62class VSGWTenantForm(forms.ModelForm):
63
64 class Meta:
65 model = VSGWTenant
66 fields = '__all__'
67
68 creator = forms.ModelChoiceField(queryset=User.objects.all())
69
70 def __init__(self, *args, **kwargs):
JianHaoce45e042017-01-16 11:06:29 +000071 super(VSGWTenantForm, self).__init__(*args, **kwargs)
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070072
73 self.fields['kind'].widget.attrs['readonly'] = True
74 self.fields['kind'].initial = SERVICE_NAME
75
76 self.fields['provider_service'].queryset = VSGWService.get_service_objects().all()
77
78 if self.instance:
79 self.fields['creator'].initial = self.instance.creator
80 self.fields['tenant_message'].initial = self.instance.tenant_message
81
82 if (not self.instance) or (not self.instance.pk):
83 self.fields['creator'].initial = get_request().user
84 if VSGWService.get_service_objects().exists():
85 self.fields['provider_service'].initial = VSGWService.get_service_objects().all()[0]
86
87 def save(self, commit=True):
88 self.instance.creator = self.cleaned_data.get('creator')
89 self.instance.tenant_message = self.cleaned_data.get('tenant_message')
90 return super(VSGWTenantForm, self).save(commit=commit)
91
92
93class VSGWTenantAdmin(ReadOnlyAwareAdmin):
94
95 verbose_name = TENANT_NAME_VERBOSE
96 verbose_name_plural = TENANT_NAME_VERBOSE_PLURAL
97
98 list_display = ('id', 'backend_status_icon', 'instance', 'tenant_message')
99 list_display_links = ('backend_status_icon', 'instance', 'tenant_message', 'id')
100
101 fieldsets = [(None, {
102 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'tenant_message'],
103 'classes': ['suit-tab suit-tab-general'],
104 })]
105
106 readonly_fields = ('backend_status_text', 'instance',)
107
108 form = VSGWTenantForm
109
110 suit_form_tabs = (('general', 'Details'),)
111
112 def get_queryset(self, request):
113 return VSGWTenant.get_tenant_objects_by_user(request.user)
114
JianHaoce45e042017-01-16 11:06:29 +0000115admin.site.register(VSGWTenant, VSGWTenantAdmin)