Scott Baker | 43fae6a | 2016-04-27 22:53:43 -0700 | [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 | class FabricServiceForm(forms.ModelForm): |
| 23 | def __init__(self,*args,**kwargs): |
Scott Baker | e32c842 | 2016-04-28 13:54:09 -0700 | [diff] [blame] | 24 | super (FabricServiceForm,self ).__init__(*args,**kwargs) |
Scott Baker | 43fae6a | 2016-04-27 22:53:43 -0700 | [diff] [blame] | 25 | |
| 26 | def save(self, commit=True): |
Scott Baker | e32c842 | 2016-04-28 13:54:09 -0700 | [diff] [blame] | 27 | return super(FabricServiceForm, self).save(commit=commit) |
Scott Baker | 43fae6a | 2016-04-27 22:53:43 -0700 | [diff] [blame] | 28 | |
| 29 | class Meta: |
| 30 | model = FabricService |
| 31 | |
| 32 | class FabricServiceAdmin(ReadOnlyAwareAdmin): |
| 33 | model = FabricService |
| 34 | verbose_name = "Fabric Service" |
| 35 | verbose_name_plural = "Fabric Services" |
| 36 | list_display = ("backend_status_icon", "name", "enabled") |
| 37 | list_display_links = ('backend_status_icon', 'name', ) |
| 38 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", ], |
| 39 | 'classes':['suit-tab suit-tab-general']})] |
| 40 | readonly_fields = ('backend_status_text', ) |
| 41 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
| 42 | form = FabricServiceForm |
| 43 | |
| 44 | extracontext_registered_admins = True |
| 45 | |
| 46 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 47 | |
Scott Baker | e32c842 | 2016-04-28 13:54:09 -0700 | [diff] [blame] | 48 | suit_form_tabs =(('general', 'Fabric Service Details'), |
Scott Baker | 43fae6a | 2016-04-27 22:53:43 -0700 | [diff] [blame] | 49 | ('administration', 'Administration'), |
| 50 | #('tools', 'Tools'), |
| 51 | ('slices','Slices'), |
| 52 | ('serviceattrs','Additional Attributes'), |
| 53 | ('serviceprivileges','Privileges'), |
| 54 | ) |
| 55 | |
Scott Baker | e32c842 | 2016-04-28 13:54:09 -0700 | [diff] [blame] | 56 | suit_form_includes = (('fabricadmin.html', 'top', 'administration'), |
| 57 | ) |
Scott Baker | 43fae6a | 2016-04-27 22:53:43 -0700 | [diff] [blame] | 58 | |
| 59 | def queryset(self, request): |
| 60 | return FabricService.get_service_objects_by_user(request.user) |
| 61 | |
| 62 | admin.site.register(FabricService, FabricServiceAdmin) |
| 63 | |