Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1 | from core.models import Site |
| 2 | from core.models import * |
| 3 | from openstack.manager import OpenStackManager |
Tony Mack | e59a7c8 | 2013-04-27 11:08:10 -0400 | [diff] [blame] | 4 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 5 | from django.contrib import admin |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 6 | from django.contrib.auth.models import Group |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 7 | from django import forms |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 8 | from django.utils.safestring import mark_safe |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 9 | from django.contrib.auth.admin import UserAdmin |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 10 | from django.contrib.admin.widgets import FilteredSelectMultiple, AdminTextareaWidget |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 11 | from django.contrib.auth.forms import ReadOnlyPasswordHashField, AdminPasswordChangeForm |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 12 | from django.contrib.auth.signals import user_logged_in |
| 13 | from django.utils import timezone |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 14 | from django.contrib.contenttypes import generic |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 15 | from suit.widgets import LinkedSelect |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 16 | from django.core.exceptions import PermissionDenied |
Tony Mack | 7b6400d | 2015-02-16 19:54:24 -0500 | [diff] [blame] | 17 | from django.core.urlresolvers import reverse, resolve, NoReverseMatch |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 18 | from django.utils.encoding import force_text, python_2_unicode_compatible |
| 19 | from django.utils.html import conditional_escape, format_html |
Scott Baker | 7a056af | 2015-02-26 20:42:11 -0800 | [diff] [blame] | 20 | from django.utils.text import capfirst |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 21 | from django.forms.utils import flatatt, to_current_timezone |
Scott Baker | 2d281a9 | 2015-07-09 19:06:08 -0700 | [diff] [blame] | 22 | from django.core.exceptions import PermissionDenied, ValidationError |
Scott Baker | 3cde737 | 2014-10-21 21:03:08 -0700 | [diff] [blame] | 23 | from cgi import escape as html_escape |
Scott Baker | 2d281a9 | 2015-07-09 19:06:08 -0700 | [diff] [blame] | 24 | from django.contrib import messages |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 25 | |
Scott Baker | 0a5633b | 2014-10-06 17:51:20 -0700 | [diff] [blame] | 26 | import threading |
| 27 | |
| 28 | # thread locals necessary to work around a django-suit issue |
| 29 | _thread_locals = threading.local() |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 30 | |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 31 | ICON_URLS = {"success": "/static/admin/img/icon_success.gif", |
| 32 | "clock": "/static/admin/img/icon_clock.gif", |
| 33 | "error": "/static/admin/img/icon_error.gif"} |
| 34 | |
| 35 | def backend_icon(obj): |
| 36 | (icon, tooltip) = obj.get_backend_icon() |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 37 | |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 38 | icon_url = ICON_URLS.get(icon, "unknown") |
| 39 | |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 40 | (exponent,last_success,last_failure,failures) = obj.get_backend_details() |
| 41 | |
Sapan Bhatia | 0253cf2 | 2015-12-22 18:38:36 +0100 | [diff] [blame] | 42 | # FIXME: Need to clean this up by separating Javascript from Python |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 43 | if (obj.pk): |
| 44 | script = """ |
| 45 | <script type="text/javascript"> |
| 46 | $(document).ready(function () { |
| 47 | $("#show_details_%d").click(function () { |
| 48 | $("#status%d").dialog({modal: true, height: 200, width: 200 }); |
| 49 | }); |
| 50 | }); |
| 51 | </script> |
| 52 | """%(obj.pk,obj.pk) |
| 53 | |
| 54 | div = """ |
| 55 | <div style="display:none;" id="status%d" title="Details"> |
| 56 | <p>Backoff Exponent: %r</p> |
| 57 | <p>Last Success: %r</p> |
| 58 | <p>Failures: %r</p> |
| 59 | <p>Last Failure: %r</p> |
| 60 | </div> |
| 61 | """%(obj.pk,exponent,last_success,failures,last_failure) |
| 62 | a = '<a id="show_details_%d" href="#">'%obj.pk |
| 63 | astop = '</a>' |
| 64 | else: |
| 65 | div = '' |
| 66 | script = '' |
| 67 | a = '' |
| 68 | astop = '' |
| 69 | |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 70 | if tooltip: |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 71 | return '%s %s <span style="min-width:16px;" title="%s">%s<img src="%s">%s</span>' % (script, div, tooltip, a, icon_url, astop) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 72 | else: |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 73 | return '<span style="min-width:16px;"><img src="%s"></span>' % icon_url |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 74 | |
| 75 | def backend_text(obj): |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 76 | (icon, tooltip) = obj.get_backend_icon() |
| 77 | icon_url = ICON_URLS.get(icon, "unknown") |
| 78 | |
| 79 | return '<img src="%s"> %s' % (icon_url, tooltip) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 80 | |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 81 | class UploadTextareaWidget(AdminTextareaWidget): |
| 82 | def render(self, name, value, attrs=None): |
| 83 | if value is None: |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 84 | value = '' |
| 85 | final_attrs = self.build_attrs(attrs, name=name) |
| 86 | return format_html('<input type="file" style="width: 0; height: 0" id="btn_upload_%s" onChange="uploadTextarea(event,\'%s\');">' \ |
| 87 | '<button onClick="$(\'#btn_upload_%s\').click(); return false;">Upload</button>' \ |
| 88 | '<br><textarea{0}>\r\n{1}</textarea>' % (attrs["id"], attrs["id"], attrs["id"]), |
| 89 | flatatt(final_attrs), |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 90 | force_text(value)) |
| 91 | |
Scott Baker | b92b5c7 | 2015-05-11 16:36:58 -0700 | [diff] [blame] | 92 | class SliderWidget(forms.HiddenInput): |
| 93 | def render(self, name, value, attrs=None): |
| 94 | if value is None: |
| 95 | value = '0' |
| 96 | final_attrs = self.build_attrs(attrs, name=name) |
| 97 | attrs = attrs or attrs[:] |
| 98 | attrs["name"] = name |
| 99 | attrs["value"] = value |
| 100 | html = """<div style="width:640px"><span id="%(id)s_label">%(value)s</span><div id="%(id)s_slider" style="float:right;width:610px;margin-top:5px"></div></div> |
| 101 | <script> |
| 102 | $(function() { |
| 103 | $("#%(id)s_slider").slider({ |
| 104 | value: %(value)s, |
| 105 | slide: function(event, ui) { $("#%(id)s").val( ui.value ); $("#%(id)s_label").html(ui.value); }, |
| 106 | }); |
| 107 | }); |
| 108 | </script> |
| 109 | <input type="hidden" id="%(id)s" name="%(name)s" value="%(value)s"></input> |
| 110 | """ % attrs |
| 111 | html = html.replace("{","{{").replace("}","}}") |
| 112 | return format_html(html, |
| 113 | flatatt(final_attrs), |
| 114 | force_text(value)) |
| 115 | |
| 116 | |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 117 | class PlainTextWidget(forms.HiddenInput): |
| 118 | input_type = 'hidden' |
| 119 | |
| 120 | def render(self, name, value, attrs=None): |
| 121 | if value is None: |
| 122 | value = '' |
| 123 | return mark_safe(str(value) + super(PlainTextWidget, self).render(name, value, attrs)) |
| 124 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 125 | class XOSAdminMixin(object): |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 126 | # call save_by_user and delete_by_user instead of save and delete |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 127 | |
| 128 | def has_add_permission(self, request, obj=None): |
| 129 | return (not self.__user_is_readonly(request)) |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 130 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 131 | def has_delete_permission(self, request, obj=None): |
| 132 | return (not self.__user_is_readonly(request)) |
| 133 | |
| 134 | def save_model(self, request, obj, form, change): |
| 135 | if self.__user_is_readonly(request): |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 136 | # this 'if' might be redundant if save_by_user is implemented right |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 137 | raise PermissionDenied |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 138 | |
Scott Baker | bf08f2f | 2015-12-01 10:24:01 -0800 | [diff] [blame] | 139 | # reset exponential backoff |
| 140 | if hasattr(obj, "backend_register"): |
| 141 | obj.backend_register = "{}" |
| 142 | |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 143 | obj.caller = request.user |
| 144 | # update openstack connection to use this site/tenant |
| 145 | obj.save_by_user(request.user) |
| 146 | |
| 147 | def delete_model(self, request, obj): |
| 148 | obj.delete_by_user(request.user) |
| 149 | |
| 150 | def save_formset(self, request, form, formset, change): |
| 151 | instances = formset.save(commit=False) |
| 152 | for instance in instances: |
Scott Baker | cf9cbad | 2015-07-08 18:23:17 -0700 | [diff] [blame] | 153 | instance.caller = request.user |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 154 | instance.save_by_user(request.user) |
| 155 | |
| 156 | # BUG in django 1.7? Objects are not deleted by formset.save if |
| 157 | # commit is False. So let's delete them ourselves. |
| 158 | # |
| 159 | # code from forms/models.py save_existing_objects() |
| 160 | try: |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 161 | forms_to_delete = formset.deleted_forms |
| 162 | except AttributeError: |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 163 | forms_to_delete = [] |
| 164 | if formset.initial_forms: |
| 165 | for form in formset.initial_forms: |
| 166 | obj = form.instance |
| 167 | if form in forms_to_delete: |
| 168 | if obj.pk is None: |
| 169 | continue |
| 170 | formset.deleted_objects.append(obj) |
| 171 | obj.delete() |
| 172 | |
| 173 | formset.save_m2m() |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 174 | |
| 175 | def get_actions(self,request): |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 176 | actions = super(XOSAdminMixin,self).get_actions(request) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 177 | |
| 178 | if self.__user_is_readonly(request): |
| 179 | if 'delete_selected' in actions: |
| 180 | del actions['delete_selected'] |
| 181 | |
| 182 | return actions |
| 183 | |
Scott Baker | ff3c2d2 | 2015-04-03 17:44:31 -0700 | [diff] [blame] | 184 | def url_for_model_changelist(self, request, model): |
| 185 | # used in add_extra_context |
| 186 | return reverse('admin:%s_%s_changelist' % (model._meta.app_label, model._meta.model_name), current_app=model._meta.app_label) |
| 187 | |
Scott Baker | ba534e7 | 2015-04-02 22:32:40 -0700 | [diff] [blame] | 188 | def add_extra_context(self, request, extra_context): |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 189 | # allow custom application breadcrumb url and name |
| 190 | extra_context["custom_app_breadcrumb_url"] = getattr(self, "custom_app_breadcrumb_url", None) |
| 191 | extra_context["custom_app_breadcrumb_name"] = getattr(self, "custom_app_breadcrumb_name", None) |
Scott Baker | 0998bcc | 2015-04-02 22:07:18 -0700 | [diff] [blame] | 192 | extra_context["custom_changelist_breadcrumb_url"] = getattr(self, "custom_changelist_breadcrumb_url", None) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 193 | |
| 194 | # for Service admins to render their Administration page |
| 195 | if getattr(self, "extracontext_registered_admins", False): |
| 196 | admins=[] |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 197 | for model, model_admin in admin.site._registry.items(): |
| 198 | if model == self.model: |
| 199 | continue |
| 200 | if model._meta.app_label == self.model._meta.app_label: |
| 201 | info = {"app": model._meta.app_label, |
| 202 | "model": model._meta.model_name, |
| 203 | "name": capfirst(model._meta.verbose_name_plural), |
| 204 | "url": self.url_for_model_changelist(request,model) } |
| 205 | admins.append(info) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 206 | extra_context["registered_admins"] = admins |
| 207 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 208 | def change_view(self,request,object_id, extra_context=None): |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 209 | extra_context = extra_context or {} |
| 210 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 211 | if self.__user_is_readonly(request): |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 212 | if not hasattr(self, "readonly_save"): |
| 213 | # save the original readonly fields |
| 214 | self.readonly_save = self.readonly_fields |
| 215 | self.inlines_save = self.inlines |
| 216 | if hasattr(self, "user_readonly_fields"): |
| 217 | self.readonly_fields=self.user_readonly_fields |
| 218 | if hasattr(self, "user_readonly_inlines"): |
| 219 | self.inlines = self.user_readonly_inlines |
| 220 | else: |
| 221 | if hasattr(self, "readonly_save"): |
| 222 | # restore the original readonly fields |
| 223 | self.readonly_fields = self.readonly_save |
| 224 | if hasattr(self, "inlines_save"): |
Scott Baker | af73e10 | 2014-04-22 22:40:07 -0700 | [diff] [blame] | 225 | self.inlines = self.inlines_save |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 226 | |
Scott Baker | ba534e7 | 2015-04-02 22:32:40 -0700 | [diff] [blame] | 227 | self.add_extra_context(request, extra_context) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 228 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 229 | try: |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 230 | return super(XOSAdminMixin, self).change_view(request, object_id, extra_context=extra_context) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 231 | except PermissionDenied: |
| 232 | pass |
Scott Baker | 2d281a9 | 2015-07-09 19:06:08 -0700 | [diff] [blame] | 233 | except ValidationError as e: |
| 234 | if (e.params is None): |
| 235 | # Validation errors that don't reference a specific field will |
| 236 | # often throw a non-descriptive 500 page to the user. The code |
| 237 | # below will cause an error message to be printed and the |
| 238 | # page refreshed instead. |
| 239 | # As a side-effect it turns the request back into a 'GET' which |
| 240 | # may wipe anything the user had changed on the page. But, at |
| 241 | # least the user gets a real error message. |
| 242 | # TODO: revisit this and display some kind of error view |
| 243 | request.method = 'GET' |
| 244 | messages.error(request, e.message) |
| 245 | return super(XOSAdminMixin, self).change_view(request, object_id, extra_context=extra_context) |
| 246 | else: |
| 247 | raise |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 248 | if request.method == 'POST': |
| 249 | raise PermissionDenied |
| 250 | request.readonly = True |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 251 | return super(XOSAdminMixin, self).change_view(request, object_id, extra_context=extra_context) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 252 | |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 253 | def changelist_view(self, request, extra_context = None): |
| 254 | extra_context = extra_context or {} |
| 255 | |
Scott Baker | ba534e7 | 2015-04-02 22:32:40 -0700 | [diff] [blame] | 256 | self.add_extra_context(request, extra_context) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 257 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 258 | return super(XOSAdminMixin, self).changelist_view(request, extra_context=extra_context) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 259 | |
Scott Baker | 2aea036 | 2015-04-14 17:01:18 -0700 | [diff] [blame] | 260 | def add_view(self, request, form_url='', extra_context = None): |
Scott Baker | ff3c2d2 | 2015-04-03 17:44:31 -0700 | [diff] [blame] | 261 | extra_context = extra_context or {} |
| 262 | |
| 263 | self.add_extra_context(request, extra_context) |
| 264 | |
Scott Baker | 2aea036 | 2015-04-14 17:01:18 -0700 | [diff] [blame] | 265 | return super(XOSAdminMixin, self).add_view(request, form_url, extra_context=extra_context) |
Scott Baker | ff3c2d2 | 2015-04-03 17:44:31 -0700 | [diff] [blame] | 266 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 267 | def __user_is_readonly(self, request): |
| 268 | return request.user.isReadOnlyUser() |
| 269 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 270 | def backend_status_text(self, obj): |
| 271 | return mark_safe(backend_text(obj)) |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 272 | |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 273 | def backend_status_icon(self, obj): |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 274 | return mark_safe(backend_icon(obj)) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 275 | backend_status_icon.short_description = "" |
| 276 | |
Scott Baker | 24ded6a | 2014-11-05 09:05:38 -0800 | [diff] [blame] | 277 | def get_form(self, request, obj=None, **kwargs): |
Scott Baker | 5c43269 | 2014-10-16 00:57:55 -0700 | [diff] [blame] | 278 | # Save obj and request in thread-local storage, so suit_form_tabs can |
| 279 | # use it to determine whether we're in edit or add mode, and can |
| 280 | # determine whether the user is an admin. |
| 281 | _thread_locals.request = request |
| 282 | _thread_locals.obj = obj |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 283 | return super(XOSAdminMixin, self).get_form(request, obj, **kwargs) |
Scott Baker | 5c43269 | 2014-10-16 00:57:55 -0700 | [diff] [blame] | 284 | |
| 285 | def get_inline_instances(self, request, obj=None): |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 286 | inlines = super(XOSAdminMixin, self).get_inline_instances(request, obj) |
Scott Baker | 5c43269 | 2014-10-16 00:57:55 -0700 | [diff] [blame] | 287 | |
| 288 | # inlines that should only be shown to an admin user |
| 289 | if request.user.is_admin: |
| 290 | for inline_class in getattr(self, "admin_inlines", []): |
| 291 | inlines.append(inline_class(self.model, self.admin_site)) |
| 292 | |
| 293 | return inlines |
| 294 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 295 | class ReadOnlyAwareAdmin(XOSAdminMixin, admin.ModelAdmin): |
| 296 | # Note: Make sure XOSAdminMixin is listed before |
Scott Baker | 86c83ab | 2014-10-03 13:10:47 -0700 | [diff] [blame] | 297 | # admin.ModelAdmin in the class declaration. |
| 298 | |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 299 | pass |
| 300 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 301 | class XOSBaseAdmin(ReadOnlyAwareAdmin): |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 302 | save_on_top = False |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 303 | |
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 304 | class SingletonAdmin (ReadOnlyAwareAdmin): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 305 | def has_add_permission(self, request): |
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 306 | if not super(SingletonAdmin, self).has_add_permission(request): |
| 307 | return False |
| 308 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 309 | num_objects = self.model.objects.count() |
| 310 | if num_objects >= 1: |
| 311 | return False |
| 312 | else: |
| 313 | return True |
| 314 | |
Scott Baker | 7a056af | 2015-02-26 20:42:11 -0800 | [diff] [blame] | 315 | class ServiceAppAdmin (SingletonAdmin): |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 316 | extracontext_registered_admins = True |
Scott Baker | 7a056af | 2015-02-26 20:42:11 -0800 | [diff] [blame] | 317 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 318 | class XOSTabularInline(admin.TabularInline): |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 319 | def __init__(self, *args, **kwargs): |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 320 | super(XOSTabularInline, self).__init__(*args, **kwargs) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 321 | |
| 322 | # InlineModelAdmin as no get_fields() method, so in order to add |
| 323 | # the selflink field, we override __init__ to modify self.fields and |
| 324 | # self.readonly_fields. |
| 325 | |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 326 | self.setup_selflink() |
| 327 | |
Scott Baker | d5df950 | 2015-07-24 09:32:14 -0700 | [diff] [blame] | 328 | @property |
| 329 | def selflink_model(self): |
| 330 | if hasattr(self, "selflink_fieldname"): |
| 331 | """ self.selflink_model can be defined to punch through a relation |
| 332 | to its target object. For example, in SliceNetworkInline, set |
| 333 | selflink_model = "network", and the URL will lead to the Network |
| 334 | object instead of trying to bring up a change view of the |
| 335 | SliceNetwork object. |
| 336 | """ |
| 337 | return getattr(self.model,self.selflink_fieldname).field.rel.to |
| 338 | else: |
| 339 | return self.model |
| 340 | |
| 341 | @property |
| 342 | def selflink_reverse_path(self): |
| 343 | return "admin:%s_change" % (self.selflink_model._meta.db_table) |
| 344 | |
| 345 | def get_change_url(self, id): |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 346 | """ Get the URL to a change form in the admin for this model """ |
Scott Baker | 2978678 | 2015-07-27 08:53:05 -0700 | [diff] [blame] | 347 | reverse_path = self.selflink_reverse_path # "admin:%s_change" % (self.selflink_model._meta.db_table) |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 348 | try: |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 349 | url = reverse(reverse_path, args=(id,)) |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 350 | except NoReverseMatch: |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 351 | return None |
| 352 | |
| 353 | return url |
| 354 | |
| 355 | def setup_selflink(self): |
Scott Baker | d5df950 | 2015-07-24 09:32:14 -0700 | [diff] [blame] | 356 | url = self.get_change_url(0) |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 357 | |
| 358 | # We don't have an admin for this object, so don't create the |
| 359 | # selflink. |
| 360 | if (url == None): |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 361 | return |
| 362 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 363 | # Since we need to add "selflink" to the field list, we need to create |
| 364 | # self.fields if it is None. |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 365 | if (self.fields is None): |
| 366 | self.fields = [] |
| 367 | for f in self.model._meta.fields: |
| 368 | if f.editable and f.name != "id": |
| 369 | self.fields.append(f.name) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 370 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 371 | self.fields = tuple(self.fields) + ("selflink", ) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 372 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 373 | if self.readonly_fields is None: |
| 374 | self.readonly_fields = () |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 375 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 376 | self.readonly_fields = tuple(self.readonly_fields) + ("selflink", ) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 377 | |
| 378 | def selflink(self, obj): |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 379 | if hasattr(self, "selflink_fieldname"): |
| 380 | obj = getattr(obj, self.selflink_fieldname) |
| 381 | |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 382 | if obj.id: |
Scott Baker | d5df950 | 2015-07-24 09:32:14 -0700 | [diff] [blame] | 383 | url = self.get_change_url(obj.id) |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 384 | return "<a href='%s'>Details</a>" % str(url) |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 385 | else: |
| 386 | return "Not present" |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 387 | |
| 388 | selflink.allow_tags = True |
| 389 | selflink.short_description = "Details" |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 390 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 391 | def has_add_permission(self, request): |
| 392 | return not request.user.isReadOnlyUser() |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 393 | |
| 394 | def get_readonly_fields(self, request, obj=None): |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 395 | readonly_fields = list(self.readonly_fields)[:] |
| 396 | if request.user.isReadOnlyUser(): |
| 397 | for field in self.fields: |
| 398 | if not field in readonly_fields: |
| 399 | readonly_fields.append(field) |
| 400 | return readonly_fields |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 401 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 402 | def backend_status_icon(self, obj): |
| 403 | return mark_safe(backend_icon(obj)) |
| 404 | backend_status_icon.short_description = "" |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 405 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 406 | class PlStackGenericTabularInline(generic.GenericTabularInline): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 407 | def has_add_permission(self, request): |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 408 | return not request.user.isReadOnlyUser() |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 409 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 410 | def get_readonly_fields(self, request, obj=None): |
| 411 | readonly_fields = list(self.readonly_fields)[:] |
| 412 | if request.user.isReadOnlyUser(): |
| 413 | for field in self.fields: |
| 414 | if not field in readonly_fields: |
| 415 | readonly_fields.append(field) |
| 416 | return readonly_fields |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 417 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 418 | def backend_status_icon(self, obj): |
| 419 | return mark_safe(backend_icon(obj)) |
| 420 | backend_status_icon.short_description = "" |
| 421 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 422 | class ReservationInline(XOSTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 423 | model = Reservation |
| 424 | extra = 0 |
| 425 | suit_classes = 'suit-tab suit-tab-reservations' |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 426 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 427 | def queryset(self, request): |
| 428 | return Reservation.select_by_user(request.user) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 429 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 430 | class TagInline(PlStackGenericTabularInline): |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 431 | model = Tag |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 432 | extra = 0 |
| 433 | suit_classes = 'suit-tab suit-tab-tags' |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 434 | fields = ['service', 'name', 'value'] |
| 435 | |
| 436 | def queryset(self, request): |
| 437 | return Tag.select_by_user(request.user) |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 438 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 439 | class InstanceInline(XOSTabularInline): |
| 440 | model = Instance |
Scott Baker | 4103eb3 | 2015-09-21 14:52:15 -0700 | [diff] [blame] | 441 | fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 442 | extra = 0 |
Scott Baker | 4103eb3 | 2015-09-21 14:52:15 -0700 | [diff] [blame] | 443 | max_num = 0 |
Scott Baker | 0befcd7 | 2015-09-21 15:10:18 -0700 | [diff] [blame] | 444 | readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node'] |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 445 | suit_classes = 'suit-tab suit-tab-instances' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 446 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 447 | def queryset(self, request): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 448 | return Instance.select_by_user(request.user) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 449 | |
Scott Baker | b24cc93 | 2014-06-09 10:51:16 -0700 | [diff] [blame] | 450 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 451 | if db_field.name == 'deployment': |
Tony Mack | bd908ae | 2015-02-24 15:41:49 -0500 | [diff] [blame] | 452 | kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct() |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 453 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"}) |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 454 | if db_field.name == 'flavor': |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 455 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"}) |
Scott Baker | 3b67874 | 2014-06-09 13:11:54 -0700 | [diff] [blame] | 456 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 457 | field = super(InstanceInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Scott Baker | b24cc93 | 2014-06-09 10:51:16 -0700 | [diff] [blame] | 458 | |
| 459 | return field |
| 460 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 461 | class CordInstanceInline(XOSTabularInline): |
| 462 | model = Instance |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 463 | fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'flavor', 'image', 'node'] |
| 464 | extra = 0 |
| 465 | readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name'] |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 466 | suit_classes = 'suit-tab suit-tab-instances' |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 467 | |
| 468 | def queryset(self, request): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 469 | return Instance.select_by_user(request.user) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 470 | |
| 471 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
| 472 | if db_field.name == 'deployment': |
| 473 | |
| 474 | kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct() |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 475 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"}) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 476 | if db_field.name == 'flavor': |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 477 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"}) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 478 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 479 | field = super(CordInstanceInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 480 | |
| 481 | return field |
| 482 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 483 | class SiteInline(XOSTabularInline): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 484 | model = Site |
| 485 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 486 | suit_classes = 'suit-tab suit-tab-sites' |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 487 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 488 | def queryset(self, request): |
| 489 | return Site.select_by_user(request.user) |
| 490 | |
Tony Mack | 15136b5 | 2015-08-04 17:53:23 -0400 | [diff] [blame] | 491 | class SiteHostsNodesInline(SiteInline): |
| 492 | def queryset(self, request): |
| 493 | return Site.select_by_user(request.user).filter(hosts_nodes=True) |
| 494 | |
| 495 | class SiteHostsUsersInline(SiteInline): |
| 496 | def queryset(self, request): |
| 497 | return Site.select_by_user(request.user).filter(hosts_users=True) |
| 498 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 499 | class UserInline(XOSTabularInline): |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 500 | model = User |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 501 | fields = ['backend_status_icon', 'email', 'firstname', 'lastname'] |
| 502 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 503 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 504 | suit_classes = 'suit-tab suit-tab-users' |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 505 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 506 | def queryset(self, request): |
| 507 | return User.select_by_user(request.user) |
| 508 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 509 | class SliceInline(XOSTabularInline): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 510 | model = Slice |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 511 | fields = ['backend_status_icon', 'name', 'site', 'serviceClass', 'service'] |
| 512 | readonly_fields = ('backend_status_icon', ) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 513 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 514 | suit_classes = 'suit-tab suit-tab-slices' |
| 515 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 516 | def queryset(self, request): |
| 517 | return Slice.select_by_user(request.user) |
| 518 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 519 | class NodeInline(XOSTabularInline): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 520 | model = Node |
| 521 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 522 | suit_classes = 'suit-tab suit-tab-nodes' |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 523 | fields = ['backend_status_icon', 'name', 'site_deployment'] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 524 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 525 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 526 | class DeploymentPrivilegeInline(XOSTabularInline): |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 527 | model = DeploymentPrivilege |
| 528 | extra = 0 |
Tony Mack | 4ce14c4 | 2015-02-09 21:41:57 -0500 | [diff] [blame] | 529 | suit_classes = 'suit-tab suit-tab-deploymentprivileges' |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 530 | fields = ['backend_status_icon', 'user','role','deployment'] |
| 531 | readonly_fields = ('backend_status_icon', ) |
| 532 | |
| 533 | def queryset(self, request): |
| 534 | return DeploymentPrivilege.select_by_user(request.user) |
| 535 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 536 | class ControllerSiteInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 537 | model = ControllerSite |
| 538 | extra = 0 |
| 539 | suit_classes = 'suit-tab suit-tab-admin-only' |
Tony Mack | 8f30ebe | 2015-01-06 15:08:20 -0500 | [diff] [blame] | 540 | fields = ['controller', 'site', 'tenant_id'] |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 541 | |
| 542 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 543 | class SitePrivilegeInline(XOSTabularInline): |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 544 | model = SitePrivilege |
| 545 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 546 | suit_classes = 'suit-tab suit-tab-siteprivileges' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 547 | fields = ['backend_status_icon', 'user','site', 'role'] |
| 548 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 549 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 550 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 551 | if db_field.name == 'site': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 552 | kwargs['queryset'] = Site.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 553 | |
| 554 | if db_field.name == 'user': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 555 | kwargs['queryset'] = User.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 556 | return super(SitePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 557 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 558 | def queryset(self, request): |
| 559 | return SitePrivilege.select_by_user(request.user) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 560 | |
Tony Mack | 8d108e2 | 2015-05-11 20:39:32 -0400 | [diff] [blame] | 561 | |
| 562 | class ServicePrivilegeInline(XOSTabularInline): |
| 563 | model = ServicePrivilege |
| 564 | extra = 0 |
| 565 | suit_classes = 'suit-tab suit-tab-serviceprivileges' |
| 566 | fields = ['backend_status_icon', 'user','service', 'role'] |
| 567 | readonly_fields = ('backend_status_icon', ) |
| 568 | |
| 569 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 570 | if db_field.name == 'service': |
| 571 | kwargs['queryset'] = Service.select_by_user(request.user) |
Tony Mack | cf88f8c | 2015-05-15 06:33:45 -0400 | [diff] [blame] | 572 | if db_field.name == 'user': |
| 573 | kwargs['queryset'] = User.select_by_user(request.user) |
| 574 | return super(ServicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | 8d108e2 | 2015-05-11 20:39:32 -0400 | [diff] [blame] | 575 | |
| 576 | def queryset(self, request): |
| 577 | return ServicePrivilege.select_by_user(request.user) |
| 578 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 579 | class SiteDeploymentInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 580 | model = SiteDeployment |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 581 | extra = 0 |
Tony Mack | 1081225 | 2015-01-30 10:58:29 -0500 | [diff] [blame] | 582 | suit_classes = 'suit-tab suit-tab-sitedeployments' |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 583 | fields = ['backend_status_icon', 'deployment','site', 'controller'] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 584 | readonly_fields = ('backend_status_icon', ) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 585 | |
| 586 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 587 | if db_field.name == 'site': |
| 588 | kwargs['queryset'] = Site.select_by_user(request.user) |
| 589 | |
| 590 | if db_field.name == 'deployment': |
| 591 | kwargs['queryset'] = Deployment.select_by_user(request.user) |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 592 | |
| 593 | if db_field.name == 'controller': |
Scott Baker | 4103eb3 | 2015-09-21 14:52:15 -0700 | [diff] [blame] | 594 | if len(resolve(request.path).args) > 0: |
| 595 | kwargs['queryset'] = Controller.select_by_user(request.user).filter(deployment__id=int(resolve(request.path).args[0])) |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 596 | |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 597 | return super(SiteDeploymentInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 598 | |
| 599 | def queryset(self, request): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 600 | return SiteDeployment.select_by_user(request.user) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 601 | |
| 602 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 603 | class SlicePrivilegeInline(XOSTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 604 | model = SlicePrivilege |
| 605 | suit_classes = 'suit-tab suit-tab-sliceprivileges' |
| 606 | extra = 0 |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 607 | fields = ('backend_status_icon', 'user', 'slice', 'role') |
| 608 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 609 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 610 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 611 | if db_field.name == 'slice': |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 612 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 613 | if db_field.name == 'user': |
Scott Baker | 521abcc | 2015-07-16 12:40:07 -0700 | [diff] [blame] | 614 | # all users are available to be granted SlicePrivilege |
| 615 | kwargs['queryset'] = User.objects.all() |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 616 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 617 | return super(SlicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 618 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 619 | def queryset(self, request): |
| 620 | return SlicePrivilege.select_by_user(request.user) |
| 621 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 622 | class SliceNetworkInline(XOSTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 623 | model = Network.slices.through |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 624 | selflink_fieldname = "network" |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 625 | extra = 0 |
| 626 | verbose_name = "Network Connection" |
| 627 | verbose_name_plural = "Network Connections" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 628 | suit_classes = 'suit-tab suit-tab-slicenetworks' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 629 | fields = ['backend_status_icon', 'network'] |
| 630 | readonly_fields = ('backend_status_icon', ) |
Scott Baker | 2170b97 | 2014-06-03 12:14:07 -0700 | [diff] [blame] | 631 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 632 | class ImageDeploymentsInline(XOSTabularInline): |
Sapan Bhatia | e9f96f6 | 2014-11-19 15:10:16 -0500 | [diff] [blame] | 633 | model = ImageDeployments |
Scott Baker | 2170b97 | 2014-06-03 12:14:07 -0700 | [diff] [blame] | 634 | extra = 0 |
| 635 | verbose_name = "Image Deployments" |
| 636 | verbose_name_plural = "Image Deployments" |
| 637 | suit_classes = 'suit-tab suit-tab-imagedeployments' |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 638 | fields = ['backend_status_icon', 'image', 'deployment'] |
| 639 | readonly_fields = ['backend_status_icon'] |
| 640 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 641 | class ControllerImagesInline(XOSTabularInline): |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 642 | model = ControllerImages |
| 643 | extra = 0 |
| 644 | verbose_name = "Controller Images" |
| 645 | verbose_name_plural = "Controller Images" |
| 646 | suit_classes = 'suit-tab suit-tab-admin-only' |
| 647 | fields = ['backend_status_icon', 'image', 'controller', 'glance_image_id'] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 648 | readonly_fields = ['backend_status_icon', 'glance_image_id'] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 649 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 650 | class SliceRoleAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 651 | model = SliceRole |
| 652 | pass |
| 653 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 654 | class SiteRoleAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 655 | model = SiteRole |
| 656 | pass |
| 657 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 658 | class DeploymentAdminForm(forms.ModelForm): |
Scott Baker | de0f441 | 2014-06-11 15:40:26 -0700 | [diff] [blame] | 659 | images = forms.ModelMultipleChoiceField( |
| 660 | queryset=Image.objects.all(), |
| 661 | required=False, |
| 662 | help_text="Select which images should be deployed on this deployment", |
| 663 | widget=FilteredSelectMultiple( |
| 664 | verbose_name=('Images'), is_stacked=False |
| 665 | ) |
| 666 | ) |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 667 | flavors = forms.ModelMultipleChoiceField( |
| 668 | queryset=Flavor.objects.all(), |
| 669 | required=False, |
| 670 | help_text="Select which flavors should be usable on this deployment", |
| 671 | widget=FilteredSelectMultiple( |
| 672 | verbose_name=('Flavors'), is_stacked=False |
| 673 | ) |
| 674 | ) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 675 | class Meta: |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 676 | model = Deployment |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 677 | many_to_many = ["flavors",] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 678 | |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 679 | def __init__(self, *args, **kwargs): |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 680 | request = kwargs.pop('request', None) |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 681 | super(DeploymentAdminForm, self).__init__(*args, **kwargs) |
| 682 | |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 683 | self.fields['accessControl'].initial = "allow site " + request.user.site.name |
| 684 | |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 685 | if self.instance and self.instance.pk: |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 686 | self.fields['images'].initial = [x.image for x in self.instance.imagedeployments.all()] |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 687 | self.fields['flavors'].initial = self.instance.flavors.all() |
Scott Baker | de0f441 | 2014-06-11 15:40:26 -0700 | [diff] [blame] | 688 | |
| 689 | def manipulate_m2m_objs(self, this_obj, selected_objs, all_relations, relation_class, local_attrname, foreign_attrname): |
| 690 | """ helper function for handling m2m relations from the MultipleChoiceField |
| 691 | |
| 692 | this_obj: the source object we want to link from |
| 693 | |
| 694 | selected_objs: a list of destination objects we want to link to |
| 695 | |
| 696 | all_relations: the full set of relations involving this_obj, including ones we don't want |
| 697 | |
| 698 | relation_class: the class that implements the relation from source to dest |
| 699 | |
| 700 | local_attrname: field name representing this_obj in relation_class |
| 701 | |
| 702 | foreign_attrname: field name representing selected_objs in relation_class |
| 703 | |
| 704 | This function will remove all newobjclass relations from this_obj |
| 705 | that are not contained in selected_objs, and add any relations that |
| 706 | are in selected_objs but don't exist in the data model yet. |
| 707 | """ |
| 708 | |
| 709 | existing_dest_objs = [] |
| 710 | for relation in list(all_relations): |
| 711 | if getattr(relation, foreign_attrname) not in selected_objs: |
| 712 | #print "deleting site", sdp.site |
| 713 | relation.delete() |
| 714 | else: |
| 715 | existing_dest_objs.append(getattr(relation, foreign_attrname)) |
| 716 | |
| 717 | for dest_obj in selected_objs: |
| 718 | if dest_obj not in existing_dest_objs: |
| 719 | #print "adding site", site |
| 720 | kwargs = {foreign_attrname: dest_obj, local_attrname: this_obj} |
| 721 | relation = relation_class(**kwargs) |
| 722 | relation.save() |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 723 | |
| 724 | def save(self, commit=True): |
| 725 | deployment = super(DeploymentAdminForm, self).save(commit=False) |
| 726 | |
| 727 | if commit: |
| 728 | deployment.save() |
Scott Baker | 61b6aec | 2014-10-06 17:17:40 -0700 | [diff] [blame] | 729 | # this has to be done after save() if/when a deployment is first created |
| 730 | deployment.flavors = self.cleaned_data['flavors'] |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 731 | |
| 732 | if deployment.pk: |
Scott Baker | c9b14f7 | 2014-05-22 13:44:20 -0700 | [diff] [blame] | 733 | # save_m2m() doesn't seem to work with 'through' relations. So we |
| 734 | # create/destroy the through models ourselves. There has to be |
| 735 | # a better way... |
| 736 | |
Tony Mack | 592aa95 | 2014-12-15 11:45:02 -0500 | [diff] [blame] | 737 | self.manipulate_m2m_objs(deployment, self.cleaned_data['images'], deployment.imagedeployments.all(), ImageDeployments, "deployment", "image") |
| 738 | # manipulate_m2m_objs doesn't work for Flavor/Deployment relationship |
| 739 | # so well handle that manually here |
| 740 | for flavor in deployment.flavors.all(): |
| 741 | if getattr(flavor, 'name') not in self.cleaned_data['flavors']: |
Tony Mack | 11f4d20 | 2014-12-15 12:37:59 -0500 | [diff] [blame] | 742 | deployment.flavors.remove(flavor) |
Tony Mack | 592aa95 | 2014-12-15 11:45:02 -0500 | [diff] [blame] | 743 | for flavor in self.cleaned_data['flavors']: |
| 744 | if flavor not in deployment.flavors.all(): |
| 745 | flavor.deployments.add(deployment) |
Scott Baker | c9b14f7 | 2014-05-22 13:44:20 -0700 | [diff] [blame] | 746 | |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 747 | self.save_m2m() |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 748 | |
| 749 | return deployment |
| 750 | |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 751 | class DeploymentAdminROForm(DeploymentAdminForm): |
| 752 | def save(self, commit=True): |
| 753 | raise PermissionDenied |
| 754 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 755 | class SiteAssocInline(XOSTabularInline): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 756 | model = Site.deployments.through |
| 757 | extra = 0 |
| 758 | suit_classes = 'suit-tab suit-tab-sites' |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 759 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 760 | class DeploymentAdmin(XOSBaseAdmin): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 761 | model = Deployment |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 762 | fieldList = ['backend_status_text', 'name', 'images', 'flavors', 'accessControl'] |
| 763 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 764 | # node no longer directly connected to deployment |
| 765 | #inlines = [DeploymentPrivilegeInline,NodeInline,TagInline,ImageDeploymentsInline] |
Tony Mack | 1081225 | 2015-01-30 10:58:29 -0500 | [diff] [blame] | 766 | inlines = [DeploymentPrivilegeInline,TagInline,ImageDeploymentsInline,SiteDeploymentInline] |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 767 | list_display = ['backend_status_icon', 'name'] |
| 768 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 769 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 770 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 771 | user_readonly_fields = ['name'] |
| 772 | |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 773 | # nodes no longer direclty connected to deployments |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 774 | suit_form_tabs =(('general','Deployment Details'),('deploymentprivileges','Privileges'), ('sitedeployments', 'Sites')) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 775 | |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 776 | def get_form(self, request, obj=None, **kwargs): |
Tony Mack | d893dfb | 2015-02-05 06:13:04 -0500 | [diff] [blame] | 777 | if request.user.isReadOnlyUser() or not request.user.is_admin: |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 778 | kwargs["form"] = DeploymentAdminROForm |
| 779 | else: |
| 780 | kwargs["form"] = DeploymentAdminForm |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 781 | adminForm = super(DeploymentAdmin,self).get_form(request, obj, **kwargs) |
| 782 | |
| 783 | # from stackexchange: pass the request object into the form |
| 784 | |
| 785 | class AdminFormMetaClass(adminForm): |
| 786 | def __new__(cls, *args, **kwargs): |
| 787 | kwargs['request'] = request |
| 788 | return adminForm(*args, **kwargs) |
| 789 | |
| 790 | return AdminFormMetaClass |
| 791 | |
Scott Baker | e497b3c | 2016-01-29 12:18:19 -0800 | [diff] [blame] | 792 | class ControllerAdminForm(forms.ModelForm): |
| 793 | backend_disabled = forms.BooleanField(required=False) |
| 794 | class Meta: |
| 795 | model = Controller |
| 796 | |
| 797 | def __init__(self, *args, **kwargs): |
| 798 | request = kwargs.pop('request', None) |
| 799 | super(ControllerAdminForm, self).__init__(*args, **kwargs) |
| 800 | |
| 801 | if self.instance and self.instance.pk: |
| 802 | self.fields['backend_disabled'].initial = self.instance.get_backend_register('disabled', False) |
| 803 | else: |
| 804 | # defaults when adding new controller |
| 805 | self.fields['backend_disabled'].initial = False |
| 806 | |
| 807 | def save(self, commit=True): |
| 808 | self.instance.set_backend_register("disabled", self.cleaned_data["backend_disabled"]) |
| 809 | return super(ControllerAdminForm, self).save(commit=commit) |
| 810 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 811 | class ControllerAdmin(XOSBaseAdmin): |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 812 | model = Controller |
Scott Baker | e497b3c | 2016-01-29 12:18:19 -0800 | [diff] [blame] | 813 | fieldList = ['deployment', 'name', 'backend_type', 'backend_disabled', 'version', 'auth_url', 'admin_user', 'admin_tenant','admin_password', 'domain', 'rabbit_host', 'rabbit_user', 'rabbit_password'] |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 814 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 815 | inlines = [ControllerSiteInline] # ,ControllerImagesInline] |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 816 | list_display = ['backend_status_icon', 'name', 'version', 'backend_type'] |
| 817 | list_display_links = ('backend_status_icon', 'name', ) |
| 818 | readonly_fields = ('backend_status_text',) |
Scott Baker | e497b3c | 2016-01-29 12:18:19 -0800 | [diff] [blame] | 819 | form = ControllerAdminForm |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 820 | |
| 821 | user_readonly_fields = [] |
| 822 | |
Tony Mack | c36cafb | 2015-01-13 17:33:08 -0500 | [diff] [blame] | 823 | def save_model(self, request, obj, form, change): |
| 824 | # update openstack connection to use this site/tenant |
| 825 | obj.save_by_user(request.user) |
| 826 | |
| 827 | def delete_model(self, request, obj): |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 828 | obj.delete_by_user(request.user) |
| 829 | |
Tony Mack | 79e2e66 | 2015-02-18 11:41:36 -0500 | [diff] [blame] | 830 | def queryset(self, request): |
| 831 | return Controller.select_by_user(request.user) |
| 832 | |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 833 | @property |
| 834 | def suit_form_tabs(self): |
| 835 | tabs = [('general', 'Controller Details'), |
| 836 | ] |
| 837 | |
| 838 | request=getattr(_thread_locals, "request", None) |
| 839 | if request and request.user.is_admin: |
| 840 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 841 | |
| 842 | return tabs |
Tony Mack | c36cafb | 2015-01-13 17:33:08 -0500 | [diff] [blame] | 843 | |
Scott Baker | 462a1d9 | 2015-10-15 15:59:19 -0700 | [diff] [blame] | 844 | class TenantAttributeAdmin(XOSBaseAdmin): |
| 845 | model = TenantAttribute |
| 846 | list_display = ('backend_status_icon', 'tenant', 'name', 'value') |
| 847 | list_display_links = ('backend_status_icon', 'name') |
| 848 | fieldList = ('backend_status_text', 'tenant', 'name', 'value', ) |
| 849 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
| 850 | readonly_fields = ('backend_status_text', ) |
| 851 | |
| 852 | suit_form_tabs =(('general', 'Tenant Root Details'), |
| 853 | ) |
| 854 | |
| 855 | class TenantAttrAsTabInline(XOSTabularInline): |
| 856 | model = TenantAttribute |
| 857 | fields = ['name','value'] |
| 858 | extra = 0 |
| 859 | suit_classes = 'suit-tab suit-tab-tenantattrs' |
| 860 | |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 861 | class TenantRootRoleAdmin(XOSBaseAdmin): |
| 862 | model = TenantRootRole |
| 863 | fields = ('role',) |
| 864 | |
| 865 | class TenantRootTenantInline(XOSTabularInline): |
| 866 | model = Tenant |
| 867 | fields = ['provider_service', 'subscriber_root'] |
| 868 | extra = 0 |
| 869 | suit_classes = 'suit-tab suit-tab-tenantroots' |
| 870 | fk_name = 'subscriber_root' |
| 871 | verbose_name = 'subscribed tenant' |
| 872 | verbose_name_plural = 'subscribed tenants' |
| 873 | |
| 874 | #def queryset(self, request): |
| 875 | # qs = super(TenantRootTenantInline, self).queryset(request) |
| 876 | # return qs.filter(kind="coarse") |
| 877 | |
| 878 | class TenantRootPrivilegeInline(XOSTabularInline): |
| 879 | model = TenantRootPrivilege |
| 880 | extra = 0 |
| 881 | suit_classes = 'suit-tab suit-tab-tenantrootprivileges' |
| 882 | fields = ['backend_status_icon', 'user', 'role', 'tenant_root'] |
| 883 | readonly_fields = ('backend_status_icon', ) |
| 884 | |
| 885 | def queryset(self, request): |
| 886 | return TenantRootPrivilege.select_by_user(request.user) |
| 887 | |
| 888 | class TenantRootAdmin(XOSBaseAdmin): |
| 889 | model = TenantRoot |
| 890 | list_display = ('backend_status_icon', 'name', 'kind') |
| 891 | list_display_links = ('backend_status_icon', 'name') |
| 892 | fieldList = ('backend_status_text', 'name', 'kind', ) |
| 893 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
| 894 | inlines = (TenantRootTenantInline, TenantRootPrivilegeInline) |
| 895 | readonly_fields = ('backend_status_text', ) |
| 896 | |
| 897 | suit_form_tabs =(('general', 'Tenant Root Details'), |
| 898 | ('tenantroots','Tenancy'), |
| 899 | ('tenantrootprivileges','Privileges') |
| 900 | ) |
| 901 | |
Scott Baker | 925a8fa | 2015-04-26 20:30:40 -0700 | [diff] [blame] | 902 | class ProviderTenantInline(XOSTabularInline): |
| 903 | model = CoarseTenant |
| 904 | fields = ['provider_service', 'subscriber_service', 'connect_method'] |
| 905 | extra = 0 |
| 906 | suit_classes = 'suit-tab suit-tab-servicetenants' |
| 907 | fk_name = 'provider_service' |
| 908 | verbose_name = 'provided tenant' |
| 909 | verbose_name_plural = 'provided tenants' |
| 910 | |
| 911 | def queryset(self, request): |
| 912 | qs = super(ProviderTenantInline, self).queryset(request) |
| 913 | return qs.filter(kind="coarse") |
| 914 | |
| 915 | class SubscriberTenantInline(XOSTabularInline): |
| 916 | model = CoarseTenant |
| 917 | fields = ['provider_service', 'subscriber_service', 'connect_method'] |
| 918 | extra = 0 |
| 919 | suit_classes = 'suit-tab suit-tab-servicetenants' |
| 920 | fk_name = 'subscriber_service' |
| 921 | verbose_name = 'subscribed tenant' |
| 922 | verbose_name_plural = 'subscribed tenants' |
| 923 | |
| 924 | def queryset(self, request): |
| 925 | qs = super(SubscriberTenantInline, self).queryset(request) |
| 926 | return qs.filter(kind="coarse") |
| 927 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 928 | class ServiceAttrAsTabInline(XOSTabularInline): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 929 | model = ServiceAttribute |
| 930 | fields = ['name','value'] |
| 931 | extra = 0 |
| 932 | suit_classes = 'suit-tab suit-tab-serviceattrs' |
| 933 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 934 | class ServiceAdmin(XOSBaseAdmin): |
Scott Baker | 008a996 | 2015-04-15 20:58:20 -0700 | [diff] [blame] | 935 | list_display = ("backend_status_icon","name","kind","versionNumber","enabled","published") |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 936 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | f60c010 | 2015-11-12 16:22:52 -0800 | [diff] [blame] | 937 | fieldList = ["backend_status_text","name","kind","description","versionNumber","enabled","published","view_url","icon_url","public_key","private_key_fn","service_specific_attribute","service_specific_id"] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 938 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
Tony Mack | 8d108e2 | 2015-05-11 20:39:32 -0400 | [diff] [blame] | 939 | inlines = [ServiceAttrAsTabInline,SliceInline,ProviderTenantInline,SubscriberTenantInline,ServicePrivilegeInline] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 940 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 941 | |
| 942 | user_readonly_fields = fieldList |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 943 | |
| 944 | suit_form_tabs =(('general', 'Service Details'), |
| 945 | ('slices','Slices'), |
| 946 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 925a8fa | 2015-04-26 20:30:40 -0700 | [diff] [blame] | 947 | ('servicetenants','Tenancy'), |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 948 | ('serviceprivileges','Privileges') |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 949 | ) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 950 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 951 | class SiteNodeInline(XOSTabularInline): |
Tony Mack | 82df1d0 | 2015-01-14 20:58:38 -0500 | [diff] [blame] | 952 | model = Node |
| 953 | fields = ['name', 'site_deployment'] |
| 954 | extra = 0 |
| 955 | suit_classes = 'suit-tab suit-tab-nodes' |
| 956 | |
Tony Mack | 26b5953 | 2015-02-25 11:39:34 -0500 | [diff] [blame] | 957 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 958 | # only display site deployments associated with this site |
| 959 | if db_field.name == 'site_deployment': |
| 960 | kwargs['queryset'] = SiteDeployment.objects.filter(site__id=int(request.path.split('/')[-2])) |
| 961 | |
| 962 | return super(SiteNodeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 963 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 964 | class SiteAdmin(XOSBaseAdmin): |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 965 | #fieldList = ['backend_status_text', 'name', 'site_url', 'enabled', 'is_public', 'login_base', 'accountLink','location'] |
Tony Mack | 2862dca | 2015-08-04 17:21:55 -0400 | [diff] [blame] | 966 | fieldList = ['backend_status_text', 'name', 'site_url', 'enabled', 'login_base', 'location', 'is_public', 'hosts_nodes', 'hosts_users'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 967 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 968 | (None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}), |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 969 | #('Deployment Networks', {'fields': ['deployments'], 'classes':['suit-tab suit-tab-deployments']}), |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 970 | ] |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 971 | #readonly_fields = ['backend_status_text', 'accountLink'] |
| 972 | readonly_fields = ['backend_status_text'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 973 | |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 974 | #user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'accountLink'] |
Tony Mack | 2862dca | 2015-08-04 17:21:55 -0400 | [diff] [blame] | 975 | user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'hosts_nodes', 'hosts_users'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 976 | |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 977 | list_display = ('backend_status_icon', 'name', 'login_base','site_url', 'enabled') |
| 978 | list_display_links = ('backend_status_icon', 'name', ) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 979 | filter_horizontal = ('deployments',) |
Tony Mack | 1081225 | 2015-01-30 10:58:29 -0500 | [diff] [blame] | 980 | inlines = [SliceInline,UserInline,TagInline, SitePrivilegeInline, SiteNodeInline] |
Tony Mack | 10328a1 | 2015-01-14 12:11:05 -0500 | [diff] [blame] | 981 | admin_inlines = [ControllerSiteInline] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 982 | search_fields = ['name'] |
| 983 | |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 984 | @property |
| 985 | def suit_form_tabs(self): |
| 986 | tabs = [('general', 'Site Details'), |
| 987 | ('users','Users'), |
| 988 | ('siteprivileges','Privileges'), |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 989 | ('slices','Slices'), |
Tony Mack | 82df1d0 | 2015-01-14 20:58:38 -0500 | [diff] [blame] | 990 | ('nodes','Nodes'), |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 991 | ] |
| 992 | |
| 993 | request=getattr(_thread_locals, "request", None) |
| 994 | if request and request.user.is_admin: |
| 995 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 996 | |
| 997 | return tabs |
| 998 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 999 | def queryset(self, request): |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1000 | return Site.select_by_user(request.user) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1001 | |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame] | 1002 | def get_formsets(self, request, obj=None): |
| 1003 | for inline in self.get_inline_instances(request, obj): |
| 1004 | # hide MyInline in the add view |
| 1005 | if obj is None: |
| 1006 | continue |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1007 | if isinstance(inline, InstanceInline): |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 1008 | inline.model.caller = request.user |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame] | 1009 | yield inline.get_formset(request, obj) |
| 1010 | |
Scott Baker | 545db2a | 2013-12-09 18:44:43 -0800 | [diff] [blame] | 1011 | def accountLink(self, obj): |
| 1012 | link_obj = obj.accounts.all() |
| 1013 | if link_obj: |
| 1014 | reverse_path = "admin:core_account_change" |
| 1015 | url = reverse(reverse_path, args =(link_obj[0].id,)) |
| 1016 | return "<a href='%s'>%s</a>" % (url, "view billing details") |
| 1017 | else: |
| 1018 | return "no billing data for this site" |
| 1019 | accountLink.allow_tags = True |
| 1020 | accountLink.short_description = "Billing" |
| 1021 | |
Tony Mack | 332ee1d | 2014-02-04 15:33:45 -0500 | [diff] [blame] | 1022 | def save_model(self, request, obj, form, change): |
| 1023 | # update openstack connection to use this site/tenant |
| 1024 | obj.save_by_user(request.user) |
| 1025 | |
| 1026 | def delete_model(self, request, obj): |
| 1027 | obj.delete_by_user(request.user) |
| 1028 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1029 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1030 | class SitePrivilegeAdmin(XOSBaseAdmin): |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1031 | fieldList = ['backend_status_text', 'user', 'site', 'role'] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1032 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1033 | (None, {'fields': fieldList, 'classes':['collapse']}) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1034 | ] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1035 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1036 | list_display = ('backend_status_icon', 'user', 'site', 'role') |
| 1037 | list_display_links = list_display |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1038 | user_readonly_fields = fieldList |
| 1039 | user_readonly_inlines = [] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1040 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1041 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1042 | if db_field.name == 'site': |
| 1043 | if not request.user.is_admin: |
| 1044 | # only show sites where user is an admin or pi |
| 1045 | sites = set() |
| 1046 | for site_privilege in SitePrivilege.objects.filer(user=request.user): |
| 1047 | if site_privilege.role.role_type in ['admin', 'pi']: |
| 1048 | sites.add(site_privilege.site) |
| 1049 | kwargs['queryset'] = Site.objects.filter(site__in=list(sites)) |
| 1050 | |
| 1051 | if db_field.name == 'user': |
| 1052 | if not request.user.is_admin: |
| 1053 | # only show users from sites where caller has admin or pi role |
| 1054 | roles = Role.objects.filter(role_type__in=['admin', 'pi']) |
| 1055 | site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles) |
| 1056 | sites = [site_privilege.site for site_privilege in site_privileges] |
| 1057 | site_privileges = SitePrivilege.objects.filter(site__in=sites) |
| 1058 | emails = [site_privilege.user.email for site_privilege in site_privileges] |
| 1059 | users = User.objects.filter(email__in=emails) |
| 1060 | kwargs['queryset'] = users |
| 1061 | |
| 1062 | return super(SitePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1063 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1064 | def queryset(self, request): |
| 1065 | # admins can see all privileges. Users can only see privileges at sites |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1066 | # where they have the admin role or pi role. |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1067 | qs = super(SitePrivilegeAdmin, self).queryset(request) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1068 | #if not request.user.is_admin: |
| 1069 | # roles = Role.objects.filter(role_type__in=['admin', 'pi']) |
| 1070 | # site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles) |
| 1071 | # login_bases = [site_privilege.site.login_base for site_privilege in site_privileges] |
| 1072 | # sites = Site.objects.filter(login_base__in=login_bases) |
| 1073 | # qs = qs.filter(site__in=sites) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1074 | return qs |
| 1075 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1076 | class SliceForm(forms.ModelForm): |
| 1077 | class Meta: |
| 1078 | model = Slice |
| 1079 | widgets = { |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 1080 | 'service': LinkedSelect |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1081 | } |
| 1082 | |
Tony Mack | 2cbd380 | 2014-09-29 16:10:52 -0400 | [diff] [blame] | 1083 | def clean(self): |
| 1084 | cleaned_data = super(SliceForm, self).clean() |
| 1085 | name = cleaned_data.get('name') |
Scott Baker | 6efad46 | 2014-10-06 23:09:59 -0700 | [diff] [blame] | 1086 | site = cleaned_data.get('site') |
Tony Mack | 585cb19 | 2014-10-22 12:54:19 -0400 | [diff] [blame] | 1087 | slice_id = self.instance.id |
| 1088 | if not site and slice_id: |
| 1089 | site = Slice.objects.get(id=slice_id).site |
Scott Baker | 6efad46 | 2014-10-06 23:09:59 -0700 | [diff] [blame] | 1090 | if (not isinstance(site,Site)): |
| 1091 | # previous code indicates 'site' could be a site_id and not a site? |
| 1092 | site = Slice.objects.get(id=site.id) |
Tony Mack | 2cbd380 | 2014-09-29 16:10:52 -0400 | [diff] [blame] | 1093 | if not name.startswith(site.login_base): |
| 1094 | raise forms.ValidationError('slice name must begin with %s' % site.login_base) |
| 1095 | return cleaned_data |
| 1096 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1097 | class ControllerSliceInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1098 | model = ControllerSlice |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1099 | extra = 0 |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1100 | verbose_name = "Controller Slices" |
| 1101 | verbose_name_plural = "Controller Slices" |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1102 | suit_classes = 'suit-tab suit-tab-admin-only' |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1103 | fields = ['backend_status_icon', 'controller', 'tenant_id'] |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1104 | readonly_fields = ('backend_status_icon', 'controller' ) |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1105 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1106 | class SliceAdmin(XOSBaseAdmin): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1107 | form = SliceForm |
Scott Baker | de08853 | 2015-12-14 19:37:55 -0800 | [diff] [blame] | 1108 | fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_instances', "default_isolation", "network"] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1109 | fieldsets = [('Slice Details', {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1110 | readonly_fields = ('backend_status_text', ) |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1111 | list_display = ('backend_status_icon', 'name', 'site','serviceClass', 'slice_url', 'max_instances') |
Tony Mack | 7d45990 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 1112 | list_display_links = ('backend_status_icon', 'name', ) |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1113 | normal_inlines = [SlicePrivilegeInline, InstanceInline, TagInline, ReservationInline, SliceNetworkInline] |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1114 | inlines = normal_inlines |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1115 | admin_inlines = [ControllerSliceInline] |
Scott Baker | 591fb06 | 2015-09-15 15:21:50 -0700 | [diff] [blame] | 1116 | suit_form_includes = (('slice_instance_tab.html', 'bottom', 'instances'),) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1117 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1118 | user_readonly_fields = fieldList |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1119 | |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1120 | @property |
| 1121 | def suit_form_tabs(self): |
| 1122 | tabs =[('general', 'Slice Details'), |
| 1123 | ('slicenetworks','Networks'), |
| 1124 | ('sliceprivileges','Privileges'), |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1125 | ('instances','Instances'), |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 1126 | #('reservations','Reservations'), |
Tony Mack | b34553e | 2015-01-15 14:44:06 -0500 | [diff] [blame] | 1127 | ('tags','Tags'), |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1128 | ] |
| 1129 | |
| 1130 | request=getattr(_thread_locals, "request", None) |
| 1131 | if request and request.user.is_admin: |
| 1132 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 1133 | |
| 1134 | return tabs |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1135 | |
| 1136 | def add_view(self, request, form_url='', extra_context=None): |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1137 | # Ugly hack for CORD |
| 1138 | self.inlines = self.normal_inlines |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1139 | # revert to default read-only fields |
| 1140 | self.readonly_fields = ('backend_status_text',) |
| 1141 | return super(SliceAdmin, self).add_view(request, form_url, extra_context=extra_context) |
| 1142 | |
| 1143 | def change_view(self, request, object_id, form_url='', extra_context=None): |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1144 | # cannot change the site of an existing slice so make the site field read only |
| 1145 | if object_id: |
| 1146 | self.readonly_fields = ('backend_status_text','site') |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1147 | |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1148 | return super(SliceAdmin, self).change_view(request, object_id, form_url) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1149 | |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1150 | def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1151 | deployment_nodes = [] |
| 1152 | for node in Node.objects.all(): |
Scott Baker | 39293d7 | 2015-01-21 16:24:07 -0800 | [diff] [blame] | 1153 | deployment_nodes.append( (node.site_deployment.deployment.id, node.id, node.name) ) |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1154 | |
Scott Baker | 7a61dc4 | 2014-09-02 17:08:20 -0700 | [diff] [blame] | 1155 | deployment_flavors = [] |
| 1156 | for flavor in Flavor.objects.all(): |
| 1157 | for deployment in flavor.deployments.all(): |
| 1158 | deployment_flavors.append( (deployment.id, flavor.id, flavor.name) ) |
| 1159 | |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1160 | deployment_images = [] |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1161 | for image in Image.objects.all(): |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1162 | for deployment_image in image.imagedeployments.all(): |
Scott Baker | a6a0c77 | 2014-12-22 17:35:34 -0800 | [diff] [blame] | 1163 | deployment_images.append( (deployment_image.deployment.id, image.id, image.name) ) |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1164 | |
Tony Mack | ec23b99 | 2014-09-02 21:18:45 -0400 | [diff] [blame] | 1165 | site_login_bases = [] |
| 1166 | for site in Site.objects.all(): |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1167 | site_login_bases.append((site.id, site.login_base)) |
| 1168 | |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1169 | context["deployment_nodes"] = deployment_nodes |
Scott Baker | 7a61dc4 | 2014-09-02 17:08:20 -0700 | [diff] [blame] | 1170 | context["deployment_flavors"] = deployment_flavors |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1171 | context["deployment_images"] = deployment_images |
Tony Mack | ec23b99 | 2014-09-02 21:18:45 -0400 | [diff] [blame] | 1172 | context["site_login_bases"] = site_login_bases |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1173 | return super(SliceAdmin, self).render_change_form(request, context, add, change, form_url, obj) |
| 1174 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1175 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1176 | if db_field.name == 'site': |
Tony Mack | 15136b5 | 2015-08-04 17:53:23 -0400 | [diff] [blame] | 1177 | kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_users=True) |
Tony Mack | ec23b99 | 2014-09-02 21:18:45 -0400 | [diff] [blame] | 1178 | kwargs['widget'] = forms.Select(attrs={'onChange': "update_slice_prefix(this, $($(this).closest('fieldset')[0]).find('.field-name input')[0].id)"}) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1179 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1180 | return super(SliceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1181 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1182 | def queryset(self, request): |
| 1183 | # admins can see all keys. Users can only see slices they belong to. |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1184 | return Slice.select_by_user(request.user) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1185 | |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 1186 | def get_formsets(self, request, obj=None): |
| 1187 | for inline in self.get_inline_instances(request, obj): |
| 1188 | # hide MyInline in the add view |
| 1189 | if obj is None: |
| 1190 | continue |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1191 | if isinstance(inline, InstanceInline): |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 1192 | inline.model.caller = request.user |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 1193 | yield inline.get_formset(request, obj) |
| 1194 | |
Scott Baker | 03394b3 | 2015-09-15 17:48:57 -0700 | [diff] [blame] | 1195 | def add_extra_context(self, request, extra_context): |
| 1196 | super(SliceAdmin, self).add_extra_context(request, extra_context) |
| 1197 | # set context["slice_id"] to the PK passed in the URL to this view |
| 1198 | if len(request.resolver_match.args)>0: |
| 1199 | extra_context["slice_id"] = request.resolver_match.args[0] |
| 1200 | |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1201 | def UNUSED_get_inline_instances(self, request, obj=None): |
| 1202 | # HACK for CORD to do something special on vcpe slice page |
| 1203 | # this was a good idea, but failed miserably, as something still |
| 1204 | # expects there to be a deployment field. |
| 1205 | # XXX this approach is better than clobbering self.inlines, so |
| 1206 | # try to make this work post-demo. |
| 1207 | if (obj is not None) and (obj.name == "mysite_vcpe"): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1208 | cord_vcpe_inlines = [ SlicePrivilegeInline, CordInstanceInline, TagInline, ReservationInline,SliceNetworkInline] |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1209 | |
| 1210 | inlines=[] |
| 1211 | for inline_class in cord_vcpe_inlines: |
| 1212 | inlines.append(inline_class(self.model, self.admin_site)) |
| 1213 | else: |
| 1214 | inlines = super(SliceAdmin, self).get_inline_instances(request, obj) |
| 1215 | |
| 1216 | return inlines |
| 1217 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1218 | class SlicePrivilegeAdmin(XOSBaseAdmin): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1219 | fieldsets = [ |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1220 | (None, {'fields': ['backend_status_text', 'user', 'slice', 'role']}) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1221 | ] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1222 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1223 | list_display = ('backend_status_icon', 'user', 'slice', 'role') |
| 1224 | list_display_links = list_display |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1225 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1226 | user_readonly_fields = ['user', 'slice', 'role'] |
| 1227 | user_readonly_inlines = [] |
| 1228 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1229 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1230 | if db_field.name == 'slice': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1231 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1232 | |
| 1233 | if db_field.name == 'user': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1234 | kwargs['queryset'] = User.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1235 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1236 | return super(SlicePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1237 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1238 | def queryset(self, request): |
| 1239 | # admins can see all memberships. Users can only see memberships of |
| 1240 | # slices where they have the admin role. |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1241 | return SlicePrivilege.select_by_user(request.user) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1242 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 1243 | def save_model(self, request, obj, form, change): |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1244 | # update openstack connection to use this site/tenant |
| 1245 | auth = request.session.get('auth', {}) |
Tony Mack | f7f79a1 | 2014-08-11 11:21:42 -0400 | [diff] [blame] | 1246 | auth['tenant'] = obj.slice.slicename |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1247 | obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 1248 | obj.save() |
| 1249 | |
| 1250 | def delete_model(self, request, obj): |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1251 | # update openstack connection to use this site/tenant |
| 1252 | auth = request.session.get('auth', {}) |
Tony Mack | f7f79a1 | 2014-08-11 11:21:42 -0400 | [diff] [blame] | 1253 | auth['tenant'] = obj.slice.slicename |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1254 | obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 1255 | obj.delete() |
| 1256 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1257 | class ImageAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1258 | |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 1259 | fieldsets = [('Image Details', |
Scott Baker | 1426623 | 2015-12-14 10:11:56 -0800 | [diff] [blame] | 1260 | {'fields': ['backend_status_text', 'name', 'kind', 'disk_format', 'container_format', 'tag', 'path'], |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1261 | 'classes': ['suit-tab suit-tab-general']}) |
| 1262 | ] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1263 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1264 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1265 | suit_form_tabs =(('general','Image Details'),('instances','Instances'),('imagedeployments','Deployments'), ('controllerimages', 'Controllers')) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1266 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1267 | inlines = [InstanceInline, ControllerImagesInline] |
Scott Baker | b6f9924 | 2014-06-11 11:34:44 -0700 | [diff] [blame] | 1268 | |
Scott Baker | 1426623 | 2015-12-14 10:11:56 -0800 | [diff] [blame] | 1269 | user_readonly_fields = ['name', 'disk_format', 'container_format', 'tag', 'path'] |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 1270 | |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1271 | list_display = ['backend_status_icon', 'name', 'kind'] |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1272 | list_display_links = ('backend_status_icon', 'name', ) |
| 1273 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1274 | class NodeForm(forms.ModelForm): |
| 1275 | class Meta: |
Scott Baker | 2a11f85 | 2015-09-21 15:06:38 -0700 | [diff] [blame] | 1276 | model = Node |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1277 | widgets = { |
| 1278 | 'site': LinkedSelect, |
| 1279 | 'deployment': LinkedSelect |
| 1280 | } |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1281 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1282 | class NodeAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1283 | form = NodeForm |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1284 | list_display = ('backend_status_icon', 'name', 'site_deployment') |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1285 | list_display_links = ('backend_status_icon', 'name', ) |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1286 | list_filter = ('site_deployment',) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1287 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1288 | inlines = [TagInline,InstanceInline] |
Scott Baker | 2a11f85 | 2015-09-21 15:06:38 -0700 | [diff] [blame] | 1289 | fieldsets = [('Node Details', {'fields': ['backend_status_text', 'name', 'site_deployment'], 'classes':['suit-tab suit-tab-details']})] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1290 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1291 | |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1292 | user_readonly_fields = ['name','site_deployment'] |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1293 | user_readonly_inlines = [TagInline,InstanceInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1294 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1295 | suit_form_tabs =(('details','Node Details'),('instances','Instances')) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1296 | |
Tony Mack | 17b97b8 | 2015-08-04 17:32:32 -0400 | [diff] [blame] | 1297 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1298 | if db_field.name == 'site': |
| 1299 | kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_nodes=True) |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 1300 | |
Scott Baker | 2a11f85 | 2015-09-21 15:06:38 -0700 | [diff] [blame] | 1301 | field = super(NodeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1302 | |
| 1303 | return field |
| 1304 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1305 | class InstanceForm(forms.ModelForm): |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1306 | class Meta: |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1307 | model = Instance |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1308 | ip = forms.CharField(widget=PlainTextWidget) |
Tony Mack | 1826181 | 2013-05-02 16:39:20 -0400 | [diff] [blame] | 1309 | instance_name = forms.CharField(widget=PlainTextWidget) |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1310 | widgets = { |
| 1311 | 'ip': PlainTextWidget(), |
Tony Mack | 1826181 | 2013-05-02 16:39:20 -0400 | [diff] [blame] | 1312 | 'instance_name': PlainTextWidget(), |
Scott Baker | 887d4a8 | 2015-01-19 11:32:20 -0800 | [diff] [blame] | 1313 | 'instance_id': PlainTextWidget(), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1314 | 'slice': LinkedSelect, |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 1315 | 'deployment': LinkedSelect, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1316 | 'node': LinkedSelect, |
| 1317 | 'image': LinkedSelect |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1318 | } |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1319 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1320 | class TagAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1321 | list_display = ['backend_status_icon', 'service', 'name', 'value', 'content_type', 'content_object',] |
| 1322 | list_display_links = list_display |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1323 | user_readonly_fields = ['service', 'name', 'value', 'content_type', 'content_object',] |
| 1324 | user_readonly_inlines = [] |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1325 | |
Tony Mack | 8bc36b9 | 2015-09-01 16:06:52 +0000 | [diff] [blame] | 1326 | class InstancePortInline(XOSTabularInline): |
Tony Mack | ea30da8 | 2015-09-10 21:58:15 +0000 | [diff] [blame] | 1327 | fields = ['backend_status_icon', 'network', 'instance', 'ip', 'mac'] |
Scott Baker | 0672e98 | 2015-09-08 18:22:15 -0700 | [diff] [blame] | 1328 | readonly_fields = ("backend_status_icon", "ip", "mac") |
Scott Baker | 43facad | 2015-08-26 09:43:33 -0700 | [diff] [blame] | 1329 | model = Port |
Scott Baker | 29514bc | 2015-11-16 16:21:47 -0800 | [diff] [blame] | 1330 | #selflink_fieldname = "network" |
Scott Baker | 0bdb6a5 | 2015-08-25 18:00:15 -0700 | [diff] [blame] | 1331 | extra = 0 |
| 1332 | verbose_name_plural = "Ports" |
| 1333 | verbose_name = "Port" |
| 1334 | suit_classes = 'suit-tab suit-tab-ports' |
| 1335 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1336 | class InstanceAdmin(XOSBaseAdmin): |
| 1337 | form = InstanceForm |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 1338 | fieldsets = [ |
Scott Baker | 04a356a | 2015-11-12 17:25:53 -0800 | [diff] [blame] | 1339 | ('Instance Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'isolation', 'flavor', 'image', 'node', 'parent', 'all_ips_string', 'instance_id', 'instance_name', 'ssh_command', ], 'classes': ['suit-tab suit-tab-general'], }), |
Scott Baker | e1a6e0b | 2015-11-10 17:07:23 -0800 | [diff] [blame] | 1340 | ('Container Settings', {'fields': ['volumes'], 'classes': ['suit-tab suit-tab-container'], }), |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 1341 | ] |
Tony Mack | 7d61efb | 2015-01-30 17:20:46 -0500 | [diff] [blame] | 1342 | readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string') |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1343 | list_display = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'isolation', 'slice', 'flavor', 'image', 'node', 'deployment'] |
Scott Baker | f0b403f | 2015-02-13 14:38:21 -0800 | [diff] [blame] | 1344 | list_display_links = ('backend_status_icon', 'all_ips_string', 'instance_id', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1345 | |
Scott Baker | 3cf51d6 | 2016-02-02 16:54:38 -0800 | [diff] [blame] | 1346 | suit_form_tabs =(('general', 'Instance Details'), ('ports', 'Ports'), ('container', 'Container Settings'), ('tags', 'Tags')) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1347 | |
Tony Mack | 6a782f9 | 2015-09-13 22:50:39 +0000 | [diff] [blame] | 1348 | inlines = [TagInline, InstancePortInline] |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 1349 | |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 1350 | user_readonly_fields = ['slice', 'deployment', 'node', 'ip', 'instance_name', 'flavor', 'image'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1351 | |
Scott Baker | 970314b | 2015-01-25 22:16:13 -0800 | [diff] [blame] | 1352 | def ssh_command(self, obj): |
| 1353 | ssh_command = obj.get_ssh_command() |
| 1354 | if ssh_command: |
| 1355 | return ssh_command |
| 1356 | else: |
| 1357 | return "(not available)" |
| 1358 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1359 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1360 | if db_field.name == 'slice': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1361 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1362 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1363 | return super(InstanceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1364 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1365 | def queryset(self, request): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1366 | # admins can see all instances. Users can only see instances of |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1367 | # the slices they belong to. |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1368 | return Instance.select_by_user(request.user) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1369 | |
Scott Baker | b84392d | 2015-09-21 21:42:41 -0700 | [diff] [blame] | 1370 | def add_view(self, request, form_url='', extra_context = None): |
| 1371 | self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string') |
| 1372 | return super(InstanceAdmin,self).add_view(request, form_url, extra_context) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1373 | |
Scott Baker | b84392d | 2015-09-21 21:42:41 -0700 | [diff] [blame] | 1374 | def change_view(self, request, object_id, extra_context=None): |
| 1375 | self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string', 'deployment', 'slice', 'flavor', 'image', 'node') |
| 1376 | self.readonly_save = self.readonly_fields # for XOSAdminMixin.change_view's user_readonly_fields switching code |
| 1377 | return super(InstanceAdmin,self).change_view(request, object_id, extra_context) |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 1378 | |
Scott Baker | 530e4de | 2015-09-21 16:02:54 -0700 | [diff] [blame] | 1379 | def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): |
| 1380 | deployment_nodes = [] |
| 1381 | for node in Node.objects.all(): |
| 1382 | deployment_nodes.append( (node.site_deployment.deployment.id, node.id, node.name) ) |
| 1383 | |
| 1384 | deployment_flavors = [] |
| 1385 | for flavor in Flavor.objects.all(): |
| 1386 | for deployment in flavor.deployments.all(): |
| 1387 | deployment_flavors.append( (deployment.id, flavor.id, flavor.name) ) |
| 1388 | |
| 1389 | deployment_images = [] |
| 1390 | for image in Image.objects.all(): |
| 1391 | for deployment_image in image.imagedeployments.all(): |
| 1392 | deployment_images.append( (deployment_image.deployment.id, image.id, image.name) ) |
| 1393 | |
| 1394 | site_login_bases = [] |
| 1395 | for site in Site.objects.all(): |
| 1396 | site_login_bases.append((site.id, site.login_base)) |
| 1397 | |
| 1398 | context["deployment_nodes"] = deployment_nodes |
| 1399 | context["deployment_flavors"] = deployment_flavors |
| 1400 | context["deployment_images"] = deployment_images |
| 1401 | context["site_login_bases"] = site_login_bases |
| 1402 | return super(InstanceAdmin, self).render_change_form(request, context, add, change, form_url, obj) |
| 1403 | |
| 1404 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
| 1405 | if db_field.name == 'deployment': |
| 1406 | kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct() |
| 1407 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"}) |
| 1408 | if db_field.name == 'flavor': |
| 1409 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"}) |
| 1410 | |
| 1411 | field = super(InstanceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1412 | |
| 1413 | return field |
| 1414 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1415 | #def save_model(self, request, obj, form, change): |
| 1416 | # # update openstack connection to use this site/tenant |
| 1417 | # auth = request.session.get('auth', {}) |
| 1418 | # auth['tenant'] = obj.slice.name |
| 1419 | # obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
| 1420 | # obj.creator = request.user |
| 1421 | # obj.save() |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 1422 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1423 | #def delete_model(self, request, obj): |
| 1424 | # # update openstack connection to use this site/tenant |
| 1425 | # auth = request.session.get('auth', {}) |
| 1426 | # auth['tenant'] = obj.slice.name |
| 1427 | # obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
| 1428 | # obj.delete() |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 1429 | |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1430 | #class ContainerPortInline(XOSTabularInline): |
| 1431 | # fields = ['backend_status_icon', 'network', 'container', 'ip', 'mac', 'segmentation_id'] |
| 1432 | # readonly_fields = ("backend_status_icon", "ip", "mac", "segmentation_id") |
| 1433 | # model = Port |
| 1434 | # selflink_fieldname = "network" |
| 1435 | # extra = 0 |
| 1436 | # verbose_name_plural = "Ports" |
| 1437 | # verbose_name = "Port" |
| 1438 | # suit_classes = 'suit-tab suit-tab-ports' |
Scott Baker | 1de8b0d | 2015-10-26 19:52:10 -0700 | [diff] [blame] | 1439 | |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1440 | #class ContainerAdmin(XOSBaseAdmin): |
| 1441 | # fieldsets = [ |
| 1442 | # ('Container Details', {'fields': ['backend_status_text', 'slice', 'node', 'docker_image', 'volumes', 'no_sync'], 'classes': ['suit-tab suit-tab-general'], }) |
| 1443 | # ] |
| 1444 | # readonly_fields = ('backend_status_text', ) |
| 1445 | # list_display = ['backend_status_icon', 'id'] |
| 1446 | # list_display_links = ('backend_status_icon', 'id', ) |
| 1447 | # |
| 1448 | # suit_form_tabs =(('general', 'Container Details'), ('ports', 'Ports')) |
| 1449 | # |
| 1450 | # inlines = [TagInline, ContainerPortInline] |
| 1451 | # |
| 1452 | # def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1453 | # if db_field.name == 'slice': |
| 1454 | # kwargs['queryset'] = Slice.select_by_user(request.user) |
| 1455 | # |
| 1456 | # return super(ContainerAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1457 | # |
| 1458 | # def queryset(self, request): |
| 1459 | # # admins can see all instances. Users can only see instances of |
| 1460 | # # the slices they belong to. |
| 1461 | # return Container.select_by_user(request.user) |
Scott Baker | da51365 | 2015-10-26 15:12:13 -0700 | [diff] [blame] | 1462 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1463 | class UserCreationForm(forms.ModelForm): |
| 1464 | """A form for creating new users. Includes all the required |
| 1465 | fields, plus a repeated password.""" |
| 1466 | password1 = forms.CharField(label='Password', widget=forms.PasswordInput) |
| 1467 | password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput) |
| 1468 | |
| 1469 | class Meta: |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1470 | model = User |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1471 | fields = ('email', 'firstname', 'lastname', 'phone', 'public_key') |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1472 | |
| 1473 | def clean_password2(self): |
| 1474 | # Check that the two password entries match |
| 1475 | password1 = self.cleaned_data.get("password1") |
| 1476 | password2 = self.cleaned_data.get("password2") |
| 1477 | if password1 and password2 and password1 != password2: |
| 1478 | raise forms.ValidationError("Passwords don't match") |
| 1479 | return password2 |
| 1480 | |
| 1481 | def save(self, commit=True): |
| 1482 | # Save the provided password in hashed format |
| 1483 | user = super(UserCreationForm, self).save(commit=False) |
Tony Mack | f9f4afb | 2013-05-01 21:02:12 -0400 | [diff] [blame] | 1484 | user.password = self.cleaned_data["password1"] |
| 1485 | #user.set_password(self.cleaned_data["password1"]) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1486 | if commit: |
| 1487 | user.save() |
| 1488 | return user |
| 1489 | |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 1490 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1491 | class UserChangeForm(forms.ModelForm): |
| 1492 | """A form for updating users. Includes all the fields on |
| 1493 | the user, but replaces the password field with admin's |
| 1494 | password hash display field. |
| 1495 | """ |
Siobhan Tully | 63b7ba4 | 2014-01-12 10:35:11 -0500 | [diff] [blame] | 1496 | password = ReadOnlyPasswordHashField(label='Password', |
| 1497 | help_text= '<a href=\"password/\">Change Password</a>.') |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1498 | |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1499 | PROFILE_CHOICES = ((None, '------'), ('regular', 'Regular user'), ('cp', 'Content Provider')) |
| 1500 | profile = forms.ChoiceField(choices=PROFILE_CHOICES, required=False, label="Quick Profile") |
| 1501 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1502 | class Meta: |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1503 | model = User |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 1504 | widgets = { 'public_key': UploadTextareaWidget, } |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1505 | |
| 1506 | def clean_password(self): |
| 1507 | # Regardless of what the user provides, return the initial value. |
| 1508 | # This is done here, rather than on the field, because the |
| 1509 | # field does not have access to the initial value |
| 1510 | return self.initial["password"] |
| 1511 | |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1512 | def save(self, *args, **kwargs): |
| 1513 | if self.cleaned_data['profile']: |
| 1514 | self.instance.apply_profile(self.cleaned_data['profile']) |
| 1515 | |
| 1516 | return super(UserChangeForm, self).save(*args, **kwargs) |
| 1517 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1518 | class UserDashboardViewInline(XOSTabularInline): |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1519 | model = UserDashboardView |
| 1520 | extra = 0 |
| 1521 | suit_classes = 'suit-tab suit-tab-dashboards' |
| 1522 | fields = ['user', 'dashboardView', 'order'] |
| 1523 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1524 | class ControllerUserInline(XOSTabularInline): |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1525 | model = ControllerUser |
| 1526 | extra = 0 |
| 1527 | suit_classes = 'suit-tab suit-tab-admin-only' |
| 1528 | fields = ['controller', 'user', 'kuser_id'] |
| 1529 | readonly_fields=['controller'] |
| 1530 | |
| 1531 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 1532 | class UserAdmin(XOSAdminMixin, UserAdmin): |
| 1533 | # Note: Make sure XOSAdminMixin is listed before |
Scott Baker | 86c83ab | 2014-10-03 13:10:47 -0700 | [diff] [blame] | 1534 | # admin.ModelAdmin in the class declaration. |
| 1535 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1536 | class Meta: |
| 1537 | app_label = "core" |
| 1538 | |
| 1539 | # The forms to add and change user instances |
| 1540 | form = UserChangeForm |
| 1541 | add_form = UserCreationForm |
| 1542 | |
| 1543 | # The fields to be used in displaying the User model. |
| 1544 | # These override the definitions on the base UserAdmin |
| 1545 | # that reference specific fields on auth.User. |
Scott Baker | f587f44 | 2015-01-24 13:33:26 -0800 | [diff] [blame] | 1546 | list_display = ('backend_status_icon', 'email', 'firstname', 'lastname', 'site', 'last_login') |
| 1547 | list_display_links = ("email",) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1548 | list_filter = ('site',) |
Scott Baker | 6e9027f | 2015-01-29 10:55:53 -0800 | [diff] [blame] | 1549 | inlines = [SlicePrivilegeInline,SitePrivilegeInline] |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1550 | admin_inlines = [ControllerUserInline] |
Scott Baker | e61e3a0 | 2015-06-10 16:14:58 -0700 | [diff] [blame] | 1551 | fieldListLoginDetails = ['backend_status_text', 'email', 'site','password','is_active','is_readonly','is_admin','is_appuser', 'public_key', 'login_page', 'profile'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1552 | fieldListContactInfo = ['firstname','lastname','phone','timezone'] |
| 1553 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1554 | fieldsets = ( |
Scott Baker | 74ebc7a | 2015-05-15 09:19:36 -0700 | [diff] [blame] | 1555 | ('Login Details', {'fields': ['backend_status_text', 'email', 'site','password', 'is_active', 'is_readonly', 'is_admin', 'is_appuser', 'public_key'], 'classes':['suit-tab suit-tab-general']}), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1556 | ('Contact Information', {'fields': ('firstname','lastname','phone', 'timezone'), 'classes':['suit-tab suit-tab-contact']}), |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1557 | #('Important dates', {'fields': ('last_login',)}), |
| 1558 | ) |
| 1559 | add_fieldsets = ( |
| 1560 | (None, { |
| 1561 | 'classes': ('wide',), |
Scott Baker | 74ebc7a | 2015-05-15 09:19:36 -0700 | [diff] [blame] | 1562 | 'fields': ('site', 'email', 'firstname', 'lastname', 'is_admin', 'is_readonly', 'is_appuser', 'phone', 'public_key','password1', 'password2')}, |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1563 | ), |
| 1564 | ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1565 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1566 | search_fields = ('email',) |
| 1567 | ordering = ('email',) |
| 1568 | filter_horizontal = () |
| 1569 | |
Scott Baker | 3ca51f6 | 2014-05-23 12:05:11 -0700 | [diff] [blame] | 1570 | user_readonly_fields = fieldListLoginDetails + fieldListContactInfo |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1571 | |
Scott Baker | 0a5633b | 2014-10-06 17:51:20 -0700 | [diff] [blame] | 1572 | @property |
| 1573 | def suit_form_tabs(self): |
| 1574 | if getattr(_thread_locals, "obj", None) is None: |
| 1575 | return [] |
| 1576 | else: |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1577 | tabs = [('general','Login Details'), |
Scott Baker | 0a5633b | 2014-10-06 17:51:20 -0700 | [diff] [blame] | 1578 | ('contact','Contact Information'), |
| 1579 | ('sliceprivileges','Slice Privileges'), |
Scott Baker | 6e9027f | 2015-01-29 10:55:53 -0800 | [diff] [blame] | 1580 | ('siteprivileges','Site Privileges')] |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1581 | |
| 1582 | request=getattr(_thread_locals, "request", None) |
| 1583 | if request and request.user.is_admin: |
| 1584 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 1585 | |
| 1586 | return tabs |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1587 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1588 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1589 | if db_field.name == 'site': |
Tony Mack | 17b97b8 | 2015-08-04 17:32:32 -0400 | [diff] [blame] | 1590 | kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_users=True) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1591 | |
| 1592 | return super(UserAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1593 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1594 | def queryset(self, request): |
| 1595 | return User.select_by_user(request.user) |
| 1596 | |
Tony Mack | 6235fc8 | 2015-01-25 21:58:30 -0500 | [diff] [blame] | 1597 | def get_form(self, request, obj=None, **kwargs): |
Tony Mack | b2c407f | 2015-01-28 12:37:12 -0500 | [diff] [blame] | 1598 | # copy login details list |
| 1599 | login_details_fields = list(self.fieldListLoginDetails) |
Tony Mack | 92b1205 | 2015-01-28 12:49:58 -0500 | [diff] [blame] | 1600 | if not request.user.is_admin: |
Scott Baker | 6e9027f | 2015-01-29 10:55:53 -0800 | [diff] [blame] | 1601 | # only admins can see 'is_admin' and 'is_readonly' fields |
Tony Mack | b2c407f | 2015-01-28 12:37:12 -0500 | [diff] [blame] | 1602 | if 'is_admin' in login_details_fields: |
| 1603 | login_details_fields.remove('is_admin') |
| 1604 | if 'is_readonly' in login_details_fields: |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1605 | login_details_fields.remove('is_readonly') |
| 1606 | if 'is_appuser' in login_details_fields: |
| 1607 | login_details_fields.remove('is_admin') |
| 1608 | if 'profile' in login_details_fields: |
| 1609 | login_details_fields.remove('profile') |
Tony Mack | 92b1205 | 2015-01-28 12:49:58 -0500 | [diff] [blame] | 1610 | #if len(request.user.siteprivileges.filter(role__role = 'pi')) > 0: |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1611 | # only admins and pis can change a user's site |
Tony Mack | 92b1205 | 2015-01-28 12:49:58 -0500 | [diff] [blame] | 1612 | # self.readonly_fields = ('backend_status_text', 'site') |
Tony Mack | b2c407f | 2015-01-28 12:37:12 -0500 | [diff] [blame] | 1613 | self.fieldsets = ( |
| 1614 | ('Login Details', {'fields': login_details_fields, 'classes':['suit-tab suit-tab-general']}), |
| 1615 | ('Contact Information', {'fields': self.fieldListContactInfo, 'classes':['suit-tab suit-tab-contact']}), |
| 1616 | ) |
Tony Mack | 6235fc8 | 2015-01-25 21:58:30 -0500 | [diff] [blame] | 1617 | return super(UserAdmin, self).get_form(request, obj, **kwargs) |
| 1618 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1619 | class ControllerDashboardViewInline(XOSTabularInline): |
Scott Baker | a6a0c77 | 2014-12-22 17:35:34 -0800 | [diff] [blame] | 1620 | model = ControllerDashboardView |
Scott Baker | eef5a6b | 2014-12-19 16:41:12 -0800 | [diff] [blame] | 1621 | extra = 0 |
| 1622 | fields = ["controller", "url"] |
| 1623 | suit_classes = 'suit-tab suit-tab-controllers' |
| 1624 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1625 | class DashboardViewAdmin(XOSBaseAdmin): |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1626 | fieldsets = [('Dashboard View Details', |
Scott Baker | ecc55ac | 2015-02-17 13:34:32 -0800 | [diff] [blame] | 1627 | {'fields': ['backend_status_text', 'name', 'url', 'enabled', 'deployments'], |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1628 | 'classes': ['suit-tab suit-tab-general']}) |
| 1629 | ] |
Scott Baker | 9daf19c | 2015-01-18 16:46:26 -0800 | [diff] [blame] | 1630 | list_display = ["name", "enabled", "url"] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1631 | readonly_fields = ('backend_status_text', ) |
Scott Baker | a6a0c77 | 2014-12-22 17:35:34 -0800 | [diff] [blame] | 1632 | inlines = [ControllerDashboardViewInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1633 | |
Scott Baker | eef5a6b | 2014-12-19 16:41:12 -0800 | [diff] [blame] | 1634 | suit_form_tabs =(('general','Dashboard View Details'), |
| 1635 | ('controllers', 'Per-controller Dashboard Details')) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1636 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1637 | class ServiceResourceInline(XOSTabularInline): |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1638 | model = ServiceResource |
| 1639 | extra = 0 |
| 1640 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1641 | class ServiceClassAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1642 | list_display = ('backend_status_icon', 'name', 'commitment', 'membershipFee') |
| 1643 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1644 | inlines = [ServiceResourceInline] |
| 1645 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1646 | user_readonly_fields = ['name', 'commitment', 'membershipFee'] |
| 1647 | user_readonly_inlines = [] |
| 1648 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1649 | class ReservedResourceInline(XOSTabularInline): |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1650 | model = ReservedResource |
| 1651 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1652 | suit_classes = 'suit-tab suit-tab-reservedresources' |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1653 | |
| 1654 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
| 1655 | field = super(ReservedResourceInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1656 | |
| 1657 | if db_field.name == 'resource': |
| 1658 | # restrict resources to those that the slice's service class allows |
| 1659 | if request._slice is not None: |
| 1660 | field.queryset = field.queryset.filter(serviceClass = request._slice.serviceClass, calendarReservable=True) |
| 1661 | if len(field.queryset) > 0: |
| 1662 | field.initial = field.queryset.all()[0] |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 1663 | else: |
| 1664 | field.queryset = field.queryset.none() |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1665 | elif db_field.name == 'instance': |
| 1666 | # restrict instances to those that belong to the slice |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 1667 | if request._slice is not None: |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1668 | field.queryset = field.queryset.filter(slice = request._slice) |
| 1669 | else: |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 1670 | field.queryset = field.queryset.none() |
| 1671 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1672 | return field |
| 1673 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1674 | def queryset(self, request): |
| 1675 | return ReservedResource.select_by_user(request.user) |
| 1676 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1677 | class ReservationChangeForm(forms.ModelForm): |
| 1678 | class Meta: |
| 1679 | model = Reservation |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1680 | widgets = { |
| 1681 | 'slice' : LinkedSelect |
| 1682 | } |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1683 | |
| 1684 | class ReservationAddForm(forms.ModelForm): |
| 1685 | slice = forms.ModelChoiceField(queryset=Slice.objects.all(), widget=forms.Select(attrs={"onChange":"document.getElementById('id_refresh').value=1; submit()"})) |
| 1686 | refresh = forms.CharField(widget=forms.HiddenInput()) |
| 1687 | |
| 1688 | class Media: |
Scott Baker | 97468b7 | 2015-02-18 15:15:58 -0800 | [diff] [blame] | 1689 | css = {'all': ('xos.css',)} # .field-refresh { display: none; } |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1690 | |
| 1691 | def clean_slice(self): |
| 1692 | slice = self.cleaned_data.get("slice") |
| 1693 | x = ServiceResource.objects.filter(serviceClass = slice.serviceClass, calendarReservable=True) |
| 1694 | if len(x) == 0: |
| 1695 | raise forms.ValidationError("The slice you selected does not have a service class that allows reservations") |
| 1696 | return slice |
| 1697 | |
| 1698 | class Meta: |
| 1699 | model = Reservation |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1700 | widgets = { |
| 1701 | 'slice' : LinkedSelect |
| 1702 | } |
| 1703 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1704 | |
| 1705 | class ReservationAddRefreshForm(ReservationAddForm): |
| 1706 | """ This form is displayed when the Reservation Form receives an update |
| 1707 | from the Slice dropdown onChange handler. It doesn't validate the |
| 1708 | data and doesn't save the data. This will cause the form to be |
| 1709 | redrawn. |
| 1710 | """ |
| 1711 | |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1712 | """ don't validate anything other than slice """ |
| 1713 | dont_validate_fields = ("startTime", "duration") |
| 1714 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1715 | def full_clean(self): |
| 1716 | result = super(ReservationAddForm, self).full_clean() |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1717 | |
| 1718 | for fieldname in self.dont_validate_fields: |
| 1719 | if fieldname in self._errors: |
| 1720 | del self._errors[fieldname] |
| 1721 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1722 | return result |
| 1723 | |
| 1724 | """ don't save anything """ |
| 1725 | def is_valid(self): |
| 1726 | return False |
| 1727 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1728 | class ReservationAdmin(XOSBaseAdmin): |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1729 | fieldList = ['backend_status_text', 'slice', 'startTime', 'duration'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1730 | fieldsets = [('Reservation Details', {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1731 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1732 | list_display = ('startTime', 'duration') |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1733 | form = ReservationAddForm |
| 1734 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1735 | suit_form_tabs = (('general','Reservation Details'), ('reservedresources','Reserved Resources')) |
| 1736 | |
| 1737 | inlines = [ReservedResourceInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1738 | user_readonly_fields = fieldList |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1739 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1740 | def add_view(self, request, form_url='', extra_context=None): |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 1741 | timezone.activate(request.user.timezone) |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1742 | request._refresh = False |
| 1743 | request._slice = None |
| 1744 | if request.method == 'POST': |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1745 | # "refresh" will be set to "1" if the form was submitted due to |
| 1746 | # a change in the Slice dropdown. |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1747 | if request.POST.get("refresh","1") == "1": |
| 1748 | request._refresh = True |
| 1749 | request.POST["refresh"] = "0" |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1750 | |
| 1751 | # Keep track of the slice that was selected, so the |
| 1752 | # reservedResource inline can filter items for the slice. |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1753 | request._slice = request.POST.get("slice",None) |
| 1754 | if (request._slice is not None): |
| 1755 | request._slice = Slice.objects.get(id=request._slice) |
| 1756 | |
| 1757 | result = super(ReservationAdmin, self).add_view(request, form_url, extra_context) |
| 1758 | return result |
| 1759 | |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 1760 | def changelist_view(self, request, extra_context = None): |
| 1761 | timezone.activate(request.user.timezone) |
| 1762 | return super(ReservationAdmin, self).changelist_view(request, extra_context) |
| 1763 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1764 | def get_form(self, request, obj=None, **kwargs): |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1765 | request._obj_ = obj |
| 1766 | if obj is not None: |
| 1767 | # For changes, set request._slice to the slice already set in the |
| 1768 | # object. |
| 1769 | request._slice = obj.slice |
| 1770 | self.form = ReservationChangeForm |
| 1771 | else: |
| 1772 | if getattr(request, "_refresh", False): |
| 1773 | self.form = ReservationAddRefreshForm |
| 1774 | else: |
| 1775 | self.form = ReservationAddForm |
| 1776 | return super(ReservationAdmin, self).get_form(request, obj, **kwargs) |
| 1777 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1778 | def get_readonly_fields(self, request, obj=None): |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1779 | if (obj is not None): |
| 1780 | # Prevent slice from being changed after the reservation has been |
| 1781 | # created. |
| 1782 | return ['slice'] |
| 1783 | else: |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1784 | return [] |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1785 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1786 | def queryset(self, request): |
| 1787 | return Reservation.select_by_user(request.user) |
| 1788 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1789 | class NetworkParameterTypeAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1790 | list_display = ("backend_status_icon", "name", ) |
| 1791 | list_display_links = ('backend_status_icon', 'name', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1792 | user_readonly_fields = ['name'] |
| 1793 | user_readonly_inlines = [] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1794 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1795 | class RouterAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1796 | list_display = ("backend_status_icon", "name", ) |
| 1797 | list_display_links = ('backend_status_icon', 'name', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1798 | user_readonly_fields = ['name'] |
| 1799 | user_readonly_inlines = [] |
| 1800 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1801 | class RouterInline(XOSTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1802 | model = Router.networks.through |
| 1803 | extra = 0 |
| 1804 | verbose_name_plural = "Routers" |
| 1805 | verbose_name = "Router" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1806 | suit_classes = 'suit-tab suit-tab-routers' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1807 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 1808 | class NetworkParameterInline(PlStackGenericTabularInline): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1809 | model = NetworkParameter |
Scott Baker | 618e379 | 2014-08-15 13:42:29 -0700 | [diff] [blame] | 1810 | extra = 0 |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1811 | verbose_name_plural = "Parameters" |
| 1812 | verbose_name = "Parameter" |
| 1813 | suit_classes = 'suit-tab suit-tab-netparams' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1814 | fields = ['backend_status_icon', 'parameter', 'value'] |
| 1815 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1816 | |
Scott Baker | 0bdb6a5 | 2015-08-25 18:00:15 -0700 | [diff] [blame] | 1817 | class NetworkPortInline(XOSTabularInline): |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1818 | fields = ['backend_status_icon', 'network', 'instance', 'ip', 'mac'] |
Scott Baker | 0672e98 | 2015-09-08 18:22:15 -0700 | [diff] [blame] | 1819 | readonly_fields = ("backend_status_icon", "ip", "mac") |
Scott Baker | 43facad | 2015-08-26 09:43:33 -0700 | [diff] [blame] | 1820 | model = Port |
Scott Baker | f3e905d | 2015-11-16 13:43:38 -0800 | [diff] [blame] | 1821 | #selflink_fieldname = "instance" |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1822 | extra = 0 |
Scott Baker | a68e6e3 | 2015-08-25 17:11:30 -0700 | [diff] [blame] | 1823 | verbose_name_plural = "Ports" |
| 1824 | verbose_name = "Port" |
| 1825 | suit_classes = 'suit-tab suit-tab-ports' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1826 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1827 | class NetworkSlicesInline(XOSTabularInline): |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1828 | model = NetworkSlice |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 1829 | selflink_fieldname = "slice" |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1830 | extra = 0 |
| 1831 | verbose_name_plural = "Slices" |
| 1832 | verbose_name = "Slice" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1833 | suit_classes = 'suit-tab suit-tab-networkslices' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1834 | fields = ['backend_status_icon', 'network','slice'] |
| 1835 | readonly_fields = ('backend_status_icon', ) |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1836 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1837 | class ControllerNetworkInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1838 | model = ControllerNetwork |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1839 | extra = 0 |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1840 | verbose_name_plural = "Controller Networks" |
| 1841 | verbose_name = "Controller Network" |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1842 | suit_classes = 'suit-tab suit-tab-admin-only' |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1843 | fields = ['backend_status_icon', 'controller','net_id','subnet_id'] |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1844 | readonly_fields = ('backend_status_icon', ) |
| 1845 | |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 1846 | class NetworkForm(forms.ModelForm): |
| 1847 | class Meta: |
| 1848 | model = Network |
| 1849 | widgets = { |
| 1850 | 'topologyParameters': UploadTextareaWidget, |
| 1851 | 'controllerParameters': UploadTextareaWidget, |
| 1852 | } |
| 1853 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1854 | class NetworkAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1855 | list_display = ("backend_status_icon", "name", "subnet", "ports", "labels") |
| 1856 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1857 | readonly_fields = ("subnet", ) |
Scott Baker | 0bdb6a5 | 2015-08-25 18:00:15 -0700 | [diff] [blame] | 1858 | inlines = [NetworkParameterInline, NetworkPortInline, NetworkSlicesInline, RouterInline] |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1859 | admin_inlines = [ControllerNetworkInline] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1860 | |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 1861 | form=NetworkForm |
| 1862 | |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1863 | fieldsets = [ |
Scott Baker | a4c11bd | 2015-08-21 16:40:53 -0700 | [diff] [blame] | 1864 | (None, {'fields': ['backend_status_text', 'name','template','ports','labels', |
| 1865 | 'owner','guaranteed_bandwidth', 'permit_all_slices', |
| 1866 | 'permitted_slices','network_id','router_id','subnet_id', |
| 1867 | 'subnet', 'autoconnect'], |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1868 | 'classes':['suit-tab suit-tab-general']}), |
Scott Baker | 0451fb6 | 2015-01-03 12:29:29 -0800 | [diff] [blame] | 1869 | (None, {'fields': ['topology_parameters', 'controller_url', 'controller_parameters'], |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1870 | 'classes':['suit-tab suit-tab-sdn']}), |
| 1871 | ] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1872 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1873 | readonly_fields = ('backend_status_text', ) |
Scott Baker | a4c11bd | 2015-08-21 16:40:53 -0700 | [diff] [blame] | 1874 | user_readonly_fields = ['name','template','ports','labels','owner','guaranteed_bandwidth', |
| 1875 | 'permit_all_slices','permitted_slices','network_id','router_id', |
| 1876 | 'subnet_id','subnet','autoconnect'] |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1877 | |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1878 | @property |
| 1879 | def suit_form_tabs(self): |
| 1880 | tabs=[('general','Network Details'), |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1881 | ('sdn', 'SDN Configuration'), |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1882 | ('netparams', 'Parameters'), |
Scott Baker | a68e6e3 | 2015-08-25 17:11:30 -0700 | [diff] [blame] | 1883 | ('ports','Ports'), |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1884 | ('networkslices','Slices'), |
| 1885 | ('routers','Routers'), |
| 1886 | ] |
| 1887 | |
| 1888 | request=getattr(_thread_locals, "request", None) |
| 1889 | if request and request.user.is_admin: |
| 1890 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 1891 | |
| 1892 | return tabs |
| 1893 | |
| 1894 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1895 | class NetworkTemplateAdmin(XOSBaseAdmin): |
Scott Baker | 81fa17f | 2015-01-03 12:03:38 -0800 | [diff] [blame] | 1896 | list_display = ("backend_status_icon", "name", "guaranteed_bandwidth", "visibility") |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1897 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 81fa17f | 2015-01-03 12:03:38 -0800 | [diff] [blame] | 1898 | user_readonly_fields = ["name", "guaranteed_bandwidth", "visibility"] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1899 | user_readonly_inlines = [] |
Scott Baker | 29514bc | 2015-11-16 16:21:47 -0800 | [diff] [blame] | 1900 | inlines = [NetworkParameterInline,] |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1901 | fieldsets = [ |
Scott Baker | 9d5bf3b | 2015-12-09 15:44:55 -0800 | [diff] [blame] | 1902 | (None, {'fields': ['name', 'description', 'guaranteed_bandwidth', 'visibility', 'translation', 'access', 'shared_network_name', 'shared_network_id', 'topology_kind', 'controller_kind'], |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1903 | 'classes':['suit-tab suit-tab-general']}),] |
Scott Baker | 29514bc | 2015-11-16 16:21:47 -0800 | [diff] [blame] | 1904 | suit_form_tabs = (('general','Network Template Details'), ('netparams', 'Parameters') ) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1905 | |
Scott Baker | f3e905d | 2015-11-16 13:43:38 -0800 | [diff] [blame] | 1906 | class PortAdmin(XOSBaseAdmin): |
| 1907 | list_display = ("backend_status_icon", "name", "id", "ip") |
| 1908 | list_display_links = ('backend_status_icon', 'id') |
| 1909 | readonly_fields = ("subnet", ) |
| 1910 | inlines = [NetworkParameterInline] |
| 1911 | |
| 1912 | fieldsets = [ |
| 1913 | (None, {'fields': ['backend_status_text', 'network', 'instance', 'ip', 'port_id', 'mac'], |
| 1914 | 'classes':['suit-tab suit-tab-general']}), |
| 1915 | ] |
| 1916 | |
| 1917 | readonly_fields = ('backend_status_text', ) |
| 1918 | suit_form_tabs = (('general', 'Port Details'), ('netparams', 'Parameters')) |
| 1919 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1920 | class FlavorAdmin(XOSBaseAdmin): |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 1921 | list_display = ("backend_status_icon", "name", "flavor", "order", "default") |
| 1922 | list_display_links = ("backend_status_icon", "name") |
| 1923 | user_readonly_fields = ("name", "flavor") |
| 1924 | fields = ("name", "description", "flavor", "order", "default") |
| 1925 | |
Tony Mack | 31c2b8f | 2013-04-26 20:01:42 -0400 | [diff] [blame] | 1926 | # register a signal that caches the user's credentials when they log in |
| 1927 | def cache_credentials(sender, user, request, **kwds): |
| 1928 | auth = {'username': request.POST['username'], |
| 1929 | 'password': request.POST['password']} |
| 1930 | request.session['auth'] = auth |
| 1931 | user_logged_in.connect(cache_credentials) |
| 1932 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1933 | def dollar_field(fieldName, short_description): |
| 1934 | def newFunc(self, obj): |
| 1935 | try: |
| 1936 | x= "$ %0.2f" % float(getattr(obj, fieldName, 0.0)) |
| 1937 | except: |
| 1938 | x=getattr(obj, fieldName, 0.0) |
| 1939 | return x |
| 1940 | newFunc.short_description = short_description |
| 1941 | return newFunc |
| 1942 | |
| 1943 | def right_dollar_field(fieldName, short_description): |
| 1944 | def newFunc(self, obj): |
| 1945 | try: |
| 1946 | #x= '<div align=right style="width:6em">$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0)) |
| 1947 | x= '<div align=right>$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0)) |
| 1948 | except: |
| 1949 | x=getattr(obj, fieldName, 0.0) |
| 1950 | return x |
| 1951 | newFunc.short_description = short_description |
| 1952 | newFunc.allow_tags = True |
| 1953 | return newFunc |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1954 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1955 | class InvoiceChargeInline(XOSTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1956 | model = Charge |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1957 | extra = 0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1958 | verbose_name_plural = "Charges" |
| 1959 | verbose_name = "Charge" |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1960 | exclude = ['account'] |
Scott Baker | 9cb88a2 | 2013-12-09 18:56:00 -0800 | [diff] [blame] | 1961 | fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1962 | readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1963 | can_delete = False |
| 1964 | max_num = 0 |
| 1965 | |
| 1966 | dollar_amount = right_dollar_field("amount", "Amount") |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1967 | |
| 1968 | class InvoiceAdmin(admin.ModelAdmin): |
| 1969 | list_display = ("date", "account") |
| 1970 | |
| 1971 | inlines = [InvoiceChargeInline] |
| 1972 | |
Scott Baker | 9cb88a2 | 2013-12-09 18:56:00 -0800 | [diff] [blame] | 1973 | fields = ["date", "account", "dollar_amount"] |
| 1974 | readonly_fields = ["date", "account", "dollar_amount"] |
| 1975 | |
| 1976 | dollar_amount = dollar_field("amount", "Amount") |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1977 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1978 | class InvoiceInline(XOSTabularInline): |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1979 | model = Invoice |
| 1980 | extra = 0 |
| 1981 | verbose_name_plural = "Invoices" |
| 1982 | verbose_name = "Invoice" |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1983 | fields = ["date", "dollar_amount"] |
| 1984 | readonly_fields = ["date", "dollar_amount"] |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1985 | suit_classes = 'suit-tab suit-tab-accountinvoice' |
| 1986 | can_delete=False |
| 1987 | max_num=0 |
| 1988 | |
| 1989 | dollar_amount = right_dollar_field("amount", "Amount") |
| 1990 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1991 | class PendingChargeInline(XOSTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1992 | model = Charge |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1993 | extra = 0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1994 | verbose_name_plural = "Charges" |
| 1995 | verbose_name = "Charge" |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1996 | exclude = ["invoice"] |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1997 | fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1998 | readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1999 | suit_classes = 'suit-tab suit-tab-accountpendingcharges' |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2000 | can_delete=False |
| 2001 | max_num=0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2002 | |
| 2003 | def queryset(self, request): |
| 2004 | qs = super(PendingChargeInline, self).queryset(request) |
| 2005 | qs = qs.filter(state="pending") |
| 2006 | return qs |
| 2007 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2008 | dollar_amount = right_dollar_field("amount", "Amount") |
| 2009 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 2010 | class PaymentInline(XOSTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2011 | model=Payment |
| 2012 | extra = 1 |
| 2013 | verbose_name_plural = "Payments" |
| 2014 | verbose_name = "Payment" |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2015 | fields = ["date", "dollar_amount"] |
| 2016 | readonly_fields = ["date", "dollar_amount"] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2017 | suit_classes = 'suit-tab suit-tab-accountpayments' |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2018 | can_delete=False |
| 2019 | max_num=0 |
| 2020 | |
| 2021 | dollar_amount = right_dollar_field("amount", "Amount") |
| 2022 | |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2023 | class AccountAdmin(admin.ModelAdmin): |
| 2024 | list_display = ("site", "balance_due") |
| 2025 | |
| 2026 | inlines = [InvoiceInline, PaymentInline, PendingChargeInline] |
| 2027 | |
| 2028 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 2029 | (None, {'fields': ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'],'classes':['suit-tab suit-tab-general']}),] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2030 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2031 | readonly_fields = ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2032 | |
| 2033 | suit_form_tabs =( |
| 2034 | ('general','Account Details'), |
| 2035 | ('accountinvoice', 'Invoices'), |
| 2036 | ('accountpayments', 'Payments'), |
| 2037 | ('accountpendingcharges','Pending Charges'), |
| 2038 | ) |
| 2039 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2040 | dollar_balance_due = dollar_field("balance_due", "Balance Due") |
| 2041 | dollar_total_invoices = dollar_field("total_invoices", "Total Invoices") |
| 2042 | dollar_total_payments = dollar_field("total_payments", "Total Payments") |
| 2043 | |
Scott Baker | 2461bec | 2015-08-14 09:10:11 -0700 | [diff] [blame] | 2044 | class ProgramForm(forms.ModelForm): |
| 2045 | class Meta: |
| 2046 | model = Program |
| 2047 | widgets = { |
| 2048 | 'contents': UploadTextareaWidget(attrs={'rows': 20, 'cols': 80, 'class': "input-xxlarge"}), |
| 2049 | 'description': forms.Textarea(attrs={'rows': 3, 'cols': 80, 'class': 'input-xxlarge'}), |
| 2050 | 'messages': forms.Textarea(attrs={'rows': 20, 'cols': 80, 'class': 'input-xxlarge'}), |
| 2051 | 'output': forms.Textarea(attrs={'rows': 3, 'cols': 80, 'class': 'input-xxlarge'}) |
| 2052 | } |
| 2053 | |
| 2054 | class ProgramAdmin(XOSBaseAdmin): |
| 2055 | list_display = ("name", "status") |
| 2056 | list_display_links = ('name', "status") |
| 2057 | |
| 2058 | form=ProgramForm |
| 2059 | |
| 2060 | fieldsets = [ |
| 2061 | (None, {'fields': ['name', 'command', 'kind', 'description', 'output', 'status'], |
| 2062 | 'classes':['suit-tab suit-tab-general']}), |
| 2063 | (None, {'fields': ['contents'], |
| 2064 | 'classes':['suit-tab suit-tab-contents']}), |
| 2065 | (None, {'fields': ['messages'], |
| 2066 | 'classes':['suit-tab suit-tab-messages']}), |
| 2067 | ] |
| 2068 | |
| 2069 | readonly_fields = ("status",) |
| 2070 | |
| 2071 | @property |
| 2072 | def suit_form_tabs(self): |
| 2073 | tabs=[('general','Program Details'), |
| 2074 | ('contents','Program Source'), |
| 2075 | ('messages','Messages'), |
| 2076 | ] |
| 2077 | |
| 2078 | request=getattr(_thread_locals, "request", None) |
| 2079 | if request and request.user.is_admin: |
| 2080 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 2081 | |
| 2082 | return tabs |
| 2083 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 2084 | # Now register the new UserAdmin... |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 2085 | admin.site.register(User, UserAdmin) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 2086 | # ... and, since we're not using Django's builtin permissions, |
| 2087 | # unregister the Group model from admin. |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 2088 | #admin.site.unregister(Group) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 2089 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2090 | # When debugging it is often easier to see all the classes, but for regular use |
| 2091 | # only the top-levels should be displayed |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 2092 | showAll = False |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2093 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2094 | admin.site.register(Deployment, DeploymentAdmin) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 2095 | admin.site.register(Controller, ControllerAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 2096 | admin.site.register(Site, SiteAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 2097 | admin.site.register(Slice, SliceAdmin) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 2098 | admin.site.register(Service, ServiceAdmin) |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 2099 | #admin.site.register(Reservation, ReservationAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 2100 | admin.site.register(Network, NetworkAdmin) |
Scott Baker | f3e905d | 2015-11-16 13:43:38 -0800 | [diff] [blame] | 2101 | admin.site.register(Port, PortAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 2102 | admin.site.register(Router, RouterAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 2103 | admin.site.register(NetworkTemplate, NetworkTemplateAdmin) |
Scott Baker | 2461bec | 2015-08-14 09:10:11 -0700 | [diff] [blame] | 2104 | admin.site.register(Program, ProgramAdmin) |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 2105 | #admin.site.register(Account, AccountAdmin) |
| 2106 | #admin.site.register(Invoice, InvoiceAdmin) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2107 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 2108 | if True: |
| 2109 | admin.site.register(NetworkParameterType, NetworkParameterTypeAdmin) |
| 2110 | admin.site.register(ServiceClass, ServiceClassAdmin) |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 2111 | admin.site.register(Tag, TagAdmin) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 2112 | admin.site.register(ControllerRole) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 2113 | admin.site.register(SiteRole) |
| 2114 | admin.site.register(SliceRole) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2115 | admin.site.register(Node, NodeAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 2116 | #admin.site.register(SlicePrivilege, SlicePrivilegeAdmin) |
| 2117 | #admin.site.register(SitePrivilege, SitePrivilegeAdmin) |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 2118 | admin.site.register(Instance, InstanceAdmin) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2119 | admin.site.register(Image, ImageAdmin) |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 2120 | admin.site.register(DashboardView, DashboardViewAdmin) |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 2121 | admin.site.register(Flavor, FlavorAdmin) |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 2122 | admin.site.register(TenantRoot, TenantRootAdmin) |
| 2123 | admin.site.register(TenantRootRole, TenantRootRoleAdmin) |
Scott Baker | 462a1d9 | 2015-10-15 15:59:19 -0700 | [diff] [blame] | 2124 | admin.site.register(TenantAttribute, TenantAttributeAdmin) |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 2125 | # admin.site.register(Container, ContainerAdmin) |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 2126 | |