Browse Source

Change CoinLdapSyncModel to a Mixin class because it's more appropriate (This just add/modify method to somes models, it's more a role than a type of object)

Fabs 10 years ago
parent
commit
37440ecf8d
4 changed files with 7 additions and 14 deletions
  1. 2 2
      coin/members/models.py
  2. 3 8
      coin/models.py
  3. 0 2
      coin/reverse_dns/models.py
  4. 2 2
      coin/vpn/models.py

+ 2 - 2
coin/members/models.py

@@ -10,13 +10,13 @@ from django.dispatch import receiver
 from ldapdb.models.fields import CharField, IntegerField, ListField
 from south.modelsinspector import add_ignored_fields
 from coin.offers.models import OfferSubscription
-from coin.models import CoinLdapSyncModel
+from coin.mixins import CoinLdapSyncMixin
 from coin import utils
 from django.contrib.auth.signals import user_logged_in
 from django.conf import settings
 
 
-class Member(CoinLdapSyncModel):
+class Member(CoinLdapSyncMixin, models.Model):
 
     MEMBER_TYPE_CHOICES = (
         ('personne_physique', 'Personne physique'),

+ 3 - 8
coin/models.py

@@ -1,9 +1,8 @@
 # -*- coding: utf-8 -*-
-from django.db import models
 from django.db import transaction
 
 
-class CoinLdapSyncModel(models.Model):
+class CoinLdapSyncMixin(object):
 
     """
     Ce modèle abstrait est à utiliser lorsqu'il s'agit de définir un modèle
@@ -28,7 +27,7 @@ class CoinLdapSyncModel(models.Model):
         creation = (self.pk == None)
 
         # Sauvegarde en base de donnée (mais sans commit, cf decorator)
-        super(CoinLdapSyncModel, self).save(*args, **kwargs)
+        super(CoinLdapSyncMixin, self).save(*args, **kwargs)
 
         # Sauvegarde dans le LDAP
         # Si la sauvegarde LDAP échoue, Rollback la sauvegarde en base, sinon
@@ -41,13 +40,9 @@ class CoinLdapSyncModel(models.Model):
     @transaction.atomic
     def delete(self, *args, **kwargs):
         # Supprime de la base de donnée (mais sans commit, cf decorator)
-        super(CoinLdapSyncModel, self).delete(*args, **kwargs)
+        super(CoinLdapSyncMixin, self).delete(*args, **kwargs)
 
         try:
             self.delete_from_ldap()
         except:
             raise
-
-
-    class Meta:
-        abstract = True

+ 0 - 2
coin/reverse_dns/models.py

@@ -7,8 +7,6 @@ from netaddr import IPAddress
 import ldapdb.models
 from ldapdb.models.fields import CharField, IntegerField, ListField
 
-from coin.models import CoinLdapSyncModel
-
 # TODO: validate DNS names with this regex
 REGEX = r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,})\.?$'
 

+ 2 - 2
coin/vpn/models.py

@@ -5,14 +5,14 @@ from netfields import InetAddressField, NetManager
 import ldapdb.models
 from ldapdb.models.fields import CharField, ListField
 
-from coin.models import CoinLdapSyncModel
+from coin.mixins import CoinLdapSyncMixin
 from coin.offers.models import OfferSubscription
 from coin.offers.backends import ValidateBackendType
 from coin import utils
 from coin import validation
 
 
-class VPNSubscription(CoinLdapSyncModel):
+class VPNSubscription(CoinLdapSyncMixin, models.Model):
     backend_name = "openvpn_ldap"
     administrative_subscription = models.OneToOneField(
         'offers.OfferSubscription',