|
@@ -11,30 +11,19 @@ from coin.resources.models import IPSubnet
|
|
class Offer(models.Model):
|
|
class Offer(models.Model):
|
|
"""Description of an offer available to subscribers.
|
|
"""Description of an offer available to subscribers.
|
|
|
|
|
|
- Implementation notes: achieving genericity is difficult, especially
|
|
|
|
- because different technologies may have very different configuration
|
|
|
|
- parameters.
|
|
|
|
-
|
|
|
|
- Technology-specific configuration (e.g. for VPN) is implemented as a
|
|
|
|
- model having a OneToOne relation to OfferSubscription. In order to
|
|
|
|
- reach the technology-specific configuration model from an
|
|
|
|
- OfferSubscription, the OneToOne relation MUST have a related_name
|
|
|
|
- equal to one of the backends in OFFER_BACKEND_CHOICES (for instance
|
|
|
|
- "openvpn_ldap").
|
|
|
|
-
|
|
|
|
|
|
+ Implementation notes:
|
|
|
|
+ configuration_type store the model name of the configuration backend
|
|
|
|
+ (ex VPNConfiguration).
|
|
|
|
+ The choices list is dynamically generated at start in the __init__
|
|
"""
|
|
"""
|
|
- # OFFER_BACKEND_CHOICES = (
|
|
|
|
- # ('openvpn_ldap', 'OpenVPN (LDAP)'),
|
|
|
|
- # # Use this if you don't actually want to implement a backend, for
|
|
|
|
- # # instance if you resell somebody else's offers and don't manage
|
|
|
|
- # # technical information yourself.
|
|
|
|
- # ('none', 'None'),
|
|
|
|
- # )
|
|
|
|
|
|
+
|
|
def __init__(self, *args, **kwargs):
|
|
def __init__(self, *args, **kwargs):
|
|
from coin.configuration.models import Configuration
|
|
from coin.configuration.models import Configuration
|
|
super(Offer, self).__init__(*args, **kwargs)
|
|
super(Offer, self).__init__(*args, **kwargs)
|
|
- """Génère automatiquement la liste de choix possibles de types
|
|
|
|
- de configurations en fonction des classes enfants de Configuration"""
|
|
|
|
|
|
+ """
|
|
|
|
+ Génère automatiquement la liste de choix possibles de types
|
|
|
|
+ de configurations en fonction des classes enfants de Configuration
|
|
|
|
+ """
|
|
self._meta.get_field_by_name('configuration_type')[0]._choices = (
|
|
self._meta.get_field_by_name('configuration_type')[0]._choices = (
|
|
Configuration.get_configurations_choices_list())
|
|
Configuration.get_configurations_choices_list())
|
|
|
|
|
|
@@ -56,9 +45,6 @@ class Offer(models.Model):
|
|
blank=False, null=False,
|
|
blank=False, null=False,
|
|
verbose_name='Frais de mise en service',
|
|
verbose_name='Frais de mise en service',
|
|
help_text='en €')
|
|
help_text='en €')
|
|
- # TODO: really ensure that this field does not change (as it would
|
|
|
|
- # seriously break subscriptions)
|
|
|
|
- # backend = models.CharField(max_length=50, choices=OFFER_BACKEND_CHOICES)
|
|
|
|
|
|
|
|
def get_configuration_type_display(self):
|
|
def get_configuration_type_display(self):
|
|
"""
|
|
"""
|
|
@@ -84,13 +70,9 @@ class OfferSubscription(models.Model):
|
|
"""Only contains administrative details about a subscription, not
|
|
"""Only contains administrative details about a subscription, not
|
|
technical. Nothing here should end up into the LDAP backend.
|
|
technical. Nothing here should end up into the LDAP backend.
|
|
|
|
|
|
- Implementation notes: the model actually implementing the backend
|
|
|
|
- (technical configuration for the technology) MUST relate to this class
|
|
|
|
- with a OneToOneField whose related name is a member of
|
|
|
|
- OFFER_BACKEND_CHOICES, for instance:
|
|
|
|
-
|
|
|
|
- models.OneToOneField('offers.OfferSubscription', related_name="openvpn_ldap")
|
|
|
|
-
|
|
|
|
|
|
+ Implementation notes: the Configuration model (which actually implementing the backend
|
|
|
|
+ (technical configuration for the technology)) relate to this class
|
|
|
|
+ with a OneToOneField
|
|
"""
|
|
"""
|
|
subscription_date = models.DateField(
|
|
subscription_date = models.DateField(
|
|
null=False,
|
|
null=False,
|
|
@@ -111,21 +93,9 @@ class OfferSubscription(models.Model):
|
|
member = models.ForeignKey('members.Member', verbose_name='Membre')
|
|
member = models.ForeignKey('members.Member', verbose_name='Membre')
|
|
offer = models.ForeignKey('Offer', verbose_name='Offre')
|
|
offer = models.ForeignKey('Offer', verbose_name='Offre')
|
|
|
|
|
|
- # @property
|
|
|
|
- # def configuration(self):
|
|
|
|
- # """Returns the configuration object associated to this subscription,
|
|
|
|
- # according to the backend type specified in the offer. Yes, this
|
|
|
|
- # is hand-made genericity. If you can think of a better way, feel
|
|
|
|
- # free to propose something.
|
|
|
|
- # """
|
|
|
|
- # if self.offer.backend == 'none' or not hasattr(self, self.offer.backend):
|
|
|
|
- # return
|
|
|
|
- # return getattr(self, self.offer.backend)
|
|
|
|
-
|
|
|
|
def __unicode__(self):
|
|
def __unicode__(self):
|
|
- return u'%s - %s - %s - %s' % (self.member, self.offer.name,
|
|
|
|
- self.subscription_date,
|
|
|
|
- self.offer.configuration_type)
|
|
|
|
|
|
+ return u'%s - %s - %s' % (self.member, self.offer.name,
|
|
|
|
+ self.subscription_date)
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
verbose_name = 'abonnement'
|
|
verbose_name = 'abonnement'
|