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