Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index 1952890..34a77c0 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -738,6 +738,9 @@
cleaned_data = super(SliceForm, self).clean()
name = cleaned_data.get('name')
site = cleaned_data.get('site')
+ slice_id = self.instance.id
+ if not site and slice_id:
+ site = Slice.objects.get(id=slice_id).site
if (not isinstance(site,Site)):
# previous code indicates 'site' could be a site_id and not a site?
site = Slice.objects.get(id=site.id)
@@ -781,6 +784,18 @@
tabs.append( ('admin-only', 'Admin-Only') )
return tabs
+
+ def add_view(self, request, form_url='', extra_context=None):
+ # revert to default read-only fields
+ self.readonly_fields = ('backend_status_text',)
+ return super(SliceAdmin, self).add_view(request, form_url, extra_context=extra_context)
+
+ def change_view(self, request, object_id, form_url='', extra_context=None):
+ print object_id
+ # cannot change the site of an existing slice so make the site field read only
+ if object_id:
+ self.readonly_fields = ('backend_status_text','site')
+ return super(SliceAdmin, self).change_view(request, object_id, form_url)
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
deployment_nodes = []
diff --git a/planetstack/core/models/slice.py b/planetstack/core/models/slice.py
index 7915d42..7412fe2 100644
--- a/planetstack/core/models/slice.py
+++ b/planetstack/core/models/slice.py
@@ -87,6 +87,13 @@
qs = Slice.objects.filter(id__in=slice_ids)
return qs
+ def delete(self, *args, **kwds):
+ # delete networks associated with this slice
+ from core.models.network import Network
+ nets = Network.objects.filter(slices=self)
+ nets.delete()
+ super(SliceAdmin, self).delete(*args, **kwds)
+
class SliceRole(PlCoreBase):
ROLE_CHOICES = (('admin','Admin'),('default','Default'))