| from xos.exceptions import XOSValidationError |
| |
| from models_decl import ProgranService_decl |
| from models_decl import ENodeB_decl |
| from models_decl import Handover_decl |
| from models_decl import ProgranServiceInstance_decl |
| |
| |
| |
| |
| |
| |
| |
| 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): |
| class Meta: |
| proxy = True |
| |
| ## TODO do not allow enbId duplicates |
| |
| |
| class Handover(Handover_decl): |
| class Meta: |
| proxy = True |
| |
| |
| class ProgranServiceInstance(ProgranServiceInstance_decl): |
| class Meta: |
| proxy = True |
| |
| def save(self, *args, **kwargs): |
| # NOTE someone is setting owner_id, so just override it for now |
| try: |
| # 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) |
| except self.DoesNotExist: |
| # it's ok not to find anything here |
| pass |
| |
| if instances_with_same_name: |
| raise XOSValidationError("A ProgranServiceInstance with name '%s' already exists" % self.name) |
| super(ProgranServiceInstance, self).save(*args, **kwargs) |
| |
| |