|
@@ -3,6 +3,7 @@ from django.db import models
|
|
|
from polymorphic import PolymorphicModel
|
|
|
from coin.offers.models import OfferSubscription
|
|
|
from django.db.models.signals import post_save, post_delete
|
|
|
+from django.core.exceptions import ObjectDoesNotExist
|
|
|
from django.dispatch import receiver
|
|
|
|
|
|
from coin.resources.models import IPSubnet
|
|
@@ -80,9 +81,12 @@ def subnet_save_event(sender, **kwargs):
|
|
|
Django signals.
|
|
|
"""
|
|
|
subnet = kwargs['instance']
|
|
|
- config = subnet.configuration
|
|
|
- if config:
|
|
|
+ try:
|
|
|
+ config = subnet.configuration
|
|
|
config.save_subnet(subnet, kwargs['created'])
|
|
|
+ except ObjectDoesNotExist:
|
|
|
+ pass
|
|
|
+
|
|
|
|
|
|
@receiver(post_delete, sender=IPSubnet)
|
|
|
def subnet_delete_event(sender, **kwargs):
|
|
@@ -90,6 +94,8 @@ def subnet_delete_event(sender, **kwargs):
|
|
|
do whatever it needs to do with it.
|
|
|
"""
|
|
|
subnet = kwargs['instance']
|
|
|
- config = subnet.configuration
|
|
|
- if config:
|
|
|
+ try:
|
|
|
+ config = subnet.configuration
|
|
|
config.delete_subnet(subnet)
|
|
|
+ except ObjectDoesNotExist:
|
|
|
+ pass
|