Matteo Scandolo | 5eb20bb | 2017-08-08 13:05:26 -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 | |
Andrea Campanella | 45536f7 | 2017-02-23 15:20:06 +0100 | [diff] [blame] | 17 | from django.contrib import admin |
| 18 | |
| 19 | from services.fabric.models import * |
| 20 | from django import forms |
| 21 | from django.utils.safestring import mark_safe |
| 22 | from django.contrib.auth.admin import UserAdmin |
| 23 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 24 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 25 | from django.contrib.auth.signals import user_logged_in |
| 26 | from django.utils import timezone |
| 27 | from django.contrib.contenttypes import generic |
| 28 | from suit.widgets import LinkedSelect |
| 29 | from core.models import AddressPool |
| 30 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline |
| 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 | #TODO this class has to be redone according to vEE needs |
| 39 | class VEEServiceForm(forms.ModelForm): |
| 40 | def __init__(self,*args,**kwargs): |
| 41 | super (VEEServiceForm,self ).__init__(*args,**kwargs) |
| 42 | |
| 43 | def save(self, commit=True): |
| 44 | return super(VEEServiceForm, self).save(commit=commit) |
| 45 | |
| 46 | class Meta: |
| 47 | model = VEEService |
| 48 | fields = '__all__' |
| 49 | |
| 50 | class VEEServiceAdmin(ReadOnlyAwareAdmin): |
| 51 | model = VEEService |
| 52 | verbose_name = "VEE Service" |
| 53 | verbose_name_plural = "VEE Services" |
| 54 | list_display = ("backend_status_icon", "name", "enabled") |
| 55 | list_display_links = ('backend_status_icon', 'name', ) |
| 56 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "autoconfig", ], |
| 57 | 'classes':['suit-tab suit-tab-general']})] |
| 58 | readonly_fields = ('backend_status_text', ) |
| 59 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
| 60 | form = VEEServiceForm |
| 61 | |
| 62 | extracontext_registered_admins = True |
| 63 | |
| 64 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 65 | |
| 66 | suit_form_tabs =(('general', 'VEE Service Details'), |
| 67 | ('administration', 'Administration'), |
| 68 | #('tools', 'Tools'), |
| 69 | ('slices','Slices'), |
| 70 | ('serviceattrs','Additional Attributes'), |
| 71 | ('serviceprivileges','Privileges'), |
| 72 | ) |
| 73 | |
| 74 | suit_form_includes = (('veeadmin.html', 'top', 'administration'), |
| 75 | ) |
| 76 | |
| 77 | def get_queryset(self, request): |
| 78 | return VEEService.get_service_objects_by_user(request.user) |
| 79 | |
| 80 | admin.site.register(VEEService, VEEServiceAdmin) |