blob: a7b9850e16339615fdeb867a434a4b7b281366e1 [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
Saleil Bhat42e8c5e2017-02-01 15:59:54 -080081 self.fields['image_name'].initial = self.instance.image_name
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070082
83 if (not self.instance) or (not self.instance.pk):
84 self.fields['creator'].initial = get_request().user
85 if VSGWService.get_service_objects().exists():
86 self.fields['provider_service'].initial = VSGWService.get_service_objects().all()[0]
87
88 def save(self, commit=True):
89 self.instance.creator = self.cleaned_data.get('creator')
90 self.instance.tenant_message = self.cleaned_data.get('tenant_message')
Saleil Bhat42e8c5e2017-02-01 15:59:54 -080091 self.instance.image_name = self.cleaned_data.get('image_name')
Murat Parlakisik66fde4d2016-09-22 13:28:13 -070092 return super(VSGWTenantForm, self).save(commit=commit)
93
94
95class VSGWTenantAdmin(ReadOnlyAwareAdmin):
96
97 verbose_name = TENANT_NAME_VERBOSE
98 verbose_name_plural = TENANT_NAME_VERBOSE_PLURAL
99
Saleil Bhat42e8c5e2017-02-01 15:59:54 -0800100 list_display = ('id', 'backend_status_icon', 'instance', 'tenant_message', 'image_name')
101 list_display_links = ('backend_status_icon', 'instance', 'tenant_message', 'id', 'image_name')
Murat Parlakisik66fde4d2016-09-22 13:28:13 -0700102
103 fieldsets = [(None, {
Saleil Bhat42e8c5e2017-02-01 15:59:54 -0800104 'fields': ['backend_status_text', 'kind', 'provider_service', 'instance', 'creator', 'tenant_message', 'image_name'],
Murat Parlakisik66fde4d2016-09-22 13:28:13 -0700105 'classes': ['suit-tab suit-tab-general'],
106 })]
107
108 readonly_fields = ('backend_status_text', 'instance',)
109
110 form = VSGWTenantForm
111
112 suit_form_tabs = (('general', 'Details'),)
113
114 def get_queryset(self, request):
115 return VSGWTenant.get_tenant_objects_by_user(request.user)
116
JianHaoce45e042017-01-16 11:06:29 +0000117admin.site.register(VSGWTenant, VSGWTenantAdmin)