Scott Baker | 4eb615b | 2017-05-05 16:55:22 -0700 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
| 3 | #from services.volt.models import * |
| 4 | from services.rcord.models import * |
| 5 | from django import forms |
| 6 | from django.utils.safestring import mark_safe |
| 7 | from django.contrib.auth.admin import UserAdmin |
| 8 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 9 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 10 | from django.contrib.auth.signals import user_logged_in |
| 11 | from django.utils import timezone |
| 12 | from django.contrib.contenttypes import generic |
| 13 | from suit.widgets import LinkedSelect |
| 14 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline |
| 15 | from core.middleware import get_request |
| 16 | |
| 17 | from functools import update_wrapper |
| 18 | from django.contrib.admin.views.main import ChangeList |
| 19 | from django.core.urlresolvers import reverse |
| 20 | from django.contrib.admin.utils import quote |
| 21 | |
| 22 | #class VOLTTenantInline(XOSTabularInline): |
| 23 | # model = VOLTTenant |
| 24 | # fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 25 | # readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 26 | # extra = 0 |
| 27 | # max_num = 0 |
| 28 | # suit_classes = 'suit-tab suit-tab-volttenants' |
| 29 | # fk_name = 'subscriber_root' |
| 30 | # verbose_name = 'subscribed tenant' |
| 31 | # verbose_name_plural = 'subscribed tenants' |
| 32 | # |
| 33 | # @property |
| 34 | # def selflink_reverse_path(self): |
| 35 | # return "admin:cord_volttenant_change" |
| 36 | |
| 37 | class CordSubscriberRootForm(forms.ModelForm): |
| 38 | def __init__(self,*args,**kwargs): |
| 39 | super (CordSubscriberRootForm,self ).__init__(*args,**kwargs) |
| 40 | self.fields['kind'].widget.attrs['readonly'] = True |
| 41 | if (not self.instance) or (not self.instance.pk): |
| 42 | # default fields for an 'add' form |
| 43 | self.fields['kind'].initial = CORD_SUBSCRIBER_KIND |
| 44 | |
| 45 | def save(self, commit=True): |
| 46 | return super(CordSubscriberRootForm, self).save(commit=commit) |
| 47 | |
| 48 | class Meta: |
| 49 | model = CordSubscriberRoot |
| 50 | fields = '__all__' |
| 51 | |
| 52 | class CordSubscriberRootAdmin(ReadOnlyAwareAdmin): |
| 53 | list_display = ('backend_status_icon', 'id', 'name', ) |
| 54 | list_display_links = ('backend_status_icon', 'id', 'name', ) |
| 55 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute', |
| 56 | 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse", "cdn_enable"], |
| 57 | 'classes':['suit-tab suit-tab-general']})] |
| 58 | readonly_fields = ('backend_status_text', 'service_specific_attribute',) |
| 59 | form = CordSubscriberRootForm |
| 60 | inlines = (TenantRootPrivilegeInline) # VOLTTenantInline |
| 61 | |
| 62 | suit_form_tabs =(('general', 'Cord Subscriber Root Details'), |
| 63 | # ('volttenants','VOLT Tenancy'), |
| 64 | ('tenantrootprivileges','Privileges') |
| 65 | ) |
| 66 | |
| 67 | def get_queryset(self, request): |
| 68 | return CordSubscriberRoot.get_tenant_objects_by_user(request.user) |
| 69 | |
| 70 | admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin) |