[CORD-2640] Creating and deleting eNodeB
Change-Id: I5acc72415acfb29e096337cff450441878383e6a
diff --git a/xos/models/models.py b/xos/models/models.py
index 2e7df7b..594255a 100644
--- a/xos/models/models.py
+++ b/xos/models/models.py
@@ -15,6 +15,14 @@
class ProgranService(ProgranService_decl):
class Meta:
proxy = True
+ def save(self, *args, **kwargs):
+
+ existing_services = ProgranService.objects.all()
+
+ if len(existing_services) > 0 and not self.delete:
+ raise XOSValidationError("A ProgranService already exists, you should not have more than one")
+
+ super(ProgranService, self).save(*args, **kwargs)
class ENodeB(ENodeB_decl):
@@ -33,19 +41,18 @@
def save(self, *args, **kwargs):
# NOTE someone is setting owner_id, so just override it for now
- # if not self.owner_id:
- services = Service.objects.all()
- services = [s for s in services if s.name.lower() == 'progran']
-
- # NOTE select the correct owner
try:
- progran_service = services[0]
+ # NOTE we allow just one ProgranService
+ progran_service = ProgranService.objects.all()[0]
self.owner_id = progran_service.id
except IndexError:
raise XOSValidationError("Service Progran cannot be found, please make sure that the model exists.")
# NOTE if the instance is new, check that the name is not duplicated
instances_with_same_name = None
+ # FIXME This may leave us vulnerable to someone changing the name at a later time and causing a conflict.
+ # If that's important to prevent, we could prevent that case when `self.pk!=None`,
+ # filter for ProgranServiceInstance with the same name but `pk!=self.pk`.
if self.pk is None:
try:
instances_with_same_name = ProgranServiceInstance.objects.get(name=self.name)
diff --git a/xos/models/progran.xproto b/xos/models/progran.xproto
index 14206ac..909f6e1 100644
--- a/xos/models/progran.xproto
+++ b/xos/models/progran.xproto
@@ -43,8 +43,8 @@
required string end = 6 [content_type = "date", null = False, blank = True];
required string AdmControl = 7 [default = "0", choices = "(('0', 'ALL'), ('1', 'Voice Only'), ('2', 'Data Only'))", max_length = 1, blank = False, null = False, db_index = False];
required int32 CellIndividualOffset = 8 [db_index = False, null = False, blank = False];
- required manytoone enodeb->ENodeB:profiles = 9 [db_index = True, null = False, blank = False];
- required manytoone handover->Handover:profiles = 10 [db_index = True, null = True, blank = False];
+ required manytoone enodeb->ENodeB:profiles = 9 [null = True, blank = True];
+ required manytoone handover->Handover:profiles = 10 [null = False, blank = False];
}