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 |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 10 | from django.contrib.admin.widgets import FilteredSelectMultiple |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 11 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
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 |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 17 | from django.core.urlresolvers import reverse, NoReverseMatch |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 18 | |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 19 | import django_evolution |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 20 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 21 | class ReadOnlyAwareAdmin(admin.ModelAdmin): |
| 22 | |
| 23 | def has_add_permission(self, request, obj=None): |
| 24 | return (not self.__user_is_readonly(request)) |
| 25 | |
| 26 | def has_delete_permission(self, request, obj=None): |
| 27 | return (not self.__user_is_readonly(request)) |
| 28 | |
| 29 | def save_model(self, request, obj, form, change): |
| 30 | if self.__user_is_readonly(request): |
| 31 | raise PermissionDenied |
| 32 | #pass |
| 33 | else: |
| 34 | return super(ReadOnlyAwareAdmin, self).save_model(request, obj, form, change) |
| 35 | |
| 36 | def get_actions(self,request): |
| 37 | actions = super(ReadOnlyAwareAdmin,self).get_actions(request) |
| 38 | |
| 39 | if self.__user_is_readonly(request): |
| 40 | if 'delete_selected' in actions: |
| 41 | del actions['delete_selected'] |
| 42 | |
| 43 | return actions |
| 44 | |
| 45 | def change_view(self,request,object_id, extra_context=None): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 46 | if self.__user_is_readonly(request): |
Scott Baker | af73e10 | 2014-04-22 22:40:07 -0700 | [diff] [blame] | 47 | if not hasattr(self, "readonly_save"):
|
| 48 | # save the original readonly fields
|
| 49 | self.readonly_save = self.readonly_fields
|
| 50 | self.inlines_save = self.inlines
|
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 51 | if hasattr(self, "user_readonly_fields"):
|
| 52 | self.readonly_fields=self.user_readonly_fields
|
| 53 | if hasattr(self, "user_readonly_inlines"):
|
| 54 | self.inlines = self.user_readonly_inlines
|
Scott Baker | af73e10 | 2014-04-22 22:40:07 -0700 | [diff] [blame] | 55 | else:
|
| 56 | if hasattr(self, "readonly_save"):
|
| 57 | # restore the original readonly fields
|
| 58 | self.readonly_fields = self.readonly_save
|
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 59 | if hasattr(self, "inlines_save"):
|
Scott Baker | af73e10 | 2014-04-22 22:40:07 -0700 | [diff] [blame] | 60 | self.inlines = self.inlines_save |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 61 | |
| 62 | try: |
| 63 | return super(ReadOnlyAwareAdmin, self).change_view(request, object_id, extra_context=extra_context) |
| 64 | except PermissionDenied: |
| 65 | pass |
| 66 | if request.method == 'POST': |
| 67 | raise PermissionDenied |
| 68 | request.readonly = True |
| 69 | return super(ReadOnlyAwareAdmin, self).change_view(request, object_id, extra_context=extra_context) |
| 70 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 71 | def __user_is_readonly(self, request): |
| 72 | return request.user.isReadOnlyUser() |
| 73 | |
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 74 | class SingletonAdmin (ReadOnlyAwareAdmin): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 75 | def has_add_permission(self, request): |
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 76 | if not super(SingletonAdmin, self).has_add_permission(request): |
| 77 | return False |
| 78 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 79 | num_objects = self.model.objects.count() |
| 80 | if num_objects >= 1: |
| 81 | return False |
| 82 | else: |
| 83 | return True |
| 84 | |
| 85 | |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 86 | class PlStackTabularInline(admin.TabularInline): |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 87 | def __init__(self, *args, **kwargs): |
| 88 | super(PlStackTabularInline, self).__init__(*args, **kwargs) |
| 89 | |
| 90 | # InlineModelAdmin as no get_fields() method, so in order to add |
| 91 | # the selflink field, we override __init__ to modify self.fields and |
| 92 | # self.readonly_fields. |
| 93 | |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 94 | self.setup_selflink() |
| 95 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 96 | def get_change_url(self, model, id): |
| 97 | """ Get the URL to a change form in the admin for this model """ |
| 98 | reverse_path = "admin:%s_change" % (model._meta.db_table) |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 99 | try: |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 100 | url = reverse(reverse_path, args=(id,)) |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 101 | except NoReverseMatch: |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 102 | return None |
| 103 | |
| 104 | return url |
| 105 | |
| 106 | def setup_selflink(self): |
| 107 | if hasattr(self, "selflink_fieldname"): |
| 108 | """ self.selflink_model can be defined to punch through a relation |
| 109 | to its target object. For example, in SliceNetworkInline, set |
| 110 | selflink_model = "network", and the URL will lead to the Network |
| 111 | object instead of trying to bring up a change view of the |
| 112 | SliceNetwork object. |
| 113 | """ |
| 114 | self.selflink_model = getattr(self.model,self.selflink_fieldname).field.rel.to |
| 115 | else: |
| 116 | self.selflink_model = self.model |
| 117 | |
| 118 | url = self.get_change_url(self.selflink_model, 0) |
| 119 | |
| 120 | # We don't have an admin for this object, so don't create the |
| 121 | # selflink. |
| 122 | if (url == None): |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 123 | return |
| 124 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 125 | # Since we need to add "selflink" to the field list, we need to create |
| 126 | # self.fields if it is None. |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 127 | if (self.fields is None): |
| 128 | self.fields = [] |
| 129 | for f in self.model._meta.fields: |
| 130 | if f.editable and f.name != "id": |
| 131 | self.fields.append(f.name) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 132 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 133 | self.fields = tuple(self.fields) + ("selflink", ) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 134 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 135 | if self.readonly_fields is None: |
| 136 | self.readonly_fields = () |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 137 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 138 | self.readonly_fields = tuple(self.readonly_fields) + ("selflink", ) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 139 | |
| 140 | def selflink(self, obj): |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 141 | if hasattr(self, "selflink_fieldname"): |
| 142 | obj = getattr(obj, self.selflink_fieldname) |
| 143 | |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 144 | if obj.id: |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 145 | url = self.get_change_url(self.selflink_model, obj.id) |
| 146 | return "<a href='%s'>Details</a>" % str(url) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 147 | else:
|
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 148 | return "Not present"
|
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 149 | |
| 150 | selflink.allow_tags = True |
| 151 | selflink.short_description = "Details" |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 152 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 153 | class ReadOnlyTabularInline(PlStackTabularInline): |
| 154 | can_delete = False |
| 155 | |
| 156 | def get_readonly_fields(self, request, obj=None): |
| 157 | return self.fields |
| 158 | |
| 159 | def has_add_permission(self, request): |
| 160 | return False |
| 161 | |
| 162 | class ReservationROInline(ReadOnlyTabularInline): |
| 163 | model = Reservation |
| 164 | extra = 0 |
| 165 | suit_classes = 'suit-tab suit-tab-reservations' |
| 166 | fields = ['startTime','slice','duration'] |
| 167 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 168 | class ReservationInline(PlStackTabularInline): |
| 169 | model = Reservation |
| 170 | extra = 0 |
| 171 | suit_classes = 'suit-tab suit-tab-reservations' |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 172 | |
| 173 | def queryset(self, request): |
| 174 | return Reservation.select_by_user(request.user) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 175 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 176 | class TagROInline(generic.GenericTabularInline): |
| 177 | model = Tag |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 178 | extra = 0 |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 179 | suit_classes = 'suit-tab suit-tab-tags' |
| 180 | can_delete = False |
| 181 | fields = ['service', 'name', 'value'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 182 | |
| 183 | def get_readonly_fields(self, request, obj=None): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 184 | return self.fields |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 185 | |
| 186 | def has_add_permission(self, request): |
| 187 | return False |
| 188 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 189 | |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 190 | class TagInline(generic.GenericTabularInline): |
| 191 | model = Tag |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 192 | extra = 0 |
| 193 | suit_classes = 'suit-tab suit-tab-tags' |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 194 | fields = ['service', 'name', 'value'] |
| 195 | |
| 196 | def queryset(self, request): |
| 197 | return Tag.select_by_user(request.user) |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 198 | |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 199 | class NetworkLookerUpper: |
Siobhan Tully | 2c780ad | 2013-09-06 11:22:40 -0400 | [diff] [blame] | 200 | """ This is a callable that looks up a network name in a sliver and returns |
| 201 | the ip address for that network. |
| 202 | """ |
| 203 | |
| 204 | def __init__(self, name): |
| 205 | self.short_description = name |
| 206 | self.__name__ = name |
| 207 | self.network_name = name |
| 208 | |
| 209 | def __call__(self, obj): |
| 210 | if obj is not None: |
| 211 | for nbs in obj.networksliver_set.all(): |
| 212 | if (nbs.network.name == self.network_name): |
| 213 | return nbs.ip |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 214 | return "" |
| 215 | |
| 216 | def __str__(self): |
| 217 | return self.network_name |
| 218 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 219 | class SliverROInline(ReadOnlyTabularInline): |
| 220 | model = Sliver |
| 221 | fields = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'node', 'deploymentNetwork'] |
| 222 | suit_classes = 'suit-tab suit-tab-slivers' |
| 223 | |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 224 | class SliverInline(PlStackTabularInline): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 225 | model = Sliver |
Tony Mack | b0d9742 | 2013-06-10 09:57:45 -0400 | [diff] [blame] | 226 | fields = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'node', 'deploymentNetwork'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 227 | extra = 0 |
Tony Mack | 3777b01 | 2013-05-07 21:38:06 -0400 | [diff] [blame] | 228 | readonly_fields = ['ip', 'instance_name'] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 229 | suit_classes = 'suit-tab suit-tab-slivers' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 230 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 231 | def queryset(self, request): |
| 232 | return Sliver.select_by_user(request.user) |
| 233 | |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 234 | # Note this is breaking in the admin.py when trying to use an inline to add a node/image |
| 235 | # def _declared_fieldsets(self): |
| 236 | # # Return None so django will call get_fieldsets and we can insert our |
| 237 | # # dynamic fields |
| 238 | # return None |
| 239 | # |
| 240 | # def get_readonly_fields(self, request, obj=None): |
| 241 | # readonly_fields = super(SliverInline, self).get_readonly_fields(request, obj) |
| 242 | # |
| 243 | # # Lookup the networks that are bound to the slivers, and add those |
| 244 | # # network names to the list of readonly fields. |
| 245 | # |
| 246 | # for sliver in obj.slivers.all(): |
| 247 | # for nbs in sliver.networksliver_set.all(): |
| 248 | # if nbs.ip: |
| 249 | # network_name = nbs.network.name |
| 250 | # if network_name not in [str(x) for x in readonly_fields]: |
| 251 | # readonly_fields.append(NetworkLookerUpper(network_name)) |
| 252 | # |
| 253 | # return readonly_fields |
| 254 | # |
| 255 | # def get_fieldsets(self, request, obj=None): |
| 256 | # form = self.get_formset(request, obj).form |
| 257 | # # fields = the read/write files + the read-only fields |
| 258 | # fields = self.fields |
| 259 | # for fieldName in self.get_readonly_fields(request,obj): |
| 260 | # if not fieldName in fields: |
| 261 | # fields.append(fieldName) |
| 262 | # |
| 263 | # return [(None, {'fields': fields})] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 264 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 265 | |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 266 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 267 | class SiteROInline(ReadOnlyTabularInline): |
| 268 | model = Site |
| 269 | extra = 0 |
| 270 | fields = ['name', 'login_base', 'site_url', 'enabled'] |
| 271 | suit_classes = 'suit-tab suit-tab-sites' |
| 272 | |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 273 | class SiteInline(PlStackTabularInline): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 274 | model = Site |
| 275 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 276 | suit_classes = 'suit-tab suit-tab-sites' |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 277 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 278 | def queryset(self, request): |
| 279 | return Site.select_by_user(request.user) |
| 280 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 281 | class UserROInline(ReadOnlyTabularInline): |
| 282 | model = User |
| 283 | fields = ['email', 'firstname', 'lastname'] |
| 284 | extra = 0 |
| 285 | suit_classes = 'suit-tab suit-tab-users' |
| 286 | |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 287 | class UserInline(PlStackTabularInline): |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 288 | model = User |
Siobhan Tully | 47ae1b5 | 2013-05-10 15:53:14 -0400 | [diff] [blame] | 289 | fields = ['email', 'firstname', 'lastname'] |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 290 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 291 | suit_classes = 'suit-tab suit-tab-users' |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 292 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 293 | def queryset(self, request): |
| 294 | return User.select_by_user(request.user) |
| 295 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 296 | class SliceROInline(ReadOnlyTabularInline): |
| 297 | model = Slice |
| 298 | suit_classes = 'suit-tab suit-tab-slices' |
| 299 | fields = ['name','site', 'serviceClass', 'service'] |
| 300 | |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 301 | class SliceInline(PlStackTabularInline): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 302 | model = Slice |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 303 | fields = ['name','site', 'serviceClass', 'service'] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 304 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 305 | suit_classes = 'suit-tab suit-tab-slices' |
| 306 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 307 | def queryset(self, request): |
| 308 | return Slice.select_by_user(request.user) |
| 309 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 310 | class NodeROInline(ReadOnlyTabularInline): |
| 311 | model = Node |
| 312 | extra = 0 |
| 313 | suit_classes = 'suit-tab suit-tab-nodes' |
| 314 | fields = ['name','deployment'] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 315 | |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 316 | class NodeInline(PlStackTabularInline): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 317 | model = Node |
| 318 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 319 | suit_classes = 'suit-tab suit-tab-nodes' |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 320 | fields = ['name','deployment'] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 321 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 322 | class DeploymentPrivilegeROInline(ReadOnlyTabularInline): |
| 323 | model = DeploymentPrivilege |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 324 | extra = 0 |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 325 | suit_classes = 'suit-tab suit-tab-deploymentprivileges' |
Scott Baker | 3ca51f6 | 2014-05-23 12:05:11 -0700 | [diff] [blame] | 326 | fields = ['user','role','deployment'] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 327 | |
| 328 | class DeploymentPrivilegeInline(PlStackTabularInline): |
| 329 | model = DeploymentPrivilege |
| 330 | extra = 0 |
| 331 | suit_classes = 'suit-tab suit-tab-deploymentprivileges' |
Scott Baker | 3ca51f6 | 2014-05-23 12:05:11 -0700 | [diff] [blame] | 332 | fields = ['user','role','deployment'] |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 333 | |
| 334 | def queryset(self, request): |
| 335 | return DeploymentPrivilege.select_by_user(request.user) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 336 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 337 | #CLEANUP DOUBLE SitePrivilegeInline |
| 338 | class SitePrivilegeROInline(ReadOnlyTabularInline): |
| 339 | model = SitePrivilege |
| 340 | extra = 0 |
| 341 | suit_classes = 'suit-tab suit-tab-siteprivileges' |
| 342 | fields = ['user','site', 'role'] |
| 343 | |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 344 | class SitePrivilegeInline(PlStackTabularInline): |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 345 | model = SitePrivilege |
| 346 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 347 | suit_classes = 'suit-tab suit-tab-siteprivileges' |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 348 | fields = ['user','site', 'role'] |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 349 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 350 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 351 | if db_field.name == 'site': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 352 | kwargs['queryset'] = Site.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 353 | |
| 354 | if db_field.name == 'user': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 355 | kwargs['queryset'] = User.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 356 | return super(SitePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 357 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 358 | def queryset(self, request): |
| 359 | return SitePrivilege.select_by_user(request.user) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 360 | |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 361 | class SiteDeploymentROInline(ReadOnlyTabularInline): |
| 362 | model = SiteDeployments |
| 363 | #model = Site.deployments.through |
| 364 | extra = 0 |
Scott Baker | f398252 | 2014-05-23 11:58:20 -0700 | [diff] [blame] | 365 | suit_classes = 'suit-tab suit-tab-deployments' |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 366 | fields = ['deployment','site'] |
| 367 | |
| 368 | class SiteDeploymentInline(PlStackTabularInline): |
| 369 | model = SiteDeployments |
| 370 | #model = Site.deployments.through |
| 371 | extra = 0 |
| 372 | suit_classes = 'suit-tab suit-tab-deployments' |
| 373 | fields = ['deployment','site'] |
| 374 | |
| 375 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 376 | if db_field.name == 'site': |
| 377 | kwargs['queryset'] = Site.select_by_user(request.user) |
| 378 | |
| 379 | if db_field.name == 'deployment': |
| 380 | kwargs['queryset'] = Deployment.select_by_user(request.user) |
| 381 | return super(SiteDeploymentInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 382 | |
| 383 | def queryset(self, request): |
| 384 | return SiteDeployments.select_by_user(request.user) |
| 385 | |
| 386 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 387 | class SlicePrivilegeROInline(ReadOnlyTabularInline): |
| 388 | model = SlicePrivilege |
| 389 | extra = 0 |
| 390 | suit_classes = 'suit-tab suit-tab-sliceprivileges' |
| 391 | fields = ['user', 'slice', 'role'] |
| 392 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 393 | class SlicePrivilegeInline(PlStackTabularInline): |
| 394 | model = SlicePrivilege |
| 395 | suit_classes = 'suit-tab suit-tab-sliceprivileges' |
| 396 | extra = 0 |
| 397 | fields = ('user', 'slice','role') |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 398 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 399 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 400 | if db_field.name == 'slice': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 401 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 402 | if db_field.name == 'user': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 403 | kwargs['queryset'] = User.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 404 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 405 | return super(SlicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 406 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 407 | def queryset(self, request): |
| 408 | return SlicePrivilege.select_by_user(request.user) |
| 409 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 410 | class SliceNetworkROInline(ReadOnlyTabularInline): |
| 411 | model = Network.slices.through |
| 412 | extra = 0 |
| 413 | verbose_name = "Network Connection" |
| 414 | verbose_name_plural = "Network Connections" |
| 415 | suit_classes = 'suit-tab suit-tab-slicenetworks' |
| 416 | fields = ['network'] |
| 417 | |
Scott Baker | a0015eb | 2013-08-14 17:28:14 -0700 | [diff] [blame] | 418 | class SliceNetworkInline(PlStackTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 419 | model = Network.slices.through |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 420 | selflink_fieldname = "network" |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 421 | extra = 0 |
| 422 | verbose_name = "Network Connection" |
| 423 | verbose_name_plural = "Network Connections" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 424 | suit_classes = 'suit-tab suit-tab-slicenetworks' |
Scott Baker | 2170b97 | 2014-06-03 12:14:07 -0700 | [diff] [blame] | 425 | fields = ['network'] |
| 426 | |
| 427 | class ImageDeploymentsInline(PlStackTabularInline): |
| 428 | model = ImageDeployments |
| 429 | extra = 0 |
| 430 | verbose_name = "Image Deployments" |
| 431 | verbose_name_plural = "Image Deployments" |
| 432 | suit_classes = 'suit-tab suit-tab-imagedeployments' |
| 433 | fields = ['deployment', 'glance_image_id'] |
| 434 | readonly_fields = ['deployment', 'glance_image_id'] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 435 | |
Tony Mack | 5e71a66 | 2013-05-03 23:30:41 -0400 | [diff] [blame] | 436 | class PlainTextWidget(forms.HiddenInput): |
| 437 | input_type = 'hidden' |
| 438 | |
| 439 | def render(self, name, value, attrs=None): |
| 440 | if value is None: |
| 441 | value = '' |
Tony Mack | 1d6b85f | 2013-05-07 18:49:14 -0400 | [diff] [blame] | 442 | return mark_safe(str(value) + super(PlainTextWidget, self).render(name, value, attrs)) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 443 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 444 | class PlanetStackBaseAdmin(ReadOnlyAwareAdmin): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 445 | save_on_top = False |
Tony Mack | 332ee1d | 2014-02-04 15:33:45 -0500 | [diff] [blame] | 446 | |
| 447 | def save_model(self, request, obj, form, change): |
Tony Mack | 3d04279 | 2014-03-17 19:18:37 -0400 | [diff] [blame] | 448 | obj.caller = request.user |
Tony Mack | 332ee1d | 2014-02-04 15:33:45 -0500 | [diff] [blame] | 449 | # update openstack connection to use this site/tenant |
| 450 | obj.save_by_user(request.user) |
| 451 | |
| 452 | def delete_model(self, request, obj): |
| 453 | obj.delete_by_user(request.user) |
| 454 | |
| 455 | def save_formset(self, request, form, formset, change): |
| 456 | instances = formset.save(commit=False) |
| 457 | for instance in instances: |
| 458 | instance.save_by_user(request.user) |
| 459 | formset.save_m2m() |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 460 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 461 | class SliceRoleAdmin(PlanetStackBaseAdmin): |
| 462 | model = SliceRole |
| 463 | pass |
| 464 | |
| 465 | class SiteRoleAdmin(PlanetStackBaseAdmin): |
| 466 | model = SiteRole |
| 467 | pass |
| 468 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 469 | class DeploymentAdminForm(forms.ModelForm): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 470 | sites = forms.ModelMultipleChoiceField( |
| 471 | queryset=Site.objects.all(), |
| 472 | required=False, |
| 473 | widget=FilteredSelectMultiple( |
| 474 | verbose_name=('Sites'), is_stacked=False |
| 475 | ) |
| 476 | ) |
| 477 | class Meta: |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 478 | model = Deployment |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 479 | |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 480 | def __init__(self, *args, **kwargs): |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 481 | request = kwargs.pop('request', None) |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 482 | super(DeploymentAdminForm, self).__init__(*args, **kwargs) |
| 483 | |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 484 | self.fields['accessControl'].initial = "allow site " + request.user.site.name |
| 485 | |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 486 | if self.instance and self.instance.pk: |
Scott Baker | c9b14f7 | 2014-05-22 13:44:20 -0700 | [diff] [blame] | 487 | self.fields['sites'].initial = [x.site for x in self.instance.sitedeployments_set.all()] |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 488 | |
| 489 | def save(self, commit=True): |
| 490 | deployment = super(DeploymentAdminForm, self).save(commit=False) |
| 491 | |
| 492 | if commit: |
| 493 | deployment.save() |
| 494 | |
| 495 | if deployment.pk: |
Scott Baker | c9b14f7 | 2014-05-22 13:44:20 -0700 | [diff] [blame] | 496 | # save_m2m() doesn't seem to work with 'through' relations. So we |
| 497 | # create/destroy the through models ourselves. There has to be |
| 498 | # a better way... |
| 499 | |
| 500 | sites = self.cleaned_data['sites'] |
| 501 | |
| 502 | existing_sites = [] |
| 503 | for sdp in list(deployment.sitedeployments_set.all()): |
| 504 | if sdp.site not in sites: |
| 505 | #print "deleting site", sdp.site |
| 506 | sdp.delete() |
| 507 | else: |
| 508 | existing_sites.append(sdp.site) |
| 509 | |
| 510 | for site in sites: |
| 511 | if site not in existing_sites: |
| 512 | #print "adding site", site |
| 513 | sdp = SiteDeployments(site=site, deployment=deployment) |
| 514 | sdp.save() |
| 515 | |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 516 | self.save_m2m() |
| 517 | |
| 518 | return deployment |
| 519 | |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 520 | class DeploymentAdminROForm(DeploymentAdminForm): |
| 521 | def save(self, commit=True): |
| 522 | raise PermissionDenied |
| 523 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 524 | class SiteAssocInline(PlStackTabularInline): |
| 525 | model = Site.deployments.through |
| 526 | extra = 0 |
| 527 | suit_classes = 'suit-tab suit-tab-sites' |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 528 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 529 | class DeploymentAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 530 | model = Deployment |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 531 | fieldList = ['name','sites', 'accessControl'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 532 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-sites']})] |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 533 | inlines = [DeploymentPrivilegeInline,NodeInline,TagInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 534 | |
| 535 | user_readonly_inlines = [DeploymentPrivilegeROInline,NodeROInline,TagROInline] |
| 536 | user_readonly_fields = ['name'] |
| 537 | |
| 538 | suit_form_tabs =(('sites','Deployment Details'),('nodes','Nodes'),('deploymentprivileges','Privileges'),('tags','Tags')) |
| 539 | |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 540 | def get_form(self, request, obj=None, **kwargs): |
| 541 | if request.user.isReadOnlyUser(): |
| 542 | kwargs["form"] = DeploymentAdminROForm |
| 543 | else: |
| 544 | kwargs["form"] = DeploymentAdminForm |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 545 | adminForm = super(DeploymentAdmin,self).get_form(request, obj, **kwargs) |
| 546 | |
| 547 | # from stackexchange: pass the request object into the form |
| 548 | |
| 549 | class AdminFormMetaClass(adminForm): |
| 550 | def __new__(cls, *args, **kwargs): |
| 551 | kwargs['request'] = request |
| 552 | return adminForm(*args, **kwargs) |
| 553 | |
| 554 | return AdminFormMetaClass |
| 555 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 556 | class ServiceAttrAsTabROInline(ReadOnlyTabularInline): |
| 557 | model = ServiceAttribute |
| 558 | fields = ['name','value'] |
| 559 | extra = 0 |
| 560 | suit_classes = 'suit-tab suit-tab-serviceattrs' |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame] | 561 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 562 | class ServiceAttrAsTabInline(PlStackTabularInline): |
| 563 | model = ServiceAttribute |
| 564 | fields = ['name','value'] |
| 565 | extra = 0 |
| 566 | suit_classes = 'suit-tab suit-tab-serviceattrs' |
| 567 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 568 | class ServiceAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 569 | list_display = ("name","description","versionNumber","enabled","published") |
| 570 | fieldList = ["name","description","versionNumber","enabled","published"] |
| 571 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
| 572 | inlines = [ServiceAttrAsTabInline,SliceInline] |
| 573 | |
| 574 | user_readonly_fields = fieldList |
| 575 | user_readonly_inlines = [ServiceAttrAsTabROInline,SliceROInline] |
| 576 | |
| 577 | suit_form_tabs =(('general', 'Service Details'), |
| 578 | ('slices','Slices'), |
| 579 | ('serviceattrs','Additional Attributes'), |
| 580 | ) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 581 | |
Tony Mack | 0553f28 | 2013-06-10 22:54:50 -0400 | [diff] [blame] | 582 | class SiteAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 583 | fieldList = ['name', 'site_url', 'enabled', 'is_public', 'login_base', 'accountLink','location'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 584 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 585 | (None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}), |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 586 | #('Deployment Networks', {'fields': ['deployments'], 'classes':['suit-tab suit-tab-deployments']}), |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 587 | ] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 588 | suit_form_tabs =(('general', 'Site Details'), |
| 589 | ('users','Users'), |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 590 | ('siteprivileges','Privileges'), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 591 | ('deployments','Deployments'), |
| 592 | ('slices','Slices'), |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 593 | ('nodes','Nodes'), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 594 | ('tags','Tags'), |
| 595 | ) |
Scott Baker | 545db2a | 2013-12-09 18:44:43 -0800 | [diff] [blame] | 596 | readonly_fields = ['accountLink'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 597 | |
| 598 | user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'accountLink'] |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 599 | user_readonly_inlines = [SliceROInline,UserROInline,TagROInline, NodeROInline, SitePrivilegeROInline,SiteDeploymentROInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 600 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 601 | list_display = ('name', 'login_base','site_url', 'enabled') |
| 602 | filter_horizontal = ('deployments',) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 603 | inlines = [SliceInline,UserInline,TagInline, NodeInline, SitePrivilegeInline, SiteDeploymentInline] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 604 | search_fields = ['name'] |
| 605 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 606 | def queryset(self, request): |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 607 | return Site.select_by_user(request.user) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 608 | |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame] | 609 | def get_formsets(self, request, obj=None): |
| 610 | for inline in self.get_inline_instances(request, obj): |
| 611 | # hide MyInline in the add view |
| 612 | if obj is None: |
| 613 | continue |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 614 | if isinstance(inline, SliceInline): |
| 615 | inline.model.caller = request.user |
| 616 | yield inline.get_formset(request, obj) |
| 617 | |
| 618 | def get_formsets(self, request, obj=None): |
| 619 | for inline in self.get_inline_instances(request, obj): |
| 620 | # hide MyInline in the add view |
| 621 | if obj is None: |
| 622 | continue |
| 623 | if isinstance(inline, SliverInline): |
| 624 | inline.model.caller = request.user |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame] | 625 | yield inline.get_formset(request, obj) |
| 626 | |
Scott Baker | 545db2a | 2013-12-09 18:44:43 -0800 | [diff] [blame] | 627 | def accountLink(self, obj): |
| 628 | link_obj = obj.accounts.all() |
| 629 | if link_obj: |
| 630 | reverse_path = "admin:core_account_change" |
| 631 | url = reverse(reverse_path, args =(link_obj[0].id,)) |
| 632 | return "<a href='%s'>%s</a>" % (url, "view billing details") |
| 633 | else: |
| 634 | return "no billing data for this site" |
| 635 | accountLink.allow_tags = True |
| 636 | accountLink.short_description = "Billing" |
| 637 | |
Tony Mack | 332ee1d | 2014-02-04 15:33:45 -0500 | [diff] [blame] | 638 | def save_model(self, request, obj, form, change): |
| 639 | # update openstack connection to use this site/tenant |
| 640 | obj.save_by_user(request.user) |
| 641 | |
| 642 | def delete_model(self, request, obj): |
| 643 | obj.delete_by_user(request.user) |
| 644 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 645 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 646 | class SitePrivilegeAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 647 | fieldList = ['user', 'site', 'role'] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 648 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 649 | (None, {'fields': fieldList, 'classes':['collapse']}) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 650 | ] |
| 651 | list_display = ('user', 'site', 'role') |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 652 | user_readonly_fields = fieldList |
| 653 | user_readonly_inlines = [] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 654 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 655 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 656 | if db_field.name == 'site': |
| 657 | if not request.user.is_admin: |
| 658 | # only show sites where user is an admin or pi |
| 659 | sites = set() |
| 660 | for site_privilege in SitePrivilege.objects.filer(user=request.user): |
| 661 | if site_privilege.role.role_type in ['admin', 'pi']: |
| 662 | sites.add(site_privilege.site) |
| 663 | kwargs['queryset'] = Site.objects.filter(site__in=list(sites)) |
| 664 | |
| 665 | if db_field.name == 'user': |
| 666 | if not request.user.is_admin: |
| 667 | # only show users from sites where caller has admin or pi role |
| 668 | roles = Role.objects.filter(role_type__in=['admin', 'pi']) |
| 669 | site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles) |
| 670 | sites = [site_privilege.site for site_privilege in site_privileges] |
| 671 | site_privileges = SitePrivilege.objects.filter(site__in=sites) |
| 672 | emails = [site_privilege.user.email for site_privilege in site_privileges] |
| 673 | users = User.objects.filter(email__in=emails) |
| 674 | kwargs['queryset'] = users |
| 675 | |
| 676 | return super(SitePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 677 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 678 | def queryset(self, request): |
| 679 | # admins can see all privileges. Users can only see privileges at sites |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 680 | # where they have the admin role or pi role. |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 681 | qs = super(SitePrivilegeAdmin, self).queryset(request) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 682 | #if not request.user.is_admin: |
| 683 | # roles = Role.objects.filter(role_type__in=['admin', 'pi']) |
| 684 | # site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles) |
| 685 | # login_bases = [site_privilege.site.login_base for site_privilege in site_privileges] |
| 686 | # sites = Site.objects.filter(login_base__in=login_bases) |
| 687 | # qs = qs.filter(site__in=sites) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 688 | return qs |
| 689 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 690 | class SliceForm(forms.ModelForm): |
| 691 | class Meta: |
| 692 | model = Slice |
| 693 | widgets = { |
| 694 | 'service': LinkedSelect |
| 695 | } |
| 696 | |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 697 | class SliceAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 698 | form = SliceForm |
Tony Mack | 29bf5e8 | 2014-04-29 21:40:24 -0400 | [diff] [blame] | 699 | fieldList = ['name', 'site', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_slivers'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 700 | fieldsets = [('Slice Details', {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),] |
Tony Mack | 29bf5e8 | 2014-04-29 21:40:24 -0400 | [diff] [blame] | 701 | list_display = ('name', 'site','serviceClass', 'slice_url', 'max_slivers') |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 702 | inlines = [SlicePrivilegeInline,SliverInline, TagInline, ReservationInline,SliceNetworkInline] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 703 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 704 | user_readonly_fields = fieldList |
| 705 | user_readonly_inlines = [SlicePrivilegeROInline,SliverROInline,TagROInline, ReservationROInline, SliceNetworkROInline] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 706 | |
| 707 | suit_form_tabs =(('general', 'Slice Details'), |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 708 | ('slicenetworks','Networks'), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 709 | ('sliceprivileges','Privileges'), |
| 710 | ('slivers','Slivers'), |
| 711 | ('tags','Tags'), |
| 712 | ('reservations','Reservations'), |
| 713 | ) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 714 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 715 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 716 | if db_field.name == 'site': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 717 | kwargs['queryset'] = Site.select_by_user(request.user) |
| 718 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 719 | return super(SliceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 720 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 721 | def queryset(self, request): |
| 722 | # 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] | 723 | return Slice.select_by_user(request.user) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 724 | |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 725 | def get_formsets(self, request, obj=None): |
| 726 | for inline in self.get_inline_instances(request, obj): |
| 727 | # hide MyInline in the add view |
| 728 | if obj is None: |
| 729 | continue |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 730 | if isinstance(inline, SliverInline): |
| 731 | inline.model.caller = request.user |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 732 | yield inline.get_formset(request, obj) |
| 733 | |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 734 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 735 | class SlicePrivilegeAdmin(PlanetStackBaseAdmin): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 736 | fieldsets = [ |
| 737 | (None, {'fields': ['user', 'slice', 'role']}) |
| 738 | ] |
| 739 | list_display = ('user', 'slice', 'role') |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 740 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 741 | user_readonly_fields = ['user', 'slice', 'role'] |
| 742 | user_readonly_inlines = [] |
| 743 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 744 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 745 | if db_field.name == 'slice': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 746 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 747 | |
| 748 | if db_field.name == 'user': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 749 | kwargs['queryset'] = User.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 750 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 751 | return super(SlicePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 752 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 753 | def queryset(self, request): |
| 754 | # admins can see all memberships. Users can only see memberships of |
| 755 | # slices where they have the admin role. |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 756 | return SlicePrivilege.select_by_user(request.user) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 757 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 758 | def save_model(self, request, obj, form, change): |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 759 | # update openstack connection to use this site/tenant |
| 760 | auth = request.session.get('auth', {}) |
| 761 | auth['tenant'] = obj.slice.name |
| 762 | obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 763 | obj.save() |
| 764 | |
| 765 | def delete_model(self, request, obj): |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 766 | # update openstack connection to use this site/tenant |
| 767 | auth = request.session.get('auth', {}) |
| 768 | auth['tenant'] = obj.slice.name |
| 769 | obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 770 | obj.delete() |
| 771 | |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 772 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 773 | class ImageAdmin(PlanetStackBaseAdmin): |
| 774 | |
| 775 | fieldsets = [('Image Details', |
Scott Baker | 00b00b3 | 2014-05-07 08:47:54 -0700 | [diff] [blame] | 776 | {'fields': ['name', 'disk_format', 'container_format'], |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 777 | 'classes': ['suit-tab suit-tab-general']}) |
| 778 | ] |
| 779 | |
Scott Baker | 2170b97 | 2014-06-03 12:14:07 -0700 | [diff] [blame] | 780 | suit_form_tabs =(('general','Image Details'),('slivers','Slivers'),('imagedeployments','Deployments')) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 781 | |
Scott Baker | 2170b97 | 2014-06-03 12:14:07 -0700 | [diff] [blame] | 782 | inlines = [SliverInline, ImageDeploymentsInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 783 | |
Tony Mack | 32e1ce3 | 2014-05-07 13:29:41 -0400 | [diff] [blame] | 784 | user_readonly_fields = ['name', 'disk_format', 'container_format'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 785 | user_readonly_inlines = [SliverROInline] |
| 786 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 787 | class NodeForm(forms.ModelForm): |
| 788 | class Meta: |
| 789 | widgets = { |
| 790 | 'site': LinkedSelect, |
| 791 | 'deployment': LinkedSelect |
| 792 | } |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 793 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 794 | class NodeAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 795 | form = NodeForm |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 796 | list_display = ('name', 'site', 'deployment') |
| 797 | list_filter = ('deployment',) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 798 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 799 | inlines = [TagInline,SliverInline] |
| 800 | fieldsets = [('Node Details', {'fields': ['name','site','deployment'], 'classes':['suit-tab suit-tab-details']})] |
| 801 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 802 | user_readonly_fields = ['name','site','deployment'] |
| 803 | user_readonly_inlines = [TagInline,SliverInline] |
| 804 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 805 | suit_form_tabs =(('details','Node Details'),('slivers','Slivers'),('tags','Tags')) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 806 | |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 807 | |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 808 | class SliverForm(forms.ModelForm): |
| 809 | class Meta: |
Tony Mack | 1d6b85f | 2013-05-07 18:49:14 -0400 | [diff] [blame] | 810 | model = Sliver |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 811 | ip = forms.CharField(widget=PlainTextWidget) |
Tony Mack | 1826181 | 2013-05-02 16:39:20 -0400 | [diff] [blame] | 812 | instance_name = forms.CharField(widget=PlainTextWidget) |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 813 | widgets = { |
| 814 | 'ip': PlainTextWidget(), |
Tony Mack | 1826181 | 2013-05-02 16:39:20 -0400 | [diff] [blame] | 815 | 'instance_name': PlainTextWidget(), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 816 | 'slice': LinkedSelect, |
| 817 | 'deploymentNetwork': LinkedSelect, |
| 818 | 'node': LinkedSelect, |
| 819 | 'image': LinkedSelect |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 820 | } |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 821 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 822 | class TagAdmin(PlanetStackBaseAdmin): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 823 | list_display = ['service', 'name', 'value', 'content_type', 'content_object',] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 824 | user_readonly_fields = ['service', 'name', 'value', 'content_type', 'content_object',] |
| 825 | user_readonly_inlines = [] |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 826 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 827 | class SliverAdmin(PlanetStackBaseAdmin): |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 828 | form = SliverForm |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 829 | fieldsets = [ |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 830 | ('Sliver Details', {'fields': ['slice', 'deploymentNetwork', 'node', 'ip', 'instance_name', 'numberCores', 'image', ], 'classes': ['suit-tab suit-tab-general'], }) |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 831 | ] |
Siobhan Tully | 5d7dc8d | 2013-07-02 13:17:33 -0400 | [diff] [blame] | 832 | list_display = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'node', 'deploymentNetwork'] |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 833 | |
| 834 | suit_form_tabs =(('general', 'Sliver Details'), |
| 835 | ('tags','Tags'), |
| 836 | ) |
| 837 | |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 838 | inlines = [TagInline] |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 839 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 840 | user_readonly_fields = ['slice', 'deploymentNetwork', 'node', 'ip', 'instance_name', 'numberCores', 'image'] |
| 841 | user_readonly_inlines = [TagROInline] |
| 842 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 843 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 844 | if db_field.name == 'slice': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 845 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 846 | |
| 847 | return super(SliverAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 848 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 849 | def queryset(self, request): |
| 850 | # admins can see all slivers. Users can only see slivers of |
| 851 | # the slices they belong to. |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 852 | return Sliver.select_by_user(request.user) |
| 853 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 854 | |
Tony Mack | 1d6b85f | 2013-05-07 18:49:14 -0400 | [diff] [blame] | 855 | def get_formsets(self, request, obj=None): |
| 856 | # make some fields read only if we are updating an existing record |
| 857 | if obj == None: |
| 858 | #self.readonly_fields = ('ip', 'instance_name') |
| 859 | self.readonly_fields = () |
| 860 | else: |
Tony Mack | 1e88946 | 2013-05-10 21:34:54 -0400 | [diff] [blame] | 861 | self.readonly_fields = () |
| 862 | #self.readonly_fields = ('ip', 'instance_name', 'slice', 'image', 'key') |
Tony Mack | 1d6b85f | 2013-05-07 18:49:14 -0400 | [diff] [blame] | 863 | |
| 864 | for inline in self.get_inline_instances(request, obj): |
| 865 | # hide MyInline in the add view |
| 866 | if obj is None: |
| 867 | continue |
Scott Baker | 526b71e | 2014-05-13 13:18:01 -0700 | [diff] [blame] | 868 | if isinstance(inline, SliverInline): |
| 869 | inline.model.caller = request.user |
| 870 | yield inline.get_formset(request, obj) |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 871 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 872 | #def save_model(self, request, obj, form, change): |
| 873 | # # update openstack connection to use this site/tenant |
| 874 | # auth = request.session.get('auth', {}) |
| 875 | # auth['tenant'] = obj.slice.name |
| 876 | # obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
| 877 | # obj.creator = request.user |
| 878 | # obj.save() |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 879 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 880 | #def delete_model(self, request, obj): |
| 881 | # # update openstack connection to use this site/tenant |
| 882 | # auth = request.session.get('auth', {}) |
| 883 | # auth['tenant'] = obj.slice.name |
| 884 | # obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
| 885 | # obj.delete() |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 886 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 887 | class UserCreationForm(forms.ModelForm): |
| 888 | """A form for creating new users. Includes all the required |
| 889 | fields, plus a repeated password.""" |
| 890 | password1 = forms.CharField(label='Password', widget=forms.PasswordInput) |
| 891 | password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput) |
| 892 | |
| 893 | class Meta: |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 894 | model = User |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 895 | fields = ('email', 'firstname', 'lastname', 'phone', 'public_key') |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 896 | |
| 897 | def clean_password2(self): |
| 898 | # Check that the two password entries match |
| 899 | password1 = self.cleaned_data.get("password1") |
| 900 | password2 = self.cleaned_data.get("password2") |
| 901 | if password1 and password2 and password1 != password2: |
| 902 | raise forms.ValidationError("Passwords don't match") |
| 903 | return password2 |
| 904 | |
| 905 | def save(self, commit=True): |
| 906 | # Save the provided password in hashed format |
| 907 | user = super(UserCreationForm, self).save(commit=False) |
Tony Mack | f9f4afb | 2013-05-01 21:02:12 -0400 | [diff] [blame] | 908 | user.password = self.cleaned_data["password1"] |
| 909 | #user.set_password(self.cleaned_data["password1"]) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 910 | if commit: |
| 911 | user.save() |
| 912 | return user |
| 913 | |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 914 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 915 | class UserChangeForm(forms.ModelForm): |
| 916 | """A form for updating users. Includes all the fields on |
| 917 | the user, but replaces the password field with admin's |
| 918 | password hash display field. |
| 919 | """ |
Siobhan Tully | 63b7ba4 | 2014-01-12 10:35:11 -0500 | [diff] [blame] | 920 | password = ReadOnlyPasswordHashField(label='Password', |
| 921 | help_text= '<a href=\"password/\">Change Password</a>.') |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 922 | |
| 923 | class Meta: |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 924 | model = User |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 925 | |
| 926 | def clean_password(self): |
| 927 | # Regardless of what the user provides, return the initial value. |
| 928 | # This is done here, rather than on the field, because the |
| 929 | # field does not have access to the initial value |
| 930 | return self.initial["password"] |
| 931 | |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 932 | class UserDashboardViewInline(PlStackTabularInline): |
| 933 | model = UserDashboardView |
| 934 | extra = 0 |
| 935 | suit_classes = 'suit-tab suit-tab-dashboards' |
| 936 | fields = ['user', 'dashboardView', 'order'] |
| 937 | |
Scott Baker | ed31f67 | 2014-05-21 18:14:03 -0700 | [diff] [blame] | 938 | class UserDashboardViewROInline(ReadOnlyTabularInline): |
| 939 | model = UserDashboardView |
| 940 | extra = 0 |
| 941 | suit_classes = 'suit-tab suit-tab-dashboards' |
| 942 | fields = ['user', 'dashboardView', 'order'] |
| 943 | |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 944 | class UserAdmin(UserAdmin): |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 945 | class Meta: |
| 946 | app_label = "core" |
| 947 | |
| 948 | # The forms to add and change user instances |
| 949 | form = UserChangeForm |
| 950 | add_form = UserCreationForm |
| 951 | |
| 952 | # The fields to be used in displaying the User model. |
| 953 | # These override the definitions on the base UserAdmin |
| 954 | # that reference specific fields on auth.User. |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 955 | list_display = ('email', 'firstname', 'lastname', 'site', 'last_login') |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 956 | #list_display = ('email', 'username','firstname', 'lastname', 'is_admin', 'last_login') |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 957 | list_filter = ('site',) |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 958 | inlines = [SlicePrivilegeInline,SitePrivilegeInline,DeploymentPrivilegeInline,UserDashboardViewInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 959 | |
| 960 | fieldListLoginDetails = ['email','site','password','is_readonly','is_amin','public_key'] |
| 961 | fieldListContactInfo = ['firstname','lastname','phone','timezone'] |
| 962 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 963 | fieldsets = ( |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 964 | ('Login Details', {'fields': ['email', 'site','password', 'is_readonly', 'is_admin', 'public_key'], 'classes':['suit-tab suit-tab-general']}), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 965 | ('Contact Information', {'fields': ('firstname','lastname','phone', 'timezone'), 'classes':['suit-tab suit-tab-contact']}), |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 966 | #('Dashboard Views', {'fields': ('dashboards',), 'classes':['suit-tab suit-tab-dashboards']}), |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 967 | #('Important dates', {'fields': ('last_login',)}), |
| 968 | ) |
| 969 | add_fieldsets = ( |
| 970 | (None, { |
| 971 | 'classes': ('wide',), |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 972 | 'fields': ('email', 'firstname', 'lastname', 'is_readonly', 'phone', 'public_key','password1', 'password2')} |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 973 | ), |
| 974 | ) |
| 975 | search_fields = ('email',) |
| 976 | ordering = ('email',) |
| 977 | filter_horizontal = () |
| 978 | |
Scott Baker | 3ca51f6 | 2014-05-23 12:05:11 -0700 | [diff] [blame] | 979 | user_readonly_fields = fieldListLoginDetails + fieldListContactInfo |
Scott Baker | ed31f67 | 2014-05-21 18:14:03 -0700 | [diff] [blame] | 980 | user_readonly_inlines = [SlicePrivilegeROInline,SitePrivilegeROInline,DeploymentPrivilegeROInline,UserDashboardViewROInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 981 | |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 982 | suit_form_tabs =(('general','Login Details'), |
| 983 | ('contact','Contact Information'), |
| 984 | ('sliceprivileges','Slice Privileges'), |
| 985 | ('siteprivileges','Site Privileges'), |
| 986 | ('deploymentprivileges','Deployment Privileges'), |
| 987 | ('dashboards','Dashboard Views')) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 988 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 989 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 990 | if db_field.name == 'site': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 991 | kwargs['queryset'] = Site.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 992 | |
| 993 | return super(UserAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 994 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 995 | def has_add_permission(self, request, obj=None): |
| 996 | return (not self.__user_is_readonly(request)) |
| 997 | |
| 998 | def has_delete_permission(self, request, obj=None): |
| 999 | return (not self.__user_is_readonly(request)) |
| 1000 | |
| 1001 | def get_actions(self,request): |
| 1002 | actions = super(UserAdmin,self).get_actions(request) |
| 1003 | |
| 1004 | if self.__user_is_readonly(request): |
| 1005 | if 'delete_selected' in actions: |
| 1006 | del actions['delete_selected'] |
| 1007 | |
| 1008 | return actions |
| 1009 | |
| 1010 | def change_view(self,request,object_id, extra_context=None): |
| 1011 | |
| 1012 | if self.__user_is_readonly(request): |
Scott Baker | f875eba | 2014-05-23 12:09:15 -0700 | [diff] [blame] | 1013 | if not hasattr(self, "readonly_save"): |
| 1014 | # save the original readonly fields
|
| 1015 | self.readonly_save = self.readonly_fields
|
| 1016 | self.inlines_save = self.inlines |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1017 | self.readonly_fields=self.user_readonly_fields |
| 1018 | self.inlines = self.user_readonly_inlines |
Scott Baker | f875eba | 2014-05-23 12:09:15 -0700 | [diff] [blame] | 1019 | else: |
| 1020 | if hasattr(self, "readonly_save"):
|
| 1021 | # restore the original readonly fields
|
| 1022 | self.readonly_fields = self.readonly_save
|
| 1023 | self.inlines = self.inlines_save |
| 1024 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1025 | try: |
| 1026 | return super(UserAdmin, self).change_view(request, object_id, extra_context=extra_context) |
| 1027 | except PermissionDenied: |
| 1028 | pass |
| 1029 | if request.method == 'POST': |
| 1030 | raise PermissionDenied |
| 1031 | request.readonly = True |
| 1032 | return super(UserAdmin, self).change_view(request, object_id, extra_context=extra_context) |
| 1033 | |
| 1034 | def __user_is_readonly(self, request): |
| 1035 | #groups = [x.name for x in request.user.groups.all() ] |
| 1036 | #return "readonly" in groups |
| 1037 | return request.user.isReadOnlyUser() |
| 1038 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1039 | def queryset(self, request): |
| 1040 | return User.select_by_user(request.user) |
| 1041 | |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1042 | class DashboardViewAdmin(PlanetStackBaseAdmin): |
| 1043 | fieldsets = [('Dashboard View Details', |
| 1044 | {'fields': ['name', 'url'], |
| 1045 | 'classes': ['suit-tab suit-tab-general']}) |
| 1046 | ] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1047 | |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1048 | suit_form_tabs =(('general','Dashboard View Details'),) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1049 | |
| 1050 | class ServiceResourceROInline(ReadOnlyTabularInline): |
| 1051 | model = ServiceResource |
| 1052 | extra = 0 |
| 1053 | fields = ['serviceClass', 'name', 'maxUnitsDeployment', 'maxUnitsNode', 'maxDuration', 'bucketInRate', 'bucketMaxSize', 'cost', 'calendarReservable'] |
| 1054 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1055 | class ServiceResourceInline(PlStackTabularInline): |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1056 | model = ServiceResource |
| 1057 | extra = 0 |
| 1058 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1059 | class ServiceClassAdmin(PlanetStackBaseAdmin): |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1060 | list_display = ('name', 'commitment', 'membershipFee') |
| 1061 | inlines = [ServiceResourceInline] |
| 1062 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1063 | user_readonly_fields = ['name', 'commitment', 'membershipFee'] |
| 1064 | user_readonly_inlines = [] |
| 1065 | |
| 1066 | class ReservedResourceROInline(ReadOnlyTabularInline): |
| 1067 | model = ReservedResource |
| 1068 | extra = 0 |
| 1069 | fields = ['sliver', 'resource','quantity','reservationSet'] |
| 1070 | suit_classes = 'suit-tab suit-tab-reservedresources' |
| 1071 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1072 | class ReservedResourceInline(PlStackTabularInline): |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1073 | model = ReservedResource |
| 1074 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1075 | suit_classes = 'suit-tab suit-tab-reservedresources' |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1076 | |
| 1077 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
| 1078 | field = super(ReservedResourceInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1079 | |
| 1080 | if db_field.name == 'resource': |
| 1081 | # restrict resources to those that the slice's service class allows |
| 1082 | if request._slice is not None: |
| 1083 | field.queryset = field.queryset.filter(serviceClass = request._slice.serviceClass, calendarReservable=True) |
| 1084 | if len(field.queryset) > 0: |
| 1085 | field.initial = field.queryset.all()[0] |
| 1086 | else:
|
| 1087 | field.queryset = field.queryset.none()
|
| 1088 | elif db_field.name == 'sliver':
|
| 1089 | # restrict slivers to those that belong to the slice
|
| 1090 | if request._slice is not None:
|
| 1091 | field.queryset = field.queryset.filter(slice = request._slice) |
| 1092 | else: |
| 1093 | field.queryset = field.queryset.none()
|
| 1094 |
|
| 1095 | return field |
| 1096 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1097 | def queryset(self, request): |
| 1098 | return ReservedResource.select_by_user(request.user) |
| 1099 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1100 | class ReservationChangeForm(forms.ModelForm): |
| 1101 | class Meta: |
| 1102 | model = Reservation |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1103 | widgets = { |
| 1104 | 'slice' : LinkedSelect |
| 1105 | } |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1106 | |
| 1107 | class ReservationAddForm(forms.ModelForm): |
| 1108 | slice = forms.ModelChoiceField(queryset=Slice.objects.all(), widget=forms.Select(attrs={"onChange":"document.getElementById('id_refresh').value=1; submit()"})) |
| 1109 | refresh = forms.CharField(widget=forms.HiddenInput()) |
| 1110 | |
| 1111 | class Media: |
| 1112 | css = {'all': ('planetstack.css',)} # .field-refresh { display: none; } |
| 1113 | |
| 1114 | def clean_slice(self): |
| 1115 | slice = self.cleaned_data.get("slice") |
| 1116 | x = ServiceResource.objects.filter(serviceClass = slice.serviceClass, calendarReservable=True) |
| 1117 | if len(x) == 0: |
| 1118 | raise forms.ValidationError("The slice you selected does not have a service class that allows reservations") |
| 1119 | return slice |
| 1120 | |
| 1121 | class Meta: |
| 1122 | model = Reservation |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1123 | widgets = { |
| 1124 | 'slice' : LinkedSelect |
| 1125 | } |
| 1126 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1127 | |
| 1128 | class ReservationAddRefreshForm(ReservationAddForm): |
| 1129 | """ This form is displayed when the Reservation Form receives an update |
| 1130 | from the Slice dropdown onChange handler. It doesn't validate the |
| 1131 | data and doesn't save the data. This will cause the form to be |
| 1132 | redrawn. |
| 1133 | """ |
| 1134 | |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1135 | """ don't validate anything other than slice """ |
| 1136 | dont_validate_fields = ("startTime", "duration") |
| 1137 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1138 | def full_clean(self): |
| 1139 | result = super(ReservationAddForm, self).full_clean() |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1140 | |
| 1141 | for fieldname in self.dont_validate_fields: |
| 1142 | if fieldname in self._errors: |
| 1143 | del self._errors[fieldname] |
| 1144 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1145 | return result |
| 1146 | |
| 1147 | """ don't save anything """ |
| 1148 | def is_valid(self): |
| 1149 | return False |
| 1150 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1151 | class ReservationAdmin(PlanetStackBaseAdmin): |
| 1152 | fieldList = ['slice', 'startTime', 'duration'] |
| 1153 | fieldsets = [('Reservation Details', {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})] |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1154 | list_display = ('startTime', 'duration') |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1155 | form = ReservationAddForm |
| 1156 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1157 | suit_form_tabs = (('general','Reservation Details'), ('reservedresources','Reserved Resources')) |
| 1158 | |
| 1159 | inlines = [ReservedResourceInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1160 | user_readonly_inlines = [ReservedResourceROInline] |
| 1161 | user_readonly_fields = fieldList |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1162 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1163 | def add_view(self, request, form_url='', extra_context=None): |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 1164 | timezone.activate(request.user.timezone) |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1165 | request._refresh = False |
| 1166 | request._slice = None |
| 1167 | if request.method == 'POST': |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1168 | # "refresh" will be set to "1" if the form was submitted due to |
| 1169 | # a change in the Slice dropdown. |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1170 | if request.POST.get("refresh","1") == "1": |
| 1171 | request._refresh = True |
| 1172 | request.POST["refresh"] = "0" |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1173 | |
| 1174 | # Keep track of the slice that was selected, so the |
| 1175 | # reservedResource inline can filter items for the slice. |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1176 | request._slice = request.POST.get("slice",None) |
| 1177 | if (request._slice is not None): |
| 1178 | request._slice = Slice.objects.get(id=request._slice) |
| 1179 | |
| 1180 | result = super(ReservationAdmin, self).add_view(request, form_url, extra_context) |
| 1181 | return result |
| 1182 | |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 1183 | def changelist_view(self, request, extra_context = None): |
| 1184 | timezone.activate(request.user.timezone) |
| 1185 | return super(ReservationAdmin, self).changelist_view(request, extra_context) |
| 1186 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1187 | def get_form(self, request, obj=None, **kwargs): |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1188 | request._obj_ = obj |
| 1189 | if obj is not None: |
| 1190 | # For changes, set request._slice to the slice already set in the |
| 1191 | # object. |
| 1192 | request._slice = obj.slice |
| 1193 | self.form = ReservationChangeForm |
| 1194 | else: |
| 1195 | if getattr(request, "_refresh", False): |
| 1196 | self.form = ReservationAddRefreshForm |
| 1197 | else: |
| 1198 | self.form = ReservationAddForm |
| 1199 | return super(ReservationAdmin, self).get_form(request, obj, **kwargs) |
| 1200 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1201 | def get_readonly_fields(self, request, obj=None): |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1202 | if (obj is not None): |
| 1203 | # Prevent slice from being changed after the reservation has been |
| 1204 | # created. |
| 1205 | return ['slice'] |
| 1206 | else: |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1207 | return [] |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1208 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1209 | def queryset(self, request): |
| 1210 | return Reservation.select_by_user(request.user) |
| 1211 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1212 | class NetworkParameterTypeAdmin(PlanetStackBaseAdmin): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1213 | list_display = ("name", ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1214 | user_readonly_fields = ['name'] |
| 1215 | user_readonly_inlines = [] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1216 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1217 | class RouterAdmin(PlanetStackBaseAdmin): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1218 | list_display = ("name", ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1219 | user_readonly_fields = ['name'] |
| 1220 | user_readonly_inlines = [] |
| 1221 | |
| 1222 | class RouterROInline(ReadOnlyTabularInline): |
| 1223 | model = Router.networks.through |
| 1224 | extra = 0 |
| 1225 | verbose_name_plural = "Routers" |
| 1226 | verbose_name = "Router" |
| 1227 | suit_classes = 'suit-tab suit-tab-routers' |
| 1228 | |
| 1229 | fields = ['name', 'owner', 'permittedNetworks', 'networks'] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1230 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1231 | class RouterInline(PlStackTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1232 | model = Router.networks.through |
| 1233 | extra = 0 |
| 1234 | verbose_name_plural = "Routers" |
| 1235 | verbose_name = "Router" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1236 | suit_classes = 'suit-tab suit-tab-routers' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1237 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1238 | class NetworkParameterROInline(ReadOnlyTabularInline): |
| 1239 | model = NetworkParameter |
| 1240 | extra = 1 |
| 1241 | verbose_name_plural = "Parameters" |
| 1242 | verbose_name = "Parameter" |
| 1243 | suit_classes = 'suit-tab suit-tab-netparams' |
| 1244 | fields = ['parameter', 'value', 'content_type', 'object_id', 'content_object'] |
| 1245 | |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1246 | class NetworkParameterInline(generic.GenericTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1247 | model = NetworkParameter |
| 1248 | extra = 1 |
| 1249 | verbose_name_plural = "Parameters" |
| 1250 | verbose_name = "Parameter" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1251 | suit_classes = 'suit-tab suit-tab-netparams' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1252 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1253 | class NetworkSliversROInline(ReadOnlyTabularInline): |
| 1254 | fields = ['network', 'sliver', 'ip', 'port_id'] |
| 1255 | model = NetworkSliver |
| 1256 | extra = 0 |
| 1257 | verbose_name_plural = "Slivers" |
| 1258 | verbose_name = "Sliver" |
| 1259 | suit_classes = 'suit-tab suit-tab-networkslivers' |
| 1260 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1261 | class NetworkSliversInline(PlStackTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1262 | readonly_fields = ("ip", ) |
| 1263 | model = NetworkSliver |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 1264 | selflink_fieldname = "sliver" |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1265 | extra = 0 |
| 1266 | verbose_name_plural = "Slivers" |
| 1267 | verbose_name = "Sliver" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1268 | suit_classes = 'suit-tab suit-tab-networkslivers' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1269 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1270 | class NetworkSlicesROInline(ReadOnlyTabularInline): |
| 1271 | model = NetworkSlice |
| 1272 | extra = 0 |
| 1273 | verbose_name_plural = "Slices" |
| 1274 | verbose_name = "Slice" |
| 1275 | suit_classes = 'suit-tab suit-tab-networkslices' |
| 1276 | fields = ['network','slice'] |
| 1277 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1278 | class NetworkSlicesInline(PlStackTabularInline): |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1279 | model = NetworkSlice |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 1280 | selflink_fieldname = "slice" |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1281 | extra = 0 |
| 1282 | verbose_name_plural = "Slices" |
| 1283 | verbose_name = "Slice" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1284 | suit_classes = 'suit-tab suit-tab-networkslices' |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1285 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1286 | class NetworkAdmin(PlanetStackBaseAdmin): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1287 | list_display = ("name", "subnet", "ports", "labels") |
| 1288 | readonly_fields = ("subnet", ) |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1289 | |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1290 | inlines = [NetworkParameterInline, NetworkSliversInline, NetworkSlicesInline, RouterInline] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1291 | |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1292 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1293 | (None, {'fields': ['name','template','ports','labels','owner','guaranteedBandwidth', 'permitAllSlices','permittedSlices','network_id','router_id','subnet_id','subnet'], 'classes':['suit-tab suit-tab-general']}),] |
| 1294 | |
| 1295 | user_readonly_fields = ['name','template','ports','labels','owner','guaranteedBandwidth', 'permitAllSlices','permittedSlices','network_id','router_id','subnet_id','subnet'] |
| 1296 | user_readonly_inlines = [NetworkParameterROInline, NetworkSliversROInline, NetworkSlicesROInline, RouterROInline] |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1297 | |
| 1298 | suit_form_tabs =( |
| 1299 | ('general','Network Details'), |
| 1300 | ('netparams', 'Parameters'), |
| 1301 | ('networkslivers','Slivers'), |
| 1302 | ('networkslices','Slices'), |
| 1303 | ('routers','Routers'), |
| 1304 | ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1305 | class NetworkTemplateAdmin(PlanetStackBaseAdmin): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1306 | list_display = ("name", "guaranteedBandwidth", "visibility") |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1307 | user_readonly_fields = ["name", "guaranteedBandwidth", "visibility"] |
| 1308 | user_readonly_inlines = [] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1309 | |
Tony Mack | 31c2b8f | 2013-04-26 20:01:42 -0400 | [diff] [blame] | 1310 | # register a signal that caches the user's credentials when they log in |
| 1311 | def cache_credentials(sender, user, request, **kwds): |
| 1312 | auth = {'username': request.POST['username'], |
| 1313 | 'password': request.POST['password']} |
| 1314 | request.session['auth'] = auth |
| 1315 | user_logged_in.connect(cache_credentials) |
| 1316 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1317 | def dollar_field(fieldName, short_description): |
| 1318 | def newFunc(self, obj): |
| 1319 | try: |
| 1320 | x= "$ %0.2f" % float(getattr(obj, fieldName, 0.0)) |
| 1321 | except: |
| 1322 | x=getattr(obj, fieldName, 0.0) |
| 1323 | return x |
| 1324 | newFunc.short_description = short_description |
| 1325 | return newFunc |
| 1326 | |
| 1327 | def right_dollar_field(fieldName, short_description): |
| 1328 | def newFunc(self, obj): |
| 1329 | try: |
| 1330 | #x= '<div align=right style="width:6em">$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0)) |
| 1331 | x= '<div align=right>$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0)) |
| 1332 | except: |
| 1333 | x=getattr(obj, fieldName, 0.0) |
| 1334 | return x |
| 1335 | newFunc.short_description = short_description |
| 1336 | newFunc.allow_tags = True |
| 1337 | return newFunc |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1338 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1339 | class InvoiceChargeInline(PlStackTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1340 | model = Charge |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1341 | extra = 0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1342 | verbose_name_plural = "Charges" |
| 1343 | verbose_name = "Charge" |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1344 | exclude = ['account'] |
Scott Baker | 9cb88a2 | 2013-12-09 18:56:00 -0800 | [diff] [blame] | 1345 | fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1346 | readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1347 | can_delete = False |
| 1348 | max_num = 0 |
| 1349 | |
| 1350 | dollar_amount = right_dollar_field("amount", "Amount") |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1351 | |
| 1352 | class InvoiceAdmin(admin.ModelAdmin): |
| 1353 | list_display = ("date", "account") |
| 1354 | |
| 1355 | inlines = [InvoiceChargeInline] |
| 1356 | |
Scott Baker | 9cb88a2 | 2013-12-09 18:56:00 -0800 | [diff] [blame] | 1357 | fields = ["date", "account", "dollar_amount"] |
| 1358 | readonly_fields = ["date", "account", "dollar_amount"] |
| 1359 | |
| 1360 | dollar_amount = dollar_field("amount", "Amount") |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1361 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1362 | class InvoiceInline(PlStackTabularInline): |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1363 | model = Invoice |
| 1364 | extra = 0 |
| 1365 | verbose_name_plural = "Invoices" |
| 1366 | verbose_name = "Invoice" |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1367 | fields = ["date", "dollar_amount"] |
| 1368 | readonly_fields = ["date", "dollar_amount"] |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1369 | suit_classes = 'suit-tab suit-tab-accountinvoice' |
| 1370 | can_delete=False |
| 1371 | max_num=0 |
| 1372 | |
| 1373 | dollar_amount = right_dollar_field("amount", "Amount") |
| 1374 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1375 | class PendingChargeInline(PlStackTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1376 | model = Charge |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1377 | extra = 0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1378 | verbose_name_plural = "Charges" |
| 1379 | verbose_name = "Charge" |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1380 | exclude = ["invoice"] |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1381 | fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1382 | readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1383 | suit_classes = 'suit-tab suit-tab-accountpendingcharges' |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1384 | can_delete=False |
| 1385 | max_num=0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1386 | |
| 1387 | def queryset(self, request): |
| 1388 | qs = super(PendingChargeInline, self).queryset(request) |
| 1389 | qs = qs.filter(state="pending") |
| 1390 | return qs |
| 1391 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1392 | dollar_amount = right_dollar_field("amount", "Amount") |
| 1393 | |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1394 | class PaymentInline(PlStackTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1395 | model=Payment |
| 1396 | extra = 1 |
| 1397 | verbose_name_plural = "Payments" |
| 1398 | verbose_name = "Payment" |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1399 | fields = ["date", "dollar_amount"] |
| 1400 | readonly_fields = ["date", "dollar_amount"] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1401 | suit_classes = 'suit-tab suit-tab-accountpayments' |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1402 | can_delete=False |
| 1403 | max_num=0 |
| 1404 | |
| 1405 | dollar_amount = right_dollar_field("amount", "Amount") |
| 1406 | |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1407 | class AccountAdmin(admin.ModelAdmin): |
| 1408 | list_display = ("site", "balance_due") |
| 1409 | |
| 1410 | inlines = [InvoiceInline, PaymentInline, PendingChargeInline] |
| 1411 | |
| 1412 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1413 | (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] | 1414 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1415 | readonly_fields = ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1416 | |
| 1417 | suit_form_tabs =( |
| 1418 | ('general','Account Details'), |
| 1419 | ('accountinvoice', 'Invoices'), |
| 1420 | ('accountpayments', 'Payments'), |
| 1421 | ('accountpendingcharges','Pending Charges'), |
| 1422 | ) |
| 1423 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1424 | dollar_balance_due = dollar_field("balance_due", "Balance Due") |
| 1425 | dollar_total_invoices = dollar_field("total_invoices", "Total Invoices") |
| 1426 | dollar_total_payments = dollar_field("total_payments", "Total Payments") |
| 1427 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1428 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1429 | # Now register the new UserAdmin... |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1430 | admin.site.register(User, UserAdmin) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1431 | # ... and, since we're not using Django's builtin permissions, |
| 1432 | # unregister the Group model from admin. |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1433 | #admin.site.unregister(Group) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1434 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 1435 | #Do not show django evolution in the admin interface |
| 1436 | from django_evolution.models import Version, Evolution |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1437 | #admin.site.unregister(Version) |
| 1438 | #admin.site.unregister(Evolution) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 1439 | |
| 1440 | |
| 1441 | # When debugging it is often easier to see all the classes, but for regular use |
| 1442 | # only the top-levels should be displayed |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1443 | showAll = False |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1444 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 1445 | admin.site.register(Deployment, DeploymentAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1446 | admin.site.register(Site, SiteAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1447 | admin.site.register(Slice, SliceAdmin) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1448 | admin.site.register(Service, ServiceAdmin) |
smbaker | a3cf70c | 2013-06-27 02:01:41 -0700 | [diff] [blame] | 1449 | admin.site.register(Reservation, ReservationAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1450 | admin.site.register(Network, NetworkAdmin) |
| 1451 | admin.site.register(Router, RouterAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1452 | admin.site.register(NetworkTemplate, NetworkTemplateAdmin) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1453 | admin.site.register(Account, AccountAdmin) |
| 1454 | admin.site.register(Invoice, InvoiceAdmin) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 1455 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1456 | if True: |
| 1457 | admin.site.register(NetworkParameterType, NetworkParameterTypeAdmin) |
| 1458 | admin.site.register(ServiceClass, ServiceClassAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1459 | #admin.site.register(PlanetStack) |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1460 | admin.site.register(Tag, TagAdmin) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1461 | admin.site.register(DeploymentRole) |
| 1462 | admin.site.register(SiteRole) |
| 1463 | admin.site.register(SliceRole) |
| 1464 | admin.site.register(PlanetStackRole) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 1465 | admin.site.register(Node, NodeAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1466 | #admin.site.register(SlicePrivilege, SlicePrivilegeAdmin) |
| 1467 | #admin.site.register(SitePrivilege, SitePrivilegeAdmin) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 1468 | admin.site.register(Sliver, SliverAdmin) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 1469 | admin.site.register(Image, ImageAdmin) |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1470 | admin.site.register(DashboardView, DashboardViewAdmin) |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 1471 | |