|
@@ -17,7 +17,7 @@ technical informations of a subscription.
|
|
|
|
|
|
To add a new configuration backend, you have to create a new app with a model
|
|
To add a new configuration backend, you have to create a new app with a model
|
|
which inherit from Configuration.
|
|
which inherit from Configuration.
|
|
-Your model can implement Meta verbose_name to have human readable name and a
|
|
|
|
|
|
+Your model can implement Meta verbose_name to have human readable name and a
|
|
url_namespace variable to specify the url namespace used by this model.
|
|
url_namespace variable to specify the url namespace used by this model.
|
|
"""
|
|
"""
|
|
|
|
|
|
@@ -35,9 +35,9 @@ class Configuration(PolymorphicModel):
|
|
Génère automatiquement la liste de choix possibles de configurations
|
|
Génère automatiquement la liste de choix possibles de configurations
|
|
en fonction des classes enfants de Configuration
|
|
en fonction des classes enfants de Configuration
|
|
"""
|
|
"""
|
|
- return tuple((x().__class__.__name__,x()._meta.verbose_name)
|
|
|
|
|
|
+ return tuple((x().__class__.__name__,x()._meta.verbose_name)
|
|
for x in Configuration.__subclasses__())
|
|
for x in Configuration.__subclasses__())
|
|
-
|
|
|
|
|
|
+
|
|
def model_name(self):
|
|
def model_name(self):
|
|
return self.__class__.__name__
|
|
return self.__class__.__name__
|
|
model_name.short_description = 'Nom du modèle'
|
|
model_name.short_description = 'Nom du modèle'
|
|
@@ -52,7 +52,7 @@ class Configuration(PolymorphicModel):
|
|
Une url doit être nommée "details"
|
|
Une url doit être nommée "details"
|
|
"""
|
|
"""
|
|
from django.core.urlresolvers import reverse
|
|
from django.core.urlresolvers import reverse
|
|
- return reverse('%s:details' % self.get_url_namespace(),
|
|
|
|
|
|
+ return reverse('%s:details' % self.get_url_namespace(),
|
|
args=[str(self.id)])
|
|
args=[str(self.id)])
|
|
|
|
|
|
def get_url_namespace(self):
|
|
def get_url_namespace(self):
|
|
@@ -66,10 +66,33 @@ class Configuration(PolymorphicModel):
|
|
else:
|
|
else:
|
|
return self.model_name().lower()
|
|
return self.model_name().lower()
|
|
|
|
|
|
|
|
+ def save(self, **kwargs):
|
|
|
|
+ self.clean()
|
|
|
|
+ os = self.offersubscription
|
|
|
|
+ for offer_ip_pool in os.offer.offerippool_set.order_by('-to_assign'):
|
|
|
|
+ IPSubnet.objects.create(
|
|
|
|
+ configuration=self,
|
|
|
|
+ ip_pool=offer_ip_pool.ip_pool)
|
|
|
|
+ return super(Configuration, self).save(**kwargs)
|
|
|
|
+
|
|
class Meta:
|
|
class Meta:
|
|
verbose_name = 'configuration'
|
|
verbose_name = 'configuration'
|
|
|
|
|
|
|
|
|
|
|
|
+@receiver(post_save, sender=OfferSubscription)
|
|
|
|
+def offer_subscription_event(sender, **kwargs):
|
|
|
|
+ os = kwargs['instance']
|
|
|
|
+
|
|
|
|
+ if not hasattr(os, 'configuration'):
|
|
|
|
+ config_cls = None
|
|
|
|
+ for subconfig_cls in Configuration.__subclasses__():
|
|
|
|
+ if subconfig_cls().__class__.__name__ == os.offer.configuration_type:
|
|
|
|
+ config_cls = subconfig_cls
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ if config_cls is not None:
|
|
|
|
+ config = config_cls.objects.create(offersubscription=os)
|
|
|
|
+
|
|
@receiver(post_save, sender=IPSubnet)
|
|
@receiver(post_save, sender=IPSubnet)
|
|
@receiver(post_delete, sender=IPSubnet)
|
|
@receiver(post_delete, sender=IPSubnet)
|
|
def subnet_event(sender, **kwargs):
|
|
def subnet_event(sender, **kwargs):
|