Scott Baker | 2986b1e | 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 | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 13 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline |
Scott Baker | 2986b1e | 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 | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 20 | #----------------------------------------------------------------------------- |
| 21 | # vOLT |
| 22 | #----------------------------------------------------------------------------- |
Scott Baker | 2986b1e | 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 | 932a16c | 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 | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 31 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 32 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 2986b1e | 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 | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 43 | ('serviceprivileges','Privileges'), |
Scott Baker | 2986b1e | 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): |
| 50 | return VOLTService.get_service_objects() |
| 51 | |
| 52 | class VOLTTenantForm(forms.ModelForm): |
| 53 | def __init__(self,*args,**kwargs):
|
| 54 | super (VOLTTenantForm,self ).__init__(*args,**kwargs)
|
| 55 | self.fields['kind'].default = "vOLT"
|
| 56 | self.fields['kind'].widget.attrs['readonly'] = True
|
| 57 | self.fields['provider_service'].queryset = VOLTService.get_service_objects().all()
|
| 58 |
|
| 59 | class Meta:
|
| 60 | model = VOLTTenant |
| 61 | |
| 62 | class VOLTTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 63 | list_display = ('backend_status_icon', 'id', 'service_specific_id', 'vlan_id' ) |
| 64 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 65 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_id', 'service_specific_attribute',], 'classes':['suit-tab suit-tab-general']})] |
| 66 | readonly_fields = ('backend_status_text', ) |
| 67 | form = VOLTTenantForm |
| 68 | |
| 69 | suit_form_tabs = (('general','Details'),) |
| 70 | |
| 71 | def queryset(self, request): |
| 72 | return VOLTTenant.get_tenant_objects() |
| 73 | |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 74 | #----------------------------------------------------------------------------- |
| 75 | # vCPE |
| 76 | #----------------------------------------------------------------------------- |
| 77 | |
| 78 | class VCPEServiceAdmin(ReadOnlyAwareAdmin): |
| 79 | model = VCPEService |
| 80 | verbose_name = "vCPE Service" |
| 81 | verbose_name_plural = "vCPE Service" |
| 82 | list_display = ("backend_status_icon", "name", "enabled") |
| 83 | list_display_links = ('backend_status_icon', 'name', ) |
| 84 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})] |
| 85 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 86 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 87 | |
| 88 | extracontext_registered_admins = True |
| 89 | |
| 90 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 91 | |
| 92 | suit_form_tabs =(('general', 'vCPE Service Details'), |
| 93 | ('administration', 'Administration'), |
| 94 | #('tools', 'Tools'), |
| 95 | ('slices','Slices'), |
| 96 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 97 | ('serviceprivileges','Privileges') , |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 98 | ) |
| 99 | |
| 100 | suit_form_includes = (('vcpeadmin.html', 'top', 'administration'), |
| 101 | ) #('hpctools.html', 'top', 'tools') ) |
| 102 | |
| 103 | def queryset(self, request): |
| 104 | return VCPEService.get_service_objects() |
| 105 | |
| 106 | class VCPETenantForm(forms.ModelForm): |
| 107 | def __init__(self,*args,**kwargs):
|
| 108 | super (VCPETenantForm,self ).__init__(*args,**kwargs)
|
| 109 | self.fields['kind'].default = "vCPE"
|
| 110 | self.fields['kind'].widget.attrs['readonly'] = True
|
| 111 | self.fields['provider_service'].queryset = VCPEService.get_service_objects().all()
|
| 112 |
|
| 113 | class Meta:
|
| 114 | model = VCPETenant |
| 115 | |
| 116 | class VCPETenantAdmin(ReadOnlyAwareAdmin): |
| 117 | list_display = ('backend_status_icon', 'id' ) |
| 118 | list_display_links = ('backend_status_icon', 'id') |
| 119 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_id', 'service_specific_attribute',], 'classes':['suit-tab suit-tab-general']})] |
| 120 | readonly_fields = ('backend_status_text', ) |
| 121 | form = VCPETenantForm |
| 122 | |
| 123 | suit_form_tabs = (('general','Details'),) |
| 124 | |
| 125 | def queryset(self, request): |
| 126 | return VCPETenant.get_tenant_objects() |
| 127 | |
| 128 | #----------------------------------------------------------------------------- |
| 129 | # vBNG |
| 130 | #----------------------------------------------------------------------------- |
| 131 | |
| 132 | class VBNGServiceAdmin(ReadOnlyAwareAdmin): |
| 133 | model = VBNGService |
| 134 | verbose_name = "vBNG Service" |
| 135 | verbose_name_plural = "vBNG Service" |
| 136 | list_display = ("backend_status_icon", "name", "enabled") |
| 137 | list_display_links = ('backend_status_icon', 'name', ) |
| 138 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})] |
| 139 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 140 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 141 | |
| 142 | extracontext_registered_admins = True |
| 143 | |
| 144 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 145 | |
| 146 | suit_form_tabs =(('general', 'vBNG Service Details'), |
| 147 | ('administration', 'Administration'), |
| 148 | #('tools', 'Tools'), |
| 149 | ('slices','Slices'), |
| 150 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 151 | ('serviceprivileges','Privileges'), |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 152 | ) |
| 153 | |
| 154 | suit_form_includes = (('vbngadmin.html', 'top', 'administration'), |
| 155 | ) #('hpctools.html', 'top', 'tools') ) |
| 156 | |
| 157 | def queryset(self, request): |
| 158 | return VBNGService.get_service_objects() |
| 159 | |
| 160 | class VBNGTenantForm(forms.ModelForm): |
| 161 | def __init__(self,*args,**kwargs):
|
| 162 | super (VBNGTenantForm,self ).__init__(*args,**kwargs)
|
| 163 | self.fields['kind'].default = "vBNG"
|
| 164 | self.fields['kind'].widget.attrs['readonly'] = True
|
| 165 | self.fields['provider_service'].queryset = VBNGService.get_service_objects().all()
|
| 166 |
|
| 167 | class Meta:
|
| 168 | model = VBNGTenant |
| 169 | |
| 170 | class VBNGTenantAdmin(ReadOnlyAwareAdmin): |
| 171 | list_display = ('backend_status_icon', 'id' ) |
| 172 | list_display_links = ('backend_status_icon', 'id') |
| 173 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_id', 'service_specific_attribute',], 'classes':['suit-tab suit-tab-general']})] |
| 174 | readonly_fields = ('backend_status_text', ) |
| 175 | form = VBNGTenantForm |
| 176 | |
| 177 | suit_form_tabs = (('general','Details'),) |
| 178 | |
| 179 | def queryset(self, request): |
| 180 | return VBNGTenant.get_tenant_objects() |
| 181 | |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 182 | admin.site.register(VOLTService, VOLTServiceAdmin) |
| 183 | admin.site.register(VOLTTenant, VOLTTenantAdmin) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 184 | admin.site.register(VCPEService, VCPEServiceAdmin) |
| 185 | admin.site.register(VCPETenant, VCPETenantAdmin) |
| 186 | admin.site.register(VBNGService, VBNGServiceAdmin) |
| 187 | admin.site.register(VBNGTenant, VBNGTenantAdmin) |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 188 | |