add admin-only tab for sliceadmine
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index d2a9b53..47f9eab 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -735,6 +735,15 @@
raise forms.ValidationError('slice name must begin with %s' % site.login_base)
return cleaned_data
+class SliceDeploymentsInline(PlStackTabularInline):
+ model = SliceDeployments
+ extra = 0
+ verbose_name = "Slice Deployment"
+ verbose_name_plural = "Slice Deployments"
+ suit_classes = 'suit-tab suit-tab-admin-only'
+ fields = ['backend_status_icon', 'deployment', 'tenant_id']
+ readonly_fields = ('backend_status_icon', )
+
class SliceAdmin(PlanetStackBaseAdmin):
form = SliceForm
fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_slivers']
@@ -743,16 +752,40 @@
list_display = ('backend_status_icon', 'name', 'site','serviceClass', 'slice_url', 'max_slivers')
list_display_links = ('backend_status_icon', 'name', )
inlines = [SlicePrivilegeInline,SliverInline, TagInline, ReservationInline,SliceNetworkInline]
+ admin_inlines = [SliceDeploymentsInline]
user_readonly_fields = fieldList
- suit_form_tabs =(('general', 'Slice Details'),
- ('slicenetworks','Networks'),
- ('sliceprivileges','Privileges'),
- ('slivers','Slivers'),
- ('tags','Tags'),
- ('reservations','Reservations'),
- )
+# suit_form_tabs =(('general', 'Slice Details'),
+# ('slicenetworks','Networks'),
+# ('sliceprivileges','Privileges'),
+# ('slivers','Slivers'),
+# ('tags','Tags'),
+# ('reservations','Reservations'),
+# )
+
+ def get_form(self, request, obj=None):
+ # Save obj in thread-local storage, so suit_form_tabs can use it to
+ # determine whether we're in edit or add mode.
+ _thread_locals.request = request
+ _thread_locals.obj = obj
+ return super(SliceAdmin, self).get_form(request, obj)
+
+ @property
+ def suit_form_tabs(self):
+ tabs =[('general', 'Slice Details'),
+ ('slicenetworks','Networks'),
+ ('sliceprivileges','Privileges'),
+ ('slivers','Slivers'),
+ ('tags','Tags'),
+ ('reservations','Reservations'),
+ ]
+
+ request=getattr(_thread_locals, "request", None)
+ if request and request.user.is_admin:
+ tabs.append( ('admin-only', 'Admin-Only') )
+
+ return tabs
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
deployment_nodes = []
@@ -799,6 +832,14 @@
inline.model.caller = request.user
yield inline.get_formset(request, obj)
+ def get_inline_instances(self, request, obj=None):
+ inlines = super(SliceAdmin, self).get_inline_instances(request, obj)
+
+ if request.user.is_admin:
+ for inline_class in self.admin_inlines:
+ inlines.append(inline_class(self.model, self.admin_site))
+
+ return inlines
class SlicePrivilegeAdmin(PlanetStackBaseAdmin):
fieldsets = [