blob: 526fe61ae2eb8a50804714bb61e9e69ceb84187d [file] [log] [blame]
Matteo Scandolof0446ed2017-08-08 13:05:24 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Scott Baker4eb615b2017-05-05 16:55:22 -070017from django.contrib import admin
18
19#from services.volt.models import *
20from services.rcord.models import *
21from django import forms
22from django.utils.safestring import mark_safe
23from django.contrib.auth.admin import UserAdmin
24from django.contrib.admin.widgets import FilteredSelectMultiple
25from django.contrib.auth.forms import ReadOnlyPasswordHashField
26from django.contrib.auth.signals import user_logged_in
27from django.utils import timezone
28from django.contrib.contenttypes import generic
29from suit.widgets import LinkedSelect
Scott Bakerc37e7a02017-07-17 17:32:20 -070030from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline
Scott Baker4eb615b2017-05-05 16:55:22 -070031from core.middleware import get_request
32
33from functools import update_wrapper
34from django.contrib.admin.views.main import ChangeList
35from django.core.urlresolvers import reverse
36from django.contrib.admin.utils import quote
37
38#class VOLTTenantInline(XOSTabularInline):
39# model = VOLTTenant
40# fields = ['provider_service', 'subscriber_root', 'service_specific_id']
41# readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id']
42# extra = 0
43# max_num = 0
44# suit_classes = 'suit-tab suit-tab-volttenants'
45# fk_name = 'subscriber_root'
46# verbose_name = 'subscribed tenant'
47# verbose_name_plural = 'subscribed tenants'
48#
49# @property
50# def selflink_reverse_path(self):
51# return "admin:cord_volttenant_change"
52
53class CordSubscriberRootForm(forms.ModelForm):
54 def __init__(self,*args,**kwargs):
55 super (CordSubscriberRootForm,self ).__init__(*args,**kwargs)
56 self.fields['kind'].widget.attrs['readonly'] = True
57 if (not self.instance) or (not self.instance.pk):
58 # default fields for an 'add' form
59 self.fields['kind'].initial = CORD_SUBSCRIBER_KIND
60
61 def save(self, commit=True):
62 return super(CordSubscriberRootForm, self).save(commit=commit)
63
64 class Meta:
65 model = CordSubscriberRoot
66 fields = '__all__'
67
68class CordSubscriberRootAdmin(ReadOnlyAwareAdmin):
69 list_display = ('backend_status_icon', 'id', 'name', )
70 list_display_links = ('backend_status_icon', 'id', 'name', )
71 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute',
72 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse", "cdn_enable"],
73 'classes':['suit-tab suit-tab-general']})]
74 readonly_fields = ('backend_status_text', 'service_specific_attribute',)
75 form = CordSubscriberRootForm
Scott Baker4eb615b2017-05-05 16:55:22 -070076
77 suit_form_tabs =(('general', 'Cord Subscriber Root Details'),
78# ('volttenants','VOLT Tenancy'),
Scott Bakerc37e7a02017-07-17 17:32:20 -070079# ('tenantrootprivileges','Privileges')
Scott Baker4eb615b2017-05-05 16:55:22 -070080 )
81
82 def get_queryset(self, request):
83 return CordSubscriberRoot.get_tenant_objects_by_user(request.user)
84
85admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin)