refactor
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index 2dbf2c4..853e5ce 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -394,6 +394,19 @@
class PlanetStackBaseAdmin(ReadOnlyAwareAdmin):
save_on_top = False
+
+ def save_model(self, request, obj, form, change):
+ # update openstack connection to use this site/tenant
+ obj.save_by_user(request.user)
+
+ def delete_model(self, request, obj):
+ obj.delete_by_user(request.user)
+
+ def save_formset(self, request, form, formset, change):
+ instances = formset.save(commit=False)
+ for instance in instances:
+ instance.save_by_user(request.user)
+ formset.save_m2m()
class SliceRoleAdmin(PlanetStackBaseAdmin):
model = SliceRole
@@ -532,6 +545,13 @@
accountLink.allow_tags = True
accountLink.short_description = "Billing"
+ def save_model(self, request, obj, form, change):
+ # update openstack connection to use this site/tenant
+ obj.save_by_user(request.user)
+
+ def delete_model(self, request, obj):
+ obj.delete_by_user(request.user)
+
class SitePrivilegeAdmin(PlanetStackBaseAdmin):
fieldList = ['user', 'site', 'role']
diff --git a/planetstack/core/models/deployment.py b/planetstack/core/models/deployment.py
index ea77dea..b97432b 100644
--- a/planetstack/core/models/deployment.py
+++ b/planetstack/core/models/deployment.py
@@ -44,10 +44,6 @@
return True
return False
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(DeploymentPrivilege, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
diff --git a/planetstack/core/models/network.py b/planetstack/core/models/network.py
index 7b9364c..23ef6ea 100644
--- a/planetstack/core/models/network.py
+++ b/planetstack/core/models/network.py
@@ -53,10 +53,6 @@
def can_update(self, user):
return self.slice.can_update(user)
- def save_by_user(self, user, *args, **kwds):
- if self.slice.can_update(user):
- super(Network, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
@@ -89,10 +85,6 @@
def can_update(self, user):
return self.slice.can_update(user)
- def save_by_user(self, user, *args, **kwds):
- if self.slice.can_update(user):
- super(NetworkSlice, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
@@ -128,10 +120,6 @@
def can_update(self, user):
return self.sliver.can_update(user)
- def save_by_user(self, user, *args, **kwds):
- if self.sliver.can_update(user):
- super(NetworkSliver, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
diff --git a/planetstack/core/models/plcorebase.py b/planetstack/core/models/plcorebase.py
index 9838d7f..8c5bddc 100644
--- a/planetstack/core/models/plcorebase.py
+++ b/planetstack/core/models/plcorebase.py
@@ -70,6 +70,10 @@
if self.can_update(user):
self.save(*args, **kwds)
+ def delete_by_user(self, user, *args, **kwds):
+ if self.can_update(user):
+ self.delete(*args, **kwds)
+
@property
def _dict(self):
return model_to_dict(self, fields=[field.name for field in
diff --git a/planetstack/core/models/reservation.py b/planetstack/core/models/reservation.py
index e89b4c8..db3769f 100644
--- a/planetstack/core/models/reservation.py
+++ b/planetstack/core/models/reservation.py
@@ -22,10 +22,6 @@
def can_update(self, user):
return self.slice.can_update(user)
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(Reservation, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
@@ -49,10 +45,6 @@
def can_update(self, user):
return self.sliver.slice.can_update(user)
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(ReservedResource, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
diff --git a/planetstack/core/models/site.py b/planetstack/core/models/site.py
index 8e77404..34699d8 100644
--- a/planetstack/core/models/site.py
+++ b/planetstack/core/models/site.py
@@ -36,10 +36,6 @@
return True
return False
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(Site, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
@@ -81,10 +77,6 @@
return True
return False
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(SitePrivilege, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
@@ -127,10 +119,6 @@
return True
return False
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(DeploymentPrivilege, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
diff --git a/planetstack/core/models/slice.py b/planetstack/core/models/slice.py
index 533165f..823b1d1 100644
--- a/planetstack/core/models/slice.py
+++ b/planetstack/core/models/slice.py
@@ -53,11 +53,6 @@
return True
return False
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(Slice, self).save(*args, **kwds)
-
-
@staticmethod
def select_by_user(user):
if user.is_admin:
@@ -90,10 +85,6 @@
return True
return False
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(SlicePrivilege, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
diff --git a/planetstack/core/models/slicetag.py b/planetstack/core/models/slicetag.py
index e815721..ea1d026 100644
--- a/planetstack/core/models/slicetag.py
+++ b/planetstack/core/models/slicetag.py
@@ -13,10 +13,6 @@
def can_update(self, user):
return self.slice.can_update(user)
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(SliceTag, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
diff --git a/planetstack/core/models/sliver.py b/planetstack/core/models/sliver.py
index 1c4a134..29ae0d4 100644
--- a/planetstack/core/models/sliver.py
+++ b/planetstack/core/models/sliver.py
@@ -47,10 +47,6 @@
def can_update(self, user):
return self.slice.can_update(user)
- def save_by_user(self, user, *args, **kwds):
- if self.slice.can_update(user):
- super(Sliver, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
if user.is_admin:
diff --git a/planetstack/core/models/tag.py b/planetstack/core/models/tag.py
index ef746da..7818c32 100644
--- a/planetstack/core/models/tag.py
+++ b/planetstack/core/models/tag.py
@@ -28,10 +28,6 @@
return True
return False
- def save_by_user(self, user, *args, **kwds):
- if self.can_update(user):
- super(Tag, self).save(*args, **kwds)
-
@staticmethod
def select_by_user(user):
return Tag.objects.all()