blob: 56e46aef59e092aa168e2acd48b4caafe4e79bfa [file] [log] [blame]
Scott Bakerbb2a2a22015-04-21 16:59:04 -07001from django.contrib import admin
2
Scott Baker98f51552015-12-31 10:18:28 -08003from services.cord.models import *
Scott Bakerbb2a2a22015-04-21 16:59:04 -07004from 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
Scott Baker6dddd2f2015-07-23 12:06:26 -070013from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
Scott Bakerd145efe2015-09-10 16:01:58 -070014from core.middleware import get_request
Scott Bakerbb2a2a22015-04-21 16:59:04 -070015
16from functools import update_wrapper
17from django.contrib.admin.views.main import ChangeList
18from django.core.urlresolvers import reverse
19from django.contrib.admin.utils import quote
20
Scott Baker27b768d2015-04-21 17:15:18 -070021#-----------------------------------------------------------------------------
22# vOLT
23#-----------------------------------------------------------------------------
Scott Bakerbb2a2a22015-04-21 16:59:04 -070024
25class VOLTServiceAdmin(ReadOnlyAwareAdmin):
26 model = VOLTService
27 verbose_name = "vOLT Service"
28 verbose_name_plural = "vOLT Service"
29 list_display = ("backend_status_icon", "name", "enabled")
30 list_display_links = ('backend_status_icon', 'name', )
Scott Baker27b768d2015-04-21 17:15:18 -070031 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
Scott Bakerbb2a2a22015-04-21 16:59:04 -070032 readonly_fields = ('backend_status_text', )
Scott Baker9da53042015-05-15 09:08:19 -070033 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Bakerbb2a2a22015-04-21 16:59:04 -070034
35 extracontext_registered_admins = True
36
37 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
38
39 suit_form_tabs =(('general', 'vOLT Service Details'),
40 ('administration', 'Administration'),
41 #('tools', 'Tools'),
42 ('slices','Slices'),
43 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -070044 ('serviceprivileges','Privileges'),
Scott Bakerbb2a2a22015-04-21 16:59:04 -070045 )
46
47 suit_form_includes = (('voltadmin.html', 'top', 'administration'),
48 ) #('hpctools.html', 'top', 'tools') )
49
50 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -070051 return VOLTService.get_service_objects_by_user(request.user)
Scott Bakerbb2a2a22015-04-21 16:59:04 -070052
53class VOLTTenantForm(forms.ModelForm):
Scott Bakerf1527cd2015-11-09 20:25:21 -080054 s_tag = forms.CharField()
55 c_tag = forms.CharField()
Scott Bakereefe65c2015-07-13 13:08:07 -070056 creator = forms.ModelChoiceField(queryset=User.objects.all())
57
Sapan Bhatia16be1432016-01-14 11:41:38 -050058 def __init__(self,*args,**kwargs):
59 super (VOLTTenantForm,self ).__init__(*args,**kwargs)
60 self.fields['kind'].widget.attrs['readonly'] = True
61 self.fields['provider_service'].queryset = VOLTService.get_service_objects().all()
62 if self.instance:
63 # fields for the attributes
64 self.fields['c_tag'].initial = self.instance.c_tag
65 self.fields['s_tag'].initial = self.instance.s_tag
66 self.fields['creator'].initial = self.instance.creator
67 if (not self.instance) or (not self.instance.pk):
68 # default fields for an 'add' form
69 self.fields['kind'].initial = VOLT_KIND
70 self.fields['creator'].initial = get_request().user
71 if VOLTService.get_service_objects().exists():
72 self.fields["provider_service"].initial = VOLTService.get_service_objects().all()[0]
73
74 def save(self, commit=True):
75 self.instance.s_tag = self.cleaned_data.get("s_tag")
76 self.instance.c_tag = self.cleaned_data.get("c_tag")
77 self.instance.creator = self.cleaned_data.get("creator")
78 return super(VOLTTenantForm, self).save(commit=commit)
79
80 class Meta:
Scott Bakerbb2a2a22015-04-21 16:59:04 -070081 model = VOLTTenant
82
83class VOLTTenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerf1527cd2015-11-09 20:25:21 -080084 list_display = ('backend_status_icon', 'id', 'service_specific_id', 's_tag', 'c_tag', 'subscriber_root' )
Scott Baker27b768d2015-04-21 17:15:18 -070085 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -070086 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_root', 'service_specific_id', # 'service_specific_attribute',
Scott Bakerf1527cd2015-11-09 20:25:21 -080087 's_tag', 'c_tag', 'creator'],
Scott Baker80a39292015-07-21 18:18:25 -070088 'classes':['suit-tab suit-tab-general']})]
Scott Bakereefe65c2015-07-13 13:08:07 -070089 readonly_fields = ('backend_status_text', 'service_specific_attribute')
Scott Bakerbb2a2a22015-04-21 16:59:04 -070090 form = VOLTTenantForm
91
92 suit_form_tabs = (('general','Details'),)
93
94 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -070095 return VOLTTenant.get_tenant_objects_by_user(request.user)
Scott Bakerbb2a2a22015-04-21 16:59:04 -070096
Scott Baker27b768d2015-04-21 17:15:18 -070097#-----------------------------------------------------------------------------
98# vCPE
99#-----------------------------------------------------------------------------
100
Scott Bakerf91e6152016-02-11 12:07:10 -0800101class VSGServiceForm(forms.ModelForm):
Scott Baker2b56cf42015-07-15 18:08:06 -0700102 bbs_api_hostname = forms.CharField(required=False)
103 bbs_api_port = forms.IntegerField(required=False)
Scott Baker80157da2015-07-15 17:42:43 -0700104 bbs_server = forms.CharField(required=False)
105 backend_network_label = forms.CharField(required=False)
106 bbs_slice = forms.ModelChoiceField(queryset=Slice.objects.all(), required=False)
Scott Bakercf6eb992016-02-18 06:43:02 -0800107 wan_container_gateway_ip = forms.CharField(required=False)
108 wan_container_gateway_mac = forms.CharField(required=False)
109 wan_container_netbits = forms.CharField(required=False)
Scott Bakerae6187c2016-02-23 14:58:49 -0800110 dns_servers = forms.CharField(required=False)
Scott Baker67074ab2016-03-04 11:29:02 -0800111 node_label = forms.CharField(required=False)
Scott Baker62312972015-07-13 14:30:25 -0700112
Sapan Bhatia16be1432016-01-14 11:41:38 -0500113 def __init__(self,*args,**kwargs):
Scott Bakerf91e6152016-02-11 12:07:10 -0800114 super (VSGServiceForm,self ).__init__(*args,**kwargs)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500115 if self.instance:
116 self.fields['bbs_api_hostname'].initial = self.instance.bbs_api_hostname
117 self.fields['bbs_api_port'].initial = self.instance.bbs_api_port
118 self.fields['bbs_server'].initial = self.instance.bbs_server
119 self.fields['backend_network_label'].initial = self.instance.backend_network_label
120 self.fields['bbs_slice'].initial = self.instance.bbs_slice
Scott Bakercf6eb992016-02-18 06:43:02 -0800121 self.fields['wan_container_gateway_ip'].initial = self.instance.wan_container_gateway_ip
122 self.fields['wan_container_gateway_mac'].initial = self.instance.wan_container_gateway_mac
123 self.fields['wan_container_netbits'].initial = self.instance.wan_container_netbits
Scott Bakerae6187c2016-02-23 14:58:49 -0800124 self.fields['dns_servers'].initial = self.instance.dns_servers
Scott Baker67074ab2016-03-04 11:29:02 -0800125 self.fields['node_label'].initial = self.instance.node_label
Sapan Bhatia16be1432016-01-14 11:41:38 -0500126
127 def save(self, commit=True):
128 self.instance.bbs_api_hostname = self.cleaned_data.get("bbs_api_hostname")
129 self.instance.bbs_api_port = self.cleaned_data.get("bbs_api_port")
130 self.instance.bbs_server = self.cleaned_data.get("bbs_server")
131 self.instance.backend_network_label = self.cleaned_data.get("backend_network_label")
132 self.instance.bbs_slice = self.cleaned_data.get("bbs_slice")
Scott Bakercf6eb992016-02-18 06:43:02 -0800133 self.instance.wan_container_gateway_ip = self.cleaned_data.get("wan_container_gateway_ip")
134 self.instance.wan_container_gateway_mac = self.cleaned_data.get("wan_container_gateway_mac")
135 self.instance.wan_container_netbits = self.cleaned_data.get("wan_container_netbits")
Scott Bakerae6187c2016-02-23 14:58:49 -0800136 self.instance.dns_servers = self.cleaned_data.get("dns_servers")
Scott Baker67074ab2016-03-04 11:29:02 -0800137 self.instance.node_label = self.cleaned_data.get("node_label")
Scott Bakerf91e6152016-02-11 12:07:10 -0800138 return super(VSGServiceForm, self).save(commit=commit)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500139
140 class Meta:
Scott Bakerf91e6152016-02-11 12:07:10 -0800141 model = VSGService
Scott Baker62312972015-07-13 14:30:25 -0700142
Scott Bakerf91e6152016-02-11 12:07:10 -0800143class VSGServiceAdmin(ReadOnlyAwareAdmin):
144 model = VSGService
Scott Bakerae6187c2016-02-23 14:58:49 -0800145 verbose_name = "vSG Service"
146 verbose_name_plural = "vSG Service"
Scott Baker27b768d2015-04-21 17:15:18 -0700147 list_display = ("backend_status_icon", "name", "enabled")
148 list_display_links = ('backend_status_icon', 'name', )
Scott Baker67074ab2016-03-04 11:29:02 -0800149 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "service_specific_attribute", "node_label"],
Scott Baker80157da2015-07-15 17:42:43 -0700150 'classes':['suit-tab suit-tab-general']}),
Scott Bakerae6187c2016-02-23 14:58:49 -0800151 ("backend config", {'fields': [ "backend_network_label", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"],
152 'classes':['suit-tab suit-tab-backend']}),
153 ("vSG config", {'fields': [ "wan_container_gateway_ip", "wan_container_gateway_mac", "wan_container_netbits", "dns_servers"],
154 'classes':['suit-tab suit-tab-vsg']}) ]
Scott Baker62312972015-07-13 14:30:25 -0700155 readonly_fields = ('backend_status_text', "service_specific_attribute")
Scott Baker9da53042015-05-15 09:08:19 -0700156 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Bakerf91e6152016-02-11 12:07:10 -0800157 form = VSGServiceForm
Scott Baker27b768d2015-04-21 17:15:18 -0700158
159 extracontext_registered_admins = True
160
161 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
162
Scott Baker80157da2015-07-15 17:42:43 -0700163 suit_form_tabs =(('general', 'Service Details'),
164 ('backend', 'Backend Config'),
Scott Bakerae6187c2016-02-23 14:58:49 -0800165 ('vsg', 'vSG Config'),
Scott Baker27b768d2015-04-21 17:15:18 -0700166 ('administration', 'Administration'),
167 #('tools', 'Tools'),
168 ('slices','Slices'),
169 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -0700170 ('serviceprivileges','Privileges') ,
Scott Baker27b768d2015-04-21 17:15:18 -0700171 )
172
173 suit_form_includes = (('vcpeadmin.html', 'top', 'administration'),
174 ) #('hpctools.html', 'top', 'tools') )
175
176 def queryset(self, request):
Scott Bakerf91e6152016-02-11 12:07:10 -0800177 return VSGService.get_service_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700178
Scott Baker4c052b22016-02-11 11:08:42 -0800179class VSGTenantForm(forms.ModelForm):
Scott Baker80a39292015-07-21 18:18:25 -0700180 bbs_account = forms.CharField(required=False)
181 creator = forms.ModelChoiceField(queryset=User.objects.all())
Tony Mackd8515472015-08-19 11:58:18 -0400182 instance = forms.ModelChoiceField(queryset=Instance.objects.all(),required=False)
Scott Baker80a39292015-07-21 18:18:25 -0700183 last_ansible_hash = forms.CharField(required=False)
Scott Bakere6780e92016-02-13 14:38:43 -0800184 wan_container_ip = forms.CharField(required=False)
Scott Bakercf6eb992016-02-18 06:43:02 -0800185 wan_container_mac = forms.CharField(required=False)
Scott Baker80a39292015-07-21 18:18:25 -0700186
Sapan Bhatia16be1432016-01-14 11:41:38 -0500187 def __init__(self,*args,**kwargs):
Scott Baker4c052b22016-02-11 11:08:42 -0800188 super (VSGTenantForm,self ).__init__(*args,**kwargs)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500189 self.fields['kind'].widget.attrs['readonly'] = True
Scott Bakerf91e6152016-02-11 12:07:10 -0800190 self.fields['provider_service'].queryset = VSGService.get_service_objects().all()
Sapan Bhatia16be1432016-01-14 11:41:38 -0500191 if self.instance:
192 # fields for the attributes
193 self.fields['bbs_account'].initial = self.instance.bbs_account
194 self.fields['creator'].initial = self.instance.creator
195 self.fields['instance'].initial = self.instance.instance
196 self.fields['last_ansible_hash'].initial = self.instance.last_ansible_hash
Scott Bakere6780e92016-02-13 14:38:43 -0800197 self.fields['wan_container_ip'].initial = self.instance.wan_container_ip
Scott Bakercf6eb992016-02-18 06:43:02 -0800198 self.fields['wan_container_mac'].initial = self.instance.wan_container_mac
Sapan Bhatia16be1432016-01-14 11:41:38 -0500199 if (not self.instance) or (not self.instance.pk):
200 # default fields for an 'add' form
201 self.fields['kind'].initial = VCPE_KIND
202 self.fields['creator'].initial = get_request().user
Scott Bakerf91e6152016-02-11 12:07:10 -0800203 if VSGService.get_service_objects().exists():
204 self.fields["provider_service"].initial = VSGService.get_service_objects().all()[0]
Sapan Bhatia16be1432016-01-14 11:41:38 -0500205
206 def save(self, commit=True):
207 self.instance.creator = self.cleaned_data.get("creator")
208 self.instance.instance = self.cleaned_data.get("instance")
209 self.instance.last_ansible_hash = self.cleaned_data.get("last_ansible_hash")
Scott Baker4c052b22016-02-11 11:08:42 -0800210 return super(VSGTenantForm, self).save(commit=commit)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500211
212 class Meta:
Scott Baker4c052b22016-02-11 11:08:42 -0800213 model = VSGTenant
Scott Baker27b768d2015-04-21 17:15:18 -0700214
Scott Baker4c052b22016-02-11 11:08:42 -0800215class VSGTenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerb3cf9212015-07-06 14:40:20 -0700216 list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
Scott Baker27b768d2015-04-21 17:15:18 -0700217 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -0700218 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute',
Scott Bakercf6eb992016-02-18 06:43:02 -0800219 'wan_container_ip', 'wan_container_mac', 'bbs_account', 'creator', 'instance', 'last_ansible_hash'],
Scott Baker80a39292015-07-21 18:18:25 -0700220 'classes':['suit-tab suit-tab-general']})]
Scott Bakercf6eb992016-02-18 06:43:02 -0800221 readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account', 'wan_container_ip', 'wan_container_mac')
Scott Baker4c052b22016-02-11 11:08:42 -0800222 form = VSGTenantForm
Scott Baker27b768d2015-04-21 17:15:18 -0700223
224 suit_form_tabs = (('general','Details'),)
225
226 def queryset(self, request):
Scott Baker4c052b22016-02-11 11:08:42 -0800227 return VSGTenant.get_tenant_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700228
229#-----------------------------------------------------------------------------
230# vBNG
231#-----------------------------------------------------------------------------
232
Scott Baker21d18932015-07-21 18:24:21 -0700233class VBNGServiceForm(forms.ModelForm):
234 vbng_url = forms.CharField(required=False)
235
Sapan Bhatia16be1432016-01-14 11:41:38 -0500236 def __init__(self,*args,**kwargs):
237 super (VBNGServiceForm,self ).__init__(*args,**kwargs)
238 if self.instance:
239 self.fields['vbng_url'].initial = self.instance.vbng_url
240
241 def save(self, commit=True):
242 self.instance.vbng_url = self.cleaned_data.get("vbng_url")
243 return super(VBNGServiceForm, self).save(commit=commit)
244
245 class Meta:
Scott Baker21d18932015-07-21 18:24:21 -0700246 model = VBNGService
247
Scott Baker27b768d2015-04-21 17:15:18 -0700248class VBNGServiceAdmin(ReadOnlyAwareAdmin):
249 model = VBNGService
250 verbose_name = "vBNG Service"
251 verbose_name_plural = "vBNG Service"
252 list_display = ("backend_status_icon", "name", "enabled")
253 list_display_links = ('backend_status_icon', 'name', )
Scott Baker21d18932015-07-21 18:24:21 -0700254 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url",
255 'vbng_url' ],
256 'classes':['suit-tab suit-tab-general']})]
Scott Baker27b768d2015-04-21 17:15:18 -0700257 readonly_fields = ('backend_status_text', )
Scott Baker9da53042015-05-15 09:08:19 -0700258 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Baker21d18932015-07-21 18:24:21 -0700259 form = VBNGServiceForm
Scott Baker27b768d2015-04-21 17:15:18 -0700260
261 extracontext_registered_admins = True
262
263 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
264
265 suit_form_tabs =(('general', 'vBNG Service Details'),
266 ('administration', 'Administration'),
267 #('tools', 'Tools'),
268 ('slices','Slices'),
269 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -0700270 ('serviceprivileges','Privileges'),
Scott Baker27b768d2015-04-21 17:15:18 -0700271 )
272
273 suit_form_includes = (('vbngadmin.html', 'top', 'administration'),
274 ) #('hpctools.html', 'top', 'tools') )
275
276 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700277 return VBNGService.get_service_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700278
279class VBNGTenantForm(forms.ModelForm):
Scott Baker80a39292015-07-21 18:18:25 -0700280 routeable_subnet = forms.CharField(required=False)
281 mapped_hostname = forms.CharField(required=False)
282 mapped_ip = forms.CharField(required=False)
283 mapped_mac = forms.CharField(required=False)
284
Sapan Bhatia16be1432016-01-14 11:41:38 -0500285 def __init__(self,*args,**kwargs):
286 super (VBNGTenantForm,self ).__init__(*args,**kwargs)
287 self.fields['kind'].widget.attrs['readonly'] = True
288 self.fields['provider_service'].queryset = VBNGService.get_service_objects().all()
289 if self.instance:
290 # fields for the attributes
291 self.fields['routeable_subnet'].initial = self.instance.routeable_subnet
292 self.fields['mapped_hostname'].initial = self.instance.mapped_hostname
293 self.fields['mapped_ip'].initial = self.instance.mapped_ip
294 self.fields['mapped_mac'].initial = self.instance.mapped_mac
295 if (not self.instance) or (not self.instance.pk):
296 # default fields for an 'add' form
297 self.fields['kind'].initial = VBNG_KIND
298 if VBNGService.get_service_objects().exists():
299 self.fields["provider_service"].initial = VBNGService.get_service_objects().all()[0]
300
301 def save(self, commit=True):
302 self.instance.routeable_subnet = self.cleaned_data.get("routeable_subnet")
303 self.instance.mapped_hostname = self.cleaned_data.get("mapped_hostname")
304 self.instance.mapped_ip = self.cleaned_data.get("mapped_ip")
305 self.instance.mapped_mac = self.cleaned_data.get("mapped_mac")
306 return super(VBNGTenantForm, self).save(commit=commit)
307
308 class Meta:
Scott Baker27b768d2015-04-21 17:15:18 -0700309 model = VBNGTenant
310
311class VBNGTenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerb3cf9212015-07-06 14:40:20 -0700312 list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
Scott Baker27b768d2015-04-21 17:15:18 -0700313 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -0700314 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute',
315 'routeable_subnet', 'mapped_hostname', 'mapped_ip', 'mapped_mac'],
316 'classes':['suit-tab suit-tab-general']})]
317 readonly_fields = ('backend_status_text', 'service_specific_attribute')
Scott Baker27b768d2015-04-21 17:15:18 -0700318 form = VBNGTenantForm
319
320 suit_form_tabs = (('general','Details'),)
321
322 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700323 return VBNGTenant.get_tenant_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700324
Scott Baker6dddd2f2015-07-23 12:06:26 -0700325#-----------------------------------------------------------------------------
326# CordSubscriberRoot
327#-----------------------------------------------------------------------------
328
Scott Baker4124e962015-07-24 10:15:01 -0700329class VOLTTenantInline(XOSTabularInline):
330 model = VOLTTenant
331 fields = ['provider_service', 'subscriber_root', 'service_specific_id']
332 readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id']
333 extra = 0
334 max_num = 0
335 suit_classes = 'suit-tab suit-tab-volttenants'
336 fk_name = 'subscriber_root'
337 verbose_name = 'subscribed tenant'
338 verbose_name_plural = 'subscribed tenants'
339
340 @property
341 def selflink_reverse_path(self):
342 return "admin:cord_volttenant_change"
343
344 def queryset(self, request):
345 qs = super(VOLTTenantInline, self).queryset(request)
346 return qs.filter(kind=VOLT_KIND)
347
Scott Baker6dddd2f2015-07-23 12:06:26 -0700348class CordSubscriberRootForm(forms.ModelForm):
349 url_filter_level = forms.CharField(required = False)
Scott Baker669212f2016-03-01 20:14:35 -0800350 uplink_speed = forms.CharField(required = False)
351 downlink_speed = forms.CharField(required = False)
352 status = forms.ChoiceField(choices=CordSubscriberRoot.status_choices, required=True)
353 enable_uverse = forms.BooleanField(required=False)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700354
Sapan Bhatia16be1432016-01-14 11:41:38 -0500355 def __init__(self,*args,**kwargs):
356 super (CordSubscriberRootForm,self ).__init__(*args,**kwargs)
357 self.fields['kind'].widget.attrs['readonly'] = True
358 if self.instance:
359 self.fields['url_filter_level'].initial = self.instance.url_filter_level
Scott Baker669212f2016-03-01 20:14:35 -0800360 self.fields['uplink_speed'].initial = self.instance.uplink_speed
361 self.fields['downlink_speed'].initial = self.instance.downlink_speed
362 self.fields['status'].initial = self.instance.status
363 self.fields['enable_uverse'].initial = self.instance.enable_uverse
Sapan Bhatia16be1432016-01-14 11:41:38 -0500364 if (not self.instance) or (not self.instance.pk):
365 # default fields for an 'add' form
366 self.fields['kind'].initial = CORD_SUBSCRIBER_KIND
Scott Baker669212f2016-03-01 20:14:35 -0800367 self.fields['uplink_speed'].initial = CordSubscriberRoot.get_default_attribute("uplink_speed")
368 self.fields['downlink_speed'].initial = CordSubscriberRoot.get_default_attribute("downlink_speed")
369 self.fields['status'].initial = CordSubscriberRoot.get_default_attribute("status")
370 self.fields['enable_uverse'].initial = CordSubscriberRoot.get_default_attribute("enable_uverse")
Sapan Bhatia16be1432016-01-14 11:41:38 -0500371
372 def save(self, commit=True):
373 self.instance.url_filter_level = self.cleaned_data.get("url_filter_level")
Scott Baker669212f2016-03-01 20:14:35 -0800374 self.instance.uplink_speed = self.cleaned_data.get("uplink_speed")
375 self.instance.downlink_speed = self.cleaned_data.get("downlink_speed")
376 self.instance.status = self.cleaned_data.get("status")
377 self.instance.enable_uverse = self.cleaned_data.get("enable_uverse")
Sapan Bhatia16be1432016-01-14 11:41:38 -0500378 return super(CordSubscriberRootForm, self).save(commit=commit)
379
380 class Meta:
Scott Baker6dddd2f2015-07-23 12:06:26 -0700381 model = CordSubscriberRoot
382
383class CordSubscriberRootAdmin(ReadOnlyAwareAdmin):
384 list_display = ('backend_status_icon', 'id', 'name', )
385 list_display_links = ('backend_status_icon', 'id', 'name', )
386 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute',
Scott Baker669212f2016-03-01 20:14:35 -0800387 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse"],
Scott Baker6dddd2f2015-07-23 12:06:26 -0700388 'classes':['suit-tab suit-tab-general']})]
Scott Baker669212f2016-03-01 20:14:35 -0800389 readonly_fields = ('backend_status_text', 'service_specific_attribute',)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700390 form = CordSubscriberRootForm
Scott Baker4124e962015-07-24 10:15:01 -0700391 inlines = (VOLTTenantInline, TenantRootPrivilegeInline)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700392
393 suit_form_tabs =(('general', 'Cord Subscriber Root Details'),
Scott Baker4124e962015-07-24 10:15:01 -0700394 ('volttenants','VOLT Tenancy'),
Scott Baker6dddd2f2015-07-23 12:06:26 -0700395 ('tenantrootprivileges','Privileges')
396 )
397
398 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700399 return CordSubscriberRoot.get_tenant_objects_by_user(request.user)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700400
Scott Bakerbb2a2a22015-04-21 16:59:04 -0700401admin.site.register(VOLTService, VOLTServiceAdmin)
402admin.site.register(VOLTTenant, VOLTTenantAdmin)
Scott Bakerf91e6152016-02-11 12:07:10 -0800403admin.site.register(VSGService, VSGServiceAdmin)
Scott Baker4c052b22016-02-11 11:08:42 -0800404admin.site.register(VSGTenant, VSGTenantAdmin)
Scott Baker27b768d2015-04-21 17:15:18 -0700405admin.site.register(VBNGService, VBNGServiceAdmin)
406admin.site.register(VBNGTenant, VBNGTenantAdmin)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700407admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin)
Scott Bakerbb2a2a22015-04-21 16:59:04 -0700408