Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
| 3 | from cord.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 |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 13 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 14 | |
| 15 | from functools import update_wrapper |
| 16 | from django.contrib.admin.views.main import ChangeList |
| 17 | from django.core.urlresolvers import reverse |
| 18 | from django.contrib.admin.utils import quote |
| 19 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 20 | #----------------------------------------------------------------------------- |
| 21 | # vOLT |
| 22 | #----------------------------------------------------------------------------- |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 23 | |
| 24 | class VOLTServiceAdmin(ReadOnlyAwareAdmin): |
| 25 | model = VOLTService |
| 26 | verbose_name = "vOLT Service" |
| 27 | verbose_name_plural = "vOLT Service" |
| 28 | list_display = ("backend_status_icon", "name", "enabled") |
| 29 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 30 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 31 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 32 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 33 | |
| 34 | extracontext_registered_admins = True |
| 35 | |
| 36 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 37 | |
| 38 | suit_form_tabs =(('general', 'vOLT Service Details'), |
| 39 | ('administration', 'Administration'), |
| 40 | #('tools', 'Tools'), |
| 41 | ('slices','Slices'), |
| 42 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 43 | ('serviceprivileges','Privileges'), |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | suit_form_includes = (('voltadmin.html', 'top', 'administration'), |
| 47 | ) #('hpctools.html', 'top', 'tools') ) |
| 48 | |
| 49 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame^] | 50 | return VOLTService.get_service_objects_by_user(request.user) |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 51 | |
| 52 | class VOLTTenantForm(forms.ModelForm): |
Scott Baker | eefe65c | 2015-07-13 13:08:07 -0700 | [diff] [blame] | 53 | vlan_id = forms.CharField() |
| 54 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
| 55 | |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 56 | def __init__(self,*args,**kwargs):
|
| 57 | super (VOLTTenantForm,self ).__init__(*args,**kwargs)
|
| 58 | self.fields['kind'].default = "vOLT"
|
| 59 | self.fields['kind'].widget.attrs['readonly'] = True
|
| 60 | self.fields['provider_service'].queryset = VOLTService.get_service_objects().all()
|
Scott Baker | eefe65c | 2015-07-13 13:08:07 -0700 | [diff] [blame] | 61 | if self.instance:
|
| 62 | # fields for the attributes
|
| 63 | self.fields['vlan_id'].initial = self.instance.vlan_id
|
| 64 | self.fields['creator'].initial = self.instance.creator
|
| 65 |
|
| 66 | def save(self, commit=True):
|
| 67 | self.instance.vlan_id = self.cleaned_data.get("vlan_id")
|
| 68 | self.instance.creator = self.cleaned_data.get("creator")
|
| 69 | return super(VOLTTenantForm, self).save(commit=commit)
|
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 70 |
|
| 71 | class Meta:
|
| 72 | model = VOLTTenant |
| 73 | |
| 74 | class VOLTTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 836fbe6 | 2015-07-06 17:20:37 -0700 | [diff] [blame] | 75 | list_display = ('backend_status_icon', 'id', 'service_specific_id', 'vlan_id', 'subscriber_root' ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 76 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 77 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_root', 'service_specific_id', # 'service_specific_attribute', |
| 78 | 'vlan_id', 'creator'], |
| 79 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | eefe65c | 2015-07-13 13:08:07 -0700 | [diff] [blame] | 80 | readonly_fields = ('backend_status_text', 'service_specific_attribute') |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 81 | form = VOLTTenantForm |
| 82 | |
| 83 | suit_form_tabs = (('general','Details'),) |
| 84 | |
| 85 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame^] | 86 | return VOLTTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 87 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 88 | #----------------------------------------------------------------------------- |
| 89 | # vCPE |
| 90 | #----------------------------------------------------------------------------- |
| 91 | |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 92 | class VCPEServiceForm(forms.ModelForm): |
Scott Baker | 2b56cf4 | 2015-07-15 18:08:06 -0700 | [diff] [blame] | 93 | bbs_api_hostname = forms.CharField(required=False) |
| 94 | bbs_api_port = forms.IntegerField(required=False) |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 95 | bbs_server = forms.CharField(required=False) |
| 96 | backend_network_label = forms.CharField(required=False) |
| 97 | bbs_slice = forms.ModelChoiceField(queryset=Slice.objects.all(), required=False) |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 98 | |
| 99 | def __init__(self,*args,**kwargs):
|
| 100 | super (VCPEServiceForm,self ).__init__(*args,**kwargs)
|
| 101 | if self.instance:
|
Scott Baker | 2b56cf4 | 2015-07-15 18:08:06 -0700 | [diff] [blame] | 102 | self.fields['bbs_api_hostname'].initial = self.instance.bbs_api_hostname
|
| 103 | self.fields['bbs_api_port'].initial = self.instance.bbs_api_port
|
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 104 | self.fields['bbs_server'].initial = self.instance.bbs_server
|
Scott Baker | d4829ea | 2015-07-15 18:04:22 -0700 | [diff] [blame] | 105 | self.fields['backend_network_label'].initial = self.instance.backend_network_label
|
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 106 | self.fields['bbs_slice'].initial = self.instance.bbs_slice
|
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 107 |
|
| 108 | def save(self, commit=True):
|
Scott Baker | 2b56cf4 | 2015-07-15 18:08:06 -0700 | [diff] [blame] | 109 | self.instance.bbs_api_hostname = self.cleaned_data.get("bbs_api_hostname")
|
| 110 | self.instance.bbs_api_port = self.cleaned_data.get("bbs_api_port")
|
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 111 | self.instance.bbs_server = self.cleaned_data.get("bbs_server")
|
Scott Baker | d4829ea | 2015-07-15 18:04:22 -0700 | [diff] [blame] | 112 | self.instance.backend_network_label = self.cleaned_data.get("backend_network_label")
|
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 113 | self.instance.bbs_slice = self.cleaned_data.get("bbs_slice")
|
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 114 | return super(VCPEServiceForm, self).save(commit=commit)
|
| 115 |
|
| 116 | class Meta:
|
| 117 | model = VCPEService |
| 118 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 119 | class VCPEServiceAdmin(ReadOnlyAwareAdmin): |
| 120 | model = VCPEService |
| 121 | verbose_name = "vCPE Service" |
| 122 | verbose_name_plural = "vCPE Service" |
| 123 | list_display = ("backend_status_icon", "name", "enabled") |
| 124 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 125 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "service_specific_attribute",], |
| 126 | 'classes':['suit-tab suit-tab-general']}), |
Scott Baker | 2b56cf4 | 2015-07-15 18:08:06 -0700 | [diff] [blame] | 127 | ("backend config", {'fields': [ "backend_network_label", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"], |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 128 | 'classes':['suit-tab suit-tab-backend']}) ] |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 129 | readonly_fields = ('backend_status_text', "service_specific_attribute") |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 130 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 131 | form = VCPEServiceForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 132 | |
| 133 | extracontext_registered_admins = True |
| 134 | |
| 135 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 136 | |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 137 | suit_form_tabs =(('general', 'Service Details'), |
| 138 | ('backend', 'Backend Config'), |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 139 | ('administration', 'Administration'), |
| 140 | #('tools', 'Tools'), |
| 141 | ('slices','Slices'), |
| 142 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 143 | ('serviceprivileges','Privileges') , |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 144 | ) |
| 145 | |
| 146 | suit_form_includes = (('vcpeadmin.html', 'top', 'administration'), |
| 147 | ) #('hpctools.html', 'top', 'tools') ) |
| 148 | |
| 149 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame^] | 150 | return VCPEService.get_service_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 151 | |
| 152 | class VCPETenantForm(forms.ModelForm): |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 153 | bbs_account = forms.CharField(required=False) |
| 154 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
| 155 | sliver = forms.ModelChoiceField(queryset=Sliver.objects.all(),required=False) |
| 156 | last_ansible_hash = forms.CharField(required=False) |
| 157 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 158 | def __init__(self,*args,**kwargs):
|
| 159 | super (VCPETenantForm,self ).__init__(*args,**kwargs)
|
| 160 | self.fields['kind'].default = "vCPE"
|
| 161 | self.fields['kind'].widget.attrs['readonly'] = True
|
| 162 | self.fields['provider_service'].queryset = VCPEService.get_service_objects().all()
|
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 163 | if self.instance:
|
| 164 | # fields for the attributes
|
| 165 | self.fields['bbs_account'].initial = self.instance.bbs_account
|
| 166 | self.fields['creator'].initial = self.instance.creator
|
| 167 | self.fields['sliver'].initial = self.instance.sliver
|
| 168 | self.fields['last_ansible_hash'].initial = self.instance.last_ansible_hash
|
| 169 |
|
| 170 | def save(self, commit=True):
|
| 171 | self.instance.creator = self.cleaned_data.get("creator")
|
| 172 | self.instance.sliver = self.cleaned_data.get("sliver")
|
| 173 | self.instance.last_ansible_hash = self.cleaned_data.get("last_ansible_hash")
|
| 174 | return super(VCPETenantForm, self).save(commit=commit)
|
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 175 |
|
| 176 | class Meta:
|
| 177 | model = VCPETenant |
| 178 | |
| 179 | class VCPETenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | b3cf921 | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 180 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 181 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 182 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute', |
| 183 | 'bbs_account', 'creator', 'sliver', 'last_ansible_hash'], |
| 184 | 'classes':['suit-tab suit-tab-general']})] |
| 185 | readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account') |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 186 | form = VCPETenantForm |
| 187 | |
| 188 | suit_form_tabs = (('general','Details'),) |
| 189 | |
| 190 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame^] | 191 | return VCPETenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 192 | |
| 193 | #----------------------------------------------------------------------------- |
| 194 | # vBNG |
| 195 | #----------------------------------------------------------------------------- |
| 196 | |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 197 | class VBNGServiceForm(forms.ModelForm): |
| 198 | vbng_url = forms.CharField(required=False) |
| 199 | |
| 200 | def __init__(self,*args,**kwargs):
|
| 201 | super (VBNGServiceForm,self ).__init__(*args,**kwargs)
|
| 202 | if self.instance:
|
| 203 | self.fields['vbng_url'].initial = self.instance.vbng_url
|
| 204 |
|
| 205 | def save(self, commit=True):
|
| 206 | self.instance.vbng_url = self.cleaned_data.get("vbng_url")
|
| 207 | return super(VBNGServiceForm, self).save(commit=commit)
|
| 208 |
|
| 209 | class Meta:
|
| 210 | model = VBNGService |
| 211 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 212 | class VBNGServiceAdmin(ReadOnlyAwareAdmin): |
| 213 | model = VBNGService |
| 214 | verbose_name = "vBNG Service" |
| 215 | verbose_name_plural = "vBNG Service" |
| 216 | list_display = ("backend_status_icon", "name", "enabled") |
| 217 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 218 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", |
| 219 | 'vbng_url' ], |
| 220 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 221 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 222 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 223 | form = VBNGServiceForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 224 | |
| 225 | extracontext_registered_admins = True |
| 226 | |
| 227 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 228 | |
| 229 | suit_form_tabs =(('general', 'vBNG Service Details'), |
| 230 | ('administration', 'Administration'), |
| 231 | #('tools', 'Tools'), |
| 232 | ('slices','Slices'), |
| 233 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 234 | ('serviceprivileges','Privileges'), |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 235 | ) |
| 236 | |
| 237 | suit_form_includes = (('vbngadmin.html', 'top', 'administration'), |
| 238 | ) #('hpctools.html', 'top', 'tools') ) |
| 239 | |
| 240 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame^] | 241 | return VBNGService.get_service_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 242 | |
| 243 | class VBNGTenantForm(forms.ModelForm): |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 244 | routeable_subnet = forms.CharField(required=False) |
| 245 | mapped_hostname = forms.CharField(required=False) |
| 246 | mapped_ip = forms.CharField(required=False) |
| 247 | mapped_mac = forms.CharField(required=False) |
| 248 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 249 | def __init__(self,*args,**kwargs):
|
| 250 | super (VBNGTenantForm,self ).__init__(*args,**kwargs)
|
| 251 | self.fields['kind'].default = "vBNG"
|
| 252 | self.fields['kind'].widget.attrs['readonly'] = True
|
| 253 | self.fields['provider_service'].queryset = VBNGService.get_service_objects().all()
|
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 254 | if self.instance:
|
| 255 | # fields for the attributes
|
| 256 | self.fields['routeable_subnet'].initial = self.instance.routeable_subnet
|
| 257 | self.fields['mapped_hostname'].initial = self.instance.mapped_hostname
|
| 258 | self.fields['mapped_ip'].initial = self.instance.mapped_ip
|
| 259 | self.fields['mapped_mac'].initial = self.instance.mapped_mac
|
| 260 |
|
| 261 | def save(self, commit=True):
|
| 262 | self.instance.routeable_subnet = self.cleaned_data.get("routeable_subnet")
|
| 263 | self.instance.mapped_hostname = self.cleaned_data.get("mapped_hostname")
|
| 264 | self.instance.mapped_ip = self.cleaned_data.get("mapped_ip")
|
| 265 | self.instance.mapped_mac = self.cleaned_data.get("mapped_mac")
|
| 266 | return super(VBNGTenantForm, self).save(commit=commit)
|
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 267 |
|
| 268 | class Meta:
|
| 269 | model = VBNGTenant |
| 270 | |
| 271 | class VBNGTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | b3cf921 | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 272 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 273 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 274 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute', |
| 275 | 'routeable_subnet', 'mapped_hostname', 'mapped_ip', 'mapped_mac'], |
| 276 | 'classes':['suit-tab suit-tab-general']})] |
| 277 | readonly_fields = ('backend_status_text', 'service_specific_attribute') |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 278 | form = VBNGTenantForm |
| 279 | |
| 280 | suit_form_tabs = (('general','Details'),) |
| 281 | |
| 282 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame^] | 283 | return VBNGTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 284 | |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 285 | #----------------------------------------------------------------------------- |
| 286 | # CordSubscriberRoot |
| 287 | #----------------------------------------------------------------------------- |
| 288 | |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 289 | class VOLTTenantInline(XOSTabularInline): |
| 290 | model = VOLTTenant |
| 291 | fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 292 | readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 293 | extra = 0 |
| 294 | max_num = 0 |
| 295 | suit_classes = 'suit-tab suit-tab-volttenants' |
| 296 | fk_name = 'subscriber_root' |
| 297 | verbose_name = 'subscribed tenant' |
| 298 | verbose_name_plural = 'subscribed tenants' |
| 299 | |
| 300 | @property |
| 301 | def selflink_reverse_path(self): |
| 302 | return "admin:cord_volttenant_change" |
| 303 | |
| 304 | def queryset(self, request): |
| 305 | qs = super(VOLTTenantInline, self).queryset(request) |
| 306 | return qs.filter(kind=VOLT_KIND) |
| 307 | |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 308 | class CordSubscriberRootForm(forms.ModelForm): |
| 309 | url_filter_level = forms.CharField(required = False) |
| 310 | |
| 311 | def __init__(self,*args,**kwargs):
|
| 312 | super (CordSubscriberRootForm,self ).__init__(*args,**kwargs)
|
| 313 | self.fields['kind'].default = CORD_SUBSCRIBER_KIND
|
| 314 | self.fields['kind'].widget.attrs['readonly'] = True
|
| 315 | if self.instance:
|
| 316 | self.fields['url_filter_level'].initial = self.instance.url_filter_level
|
| 317 |
|
| 318 | def save(self, commit=True):
|
| 319 | self.instance.url_filter_level = self.cleaned_data.get("url_filter_level")
|
| 320 | return super(CordSubscriberRootForm, self).save(commit=commit)
|
| 321 |
|
| 322 | class Meta:
|
| 323 | model = CordSubscriberRoot |
| 324 | |
| 325 | class CordSubscriberRootAdmin(ReadOnlyAwareAdmin): |
| 326 | list_display = ('backend_status_icon', 'id', 'name', ) |
| 327 | list_display_links = ('backend_status_icon', 'id', 'name', ) |
| 328 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute', |
| 329 | 'url_filter_level'], |
| 330 | 'classes':['suit-tab suit-tab-general']})] |
| 331 | readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account') |
| 332 | form = CordSubscriberRootForm |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 333 | inlines = (VOLTTenantInline, TenantRootPrivilegeInline) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 334 | |
| 335 | suit_form_tabs =(('general', 'Cord Subscriber Root Details'), |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 336 | ('volttenants','VOLT Tenancy'), |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 337 | ('tenantrootprivileges','Privileges') |
| 338 | ) |
| 339 | |
| 340 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame^] | 341 | return CordSubscriberRoot.get_tenant_objects_by_user(request.user) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 342 | |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 343 | admin.site.register(VOLTService, VOLTServiceAdmin) |
| 344 | admin.site.register(VOLTTenant, VOLTTenantAdmin) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 345 | admin.site.register(VCPEService, VCPEServiceAdmin) |
| 346 | admin.site.register(VCPETenant, VCPETenantAdmin) |
| 347 | admin.site.register(VBNGService, VBNGServiceAdmin) |
| 348 | admin.site.register(VBNGTenant, VBNGTenantAdmin) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 349 | admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin) |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 350 | |