Andrea Campanella | 45536f7 | 2017-02-23 15:20:06 +0100 | [diff] [blame^] | 1 | from django.contrib import admin |
| 2 | |
| 3 | from services.fabric.models import * |
| 4 | from django import forms |
| 5 | from django.utils.safestring import mark_safe |
| 6 | from django.contrib.auth.admin import UserAdmin |
| 7 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 8 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 9 | from django.contrib.auth.signals import user_logged_in |
| 10 | from django.utils import timezone |
| 11 | from django.contrib.contenttypes import generic |
| 12 | from suit.widgets import LinkedSelect |
| 13 | from core.models import AddressPool |
| 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 | #TODO this class has to be redone according to vEE needs |
| 23 | class VEEServiceForm(forms.ModelForm): |
| 24 | def __init__(self,*args,**kwargs): |
| 25 | super (VEEServiceForm,self ).__init__(*args,**kwargs) |
| 26 | |
| 27 | def save(self, commit=True): |
| 28 | return super(VEEServiceForm, self).save(commit=commit) |
| 29 | |
| 30 | class Meta: |
| 31 | model = VEEService |
| 32 | fields = '__all__' |
| 33 | |
| 34 | class VEEServiceAdmin(ReadOnlyAwareAdmin): |
| 35 | model = VEEService |
| 36 | verbose_name = "VEE Service" |
| 37 | verbose_name_plural = "VEE Services" |
| 38 | list_display = ("backend_status_icon", "name", "enabled") |
| 39 | list_display_links = ('backend_status_icon', 'name', ) |
| 40 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "autoconfig", ], |
| 41 | 'classes':['suit-tab suit-tab-general']})] |
| 42 | readonly_fields = ('backend_status_text', ) |
| 43 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
| 44 | form = VEEServiceForm |
| 45 | |
| 46 | extracontext_registered_admins = True |
| 47 | |
| 48 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 49 | |
| 50 | suit_form_tabs =(('general', 'VEE Service Details'), |
| 51 | ('administration', 'Administration'), |
| 52 | #('tools', 'Tools'), |
| 53 | ('slices','Slices'), |
| 54 | ('serviceattrs','Additional Attributes'), |
| 55 | ('serviceprivileges','Privileges'), |
| 56 | ) |
| 57 | |
| 58 | suit_form_includes = (('veeadmin.html', 'top', 'administration'), |
| 59 | ) |
| 60 | |
| 61 | def get_queryset(self, request): |
| 62 | return VEEService.get_service_objects_by_user(request.user) |
| 63 | |
| 64 | admin.site.register(VEEService, VEEServiceAdmin) |