Matteo Scandolo | f0446ed | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 1 | |
| 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 Baker | 4eb615b | 2017-05-05 16:55:22 -0700 | [diff] [blame] | 17 | from django.contrib import admin |
| 18 | |
| 19 | #from services.volt.models import * |
| 20 | from services.rcord.models import * |
| 21 | from django import forms |
| 22 | from django.utils.safestring import mark_safe |
| 23 | from django.contrib.auth.admin import UserAdmin |
| 24 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 25 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 26 | from django.contrib.auth.signals import user_logged_in |
| 27 | from django.utils import timezone |
| 28 | from django.contrib.contenttypes import generic |
| 29 | from suit.widgets import LinkedSelect |
Scott Baker | c37e7a0 | 2017-07-17 17:32:20 -0700 | [diff] [blame] | 30 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline |
Scott Baker | 4eb615b | 2017-05-05 16:55:22 -0700 | [diff] [blame] | 31 | from core.middleware import get_request |
| 32 | |
| 33 | from functools import update_wrapper |
| 34 | from django.contrib.admin.views.main import ChangeList |
| 35 | from django.core.urlresolvers import reverse |
| 36 | from 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 | |
| 53 | class 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 | |
| 68 | class 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 Baker | 4eb615b | 2017-05-05 16:55:22 -0700 | [diff] [blame] | 76 | |
| 77 | suit_form_tabs =(('general', 'Cord Subscriber Root Details'), |
| 78 | # ('volttenants','VOLT Tenancy'), |
Scott Baker | c37e7a0 | 2017-07-17 17:32:20 -0700 | [diff] [blame] | 79 | # ('tenantrootprivileges','Privileges') |
Scott Baker | 4eb615b | 2017-05-05 16:55:22 -0700 | [diff] [blame] | 80 | ) |
| 81 | |
| 82 | def get_queryset(self, request): |
| 83 | return CordSubscriberRoot.get_tenant_objects_by_user(request.user) |
| 84 | |
| 85 | admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin) |