blob: 5ab2f1c5c630f4b61184786e2e26879457812093 [file] [log] [blame]
Scott Baker7a327592016-06-20 17:34:06 -07001from django.contrib import admin
2
3from services.onos.models import *
4from django import forms
5from django.utils.safestring import mark_safe
6from django.contrib.auth.admin import UserAdmin
7from django.contrib.admin.widgets import FilteredSelectMultiple
8from django.contrib.auth.forms import ReadOnlyPasswordHashField
9from django.contrib.auth.signals import user_logged_in
10from django.utils import timezone
11from django.contrib.contenttypes import generic
12from suit.widgets import LinkedSelect
13from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline, TenantAttrAsTabInline
14from core.middleware import get_request
15
16from functools import update_wrapper
17from django.contrib.admin.views.main import ChangeList
18from django.core.urlresolvers import reverse
19from django.contrib.admin.utils import quote
20
Scott Baker7a327592016-06-20 17:34:06 -070021class ONOSServiceAdmin(ReadOnlyAwareAdmin):
22 model = ONOSService
23 verbose_name = "ONOS Service"
24 verbose_name_plural = "ONOS Services"
25 list_display = ("backend_status_icon", "name", "enabled")
26 list_display_links = ('backend_status_icon', 'name', )
27 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url", "rest_hostname", "rest_port", "no_container" ], 'classes':['suit-tab suit-tab-general']})]
28 readonly_fields = ('backend_status_text', )
29 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Baker7a327592016-06-20 17:34:06 -070030
31 extracontext_registered_admins = True
32
33 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
34
35 suit_form_tabs =(('general', 'ONOS Service Details'),
36 ('administration', 'Administration'),
37 ('slices','Slices'),
38 ('serviceattrs','Additional Attributes'),
39 ('serviceprivileges','Privileges'),
40 )
41
42 suit_form_includes = (('onosadmin.html', 'top', 'administration'),
43 )
44
Zack Williamsd60c7732016-06-27 13:15:21 -070045 def get_queryset(self, request):
Scott Baker7a327592016-06-20 17:34:06 -070046 return ONOSService.get_service_objects_by_user(request.user)
47
48class ONOSAppForm(forms.ModelForm):
Scott Baker7a327592016-06-20 17:34:06 -070049 def __init__(self,*args,**kwargs):
50 super (ONOSAppForm,self ).__init__(*args,**kwargs)
51 self.fields['kind'].widget.attrs['readonly'] = True
Scott Baker88b71092017-03-13 15:15:29 -070052 self.fields['provider_service'].queryset = ONOSService.objects.all()
Scott Baker7a327592016-06-20 17:34:06 -070053 if (not self.instance) or (not self.instance.pk):
54 # default fields for an 'add' form
55 self.fields['kind'].initial = ONOS_KIND
56 self.fields['creator'].initial = get_request().user
Scott Baker88b71092017-03-13 15:15:29 -070057 if ONOSService.objects.exists():
Scott Baker7a327592016-06-20 17:34:06 -070058 self.fields["provider_service"].initial = ONOSService.get_service_objects().all()[0]
59
60 def save(self, commit=True):
Scott Baker7a327592016-06-20 17:34:06 -070061 return super(ONOSAppForm, self).save(commit=commit)
62
63 class Meta:
64 model = ONOSApp
Zack Williams3026c522016-06-27 08:30:53 -070065 fields = '__all__'
Scott Baker7a327592016-06-20 17:34:06 -070066
67class ONOSAppAdmin(ReadOnlyAwareAdmin):
68 list_display = ('backend_status_icon', 'name', )
69 list_display_links = ('backend_status_icon', 'name')
70 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'provider_service', 'subscriber_service', 'service_specific_attribute', "dependencies",
71 'creator'],
72 'classes':['suit-tab suit-tab-general']})]
73 readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute')
74 inlines = [TenantAttrAsTabInline]
75 form = ONOSAppForm
76
77 suit_form_tabs = (('general','Details'), ('tenantattrs', 'Attributes'))
78
Zack Williamsd60c7732016-06-27 13:15:21 -070079 def get_queryset(self, request):
Scott Baker7a327592016-06-20 17:34:06 -070080 return ONOSApp.get_tenant_objects_by_user(request.user)
81
82admin.site.register(ONOSService, ONOSServiceAdmin)
83admin.site.register(ONOSApp, ONOSAppAdmin)
84