|
@@ -1,6 +1,9 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
import ldapdb.models
|
|
|
-import pprint, os #, base64, hashlib
|
|
|
+#import pprint
|
|
|
+import os
|
|
|
+#import base64
|
|
|
+#import hashlib
|
|
|
from django.db import models
|
|
|
from ldapdb.models.fields import CharField, IntegerField, ListField
|
|
|
from django.db.models.signals import post_save, pre_save
|
|
@@ -11,92 +14,115 @@ from django.core import exceptions
|
|
|
|
|
|
|
|
|
class LdapUser(ldapdb.models.Model):
|
|
|
- base_dn = "ou=users,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR" #TODO déplacer dans settings.py
|
|
|
+ # TODO: déplacer ligne suivante dans settings.py
|
|
|
+ base_dn = "ou=users,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
|
|
|
object_classes = ['inetOrgPerson', 'organizationalPerson', 'person', 'top']
|
|
|
|
|
|
- uid = CharField(db_column='uid', unique=True,max_length=255)
|
|
|
- nick_name = CharField(db_column='cn', unique=True, primary_key=True,max_length=255)
|
|
|
- first_name = CharField(db_column='givenName',max_length=255)
|
|
|
- last_name = CharField(db_column='sn',max_length=255)
|
|
|
- display_name = CharField(db_column='displayName',max_length=255, blank=True)
|
|
|
- password = CharField(db_column='userPassword',max_length=255)
|
|
|
+ uid = CharField(db_column='uid', unique=True, max_length=255)
|
|
|
+ nick_name = CharField(db_column='cn', unique=True, primary_key=True,
|
|
|
+ max_length=255)
|
|
|
+ first_name = CharField(db_column='givenName', max_length=255)
|
|
|
+ last_name = CharField(db_column='sn', max_length=255)
|
|
|
+ display_name = CharField(db_column='displayName', max_length=255,
|
|
|
+ blank=True)
|
|
|
+ password = CharField(db_column='userPassword', max_length=255)
|
|
|
|
|
|
def __unicode__(self):
|
|
|
return self.display_name
|
|
|
-
|
|
|
+
|
|
|
class Meta:
|
|
|
- managed = False #Indique à South de ne pas gérer ce model
|
|
|
+ managed = False # Indique à South de ne pas gérer ce model
|
|
|
+
|
|
|
+# Indique à South de ne pas gérer ce model
|
|
|
+add_ignored_fields(["^ldapdb\.models\.fields"])
|
|
|
|
|
|
-add_ignored_fields(["^ldapdb\.models\.fields"]) #Indique à South de ne pas gérer ce model
|
|
|
|
|
|
class Member(models.Model):
|
|
|
|
|
|
- MEMBER_TYPE_CHOICES =(('personne_physique','Personne physique'),('personne_morale','Personne morale'))
|
|
|
- MEMBER_STATUS_CHOICES = (('adherent','Adhérent'),('non_adherent','Non adhérent'),('demande_adhesion','Demande d\'adhésion'))
|
|
|
-
|
|
|
- status = models.CharField(max_length=50, choices=MEMBER_STATUS_CHOICES, default='non_adherent');
|
|
|
- type = models.CharField(max_length=20, choices=MEMBER_TYPE_CHOICES, default='personne_physique');
|
|
|
- first_name = models.CharField(max_length=200);
|
|
|
- last_name = models.CharField(max_length=200);
|
|
|
- ldap_cn = models.CharField(max_length=200, blank=True);
|
|
|
- organization_name = models.CharField(max_length=200, blank=True);
|
|
|
- email = models.EmailField(max_length=254);
|
|
|
- home_phone_number = models.CharField(max_length=25, blank=True);
|
|
|
- mobile_phone_number = models.CharField(max_length=25, blank=True);
|
|
|
- address = models.TextField();
|
|
|
- postal_code = models.CharField(max_length=15);
|
|
|
- city = models.CharField(max_length=200);
|
|
|
- country = models.CharField(max_length=200);
|
|
|
- entry_date = models.DateField(null=False, blank=False, default=datetime.date.today);
|
|
|
- resign_date = models.DateField(null=True, blank=True);
|
|
|
-
|
|
|
+ MEMBER_TYPE_CHOICES = (
|
|
|
+ ('personne_physique', 'Personne physique'),
|
|
|
+ ('personne_morale', 'Personne morale'),
|
|
|
+ )
|
|
|
+ MEMBER_STATUS_CHOICES = (
|
|
|
+ ('adherent', 'Adhérent'),
|
|
|
+ ('non_adherent', 'Non adhérent'),
|
|
|
+ ('demande_adhesion', "Demande d'adhésion"),
|
|
|
+ )
|
|
|
+
|
|
|
+ status = models.CharField(max_length=50, choices=MEMBER_STATUS_CHOICES,
|
|
|
+ default='non_adherent')
|
|
|
+ type = models.CharField(max_length=20, choices=MEMBER_TYPE_CHOICES,
|
|
|
+ default='personne_physique')
|
|
|
+ first_name = models.CharField(max_length=200)
|
|
|
+ last_name = models.CharField(max_length=200)
|
|
|
+ ldap_cn = models.CharField(max_length=200, blank=True)
|
|
|
+ organization_name = models.CharField(max_length=200, blank=True)
|
|
|
+ email = models.EmailField(max_length=254)
|
|
|
+ home_phone_number = models.CharField(max_length=25, blank=True)
|
|
|
+ mobile_phone_number = models.CharField(max_length=25, blank=True)
|
|
|
+ address = models.TextField()
|
|
|
+ postal_code = models.CharField(max_length=15)
|
|
|
+ city = models.CharField(max_length=200)
|
|
|
+ country = models.CharField(max_length=200)
|
|
|
+ entry_date = models.DateField(null=False, blank=False,
|
|
|
+ default=datetime.date.today)
|
|
|
+ resign_date = models.DateField(null=True, blank=True)
|
|
|
+
|
|
|
def __unicode__(self):
|
|
|
- return self.first_name+' '+self.last_name;
|
|
|
+ return self.first_name + ' ' + self.last_name
|
|
|
|
|
|
|
|
|
class CryptoKey(models.Model):
|
|
|
-
|
|
|
- KEY_TYPE_CHOICES=(('RSA','RSA'),('GPG','GPG'))
|
|
|
-
|
|
|
- type = models.CharField(max_length=3, choices=KEY_TYPE_CHOICES);
|
|
|
- key = models.TextField();
|
|
|
- member = models.ForeignKey('Member');
|
|
|
+
|
|
|
+ KEY_TYPE_CHOICES = (('RSA', 'RSA'), ('GPG', 'GPG'))
|
|
|
+
|
|
|
+ type = models.CharField(max_length=3, choices=KEY_TYPE_CHOICES)
|
|
|
+ key = models.TextField()
|
|
|
+ member = models.ForeignKey('Member')
|
|
|
|
|
|
def __unicode__(self):
|
|
|
- return self.member.__str__();
|
|
|
+ return self.member.__str__()
|
|
|
+
|
|
|
|
|
|
class MembershipFee(models.Model):
|
|
|
- member = models.ForeignKey('Member');
|
|
|
- amount = models.IntegerField(null=False, default='20');
|
|
|
- start_date = models.DateField(null=False, blank=False, default=datetime.date.today);
|
|
|
- end_date = models.DateField(null=False, blank=False, default=datetime.date.today() + datetime.timedelta(365));
|
|
|
+ member = models.ForeignKey('Member')
|
|
|
+ amount = models.IntegerField(null=False, default='20')
|
|
|
+ start_date = models.DateField(null=False, blank=False,
|
|
|
+ default=datetime.date.today)
|
|
|
+ end_date = models.DateField(
|
|
|
+ null=False, blank=False,
|
|
|
+ default=datetime.date.today() + datetime.timedelta(365))
|
|
|
+
|
|
|
|
|
|
-#~ Lors de la sauvegarde d'un membre, cette fonction est exécutée pour mettre à jour les données dans le LDAP
|
|
|
@receiver(post_save, sender=Member)
|
|
|
def sync_ldap(sender, instance, created, **kwargs):
|
|
|
+ """
|
|
|
+ Update LDAP data when a member is saved
|
|
|
+ """
|
|
|
|
|
|
if not created:
|
|
|
# try:
|
|
|
ldap_user = LdapUser.objects.get(pk=instance.ldap_cn)
|
|
|
# except exceptions.ObjectDoesNotExist:
|
|
|
# created = True
|
|
|
-
|
|
|
+
|
|
|
if created:
|
|
|
ldap_user = LdapUser()
|
|
|
ldap_user.pk = instance.ldap_cn
|
|
|
ldap_user.uid = instance.ldap_cn
|
|
|
ldap_user.nick_name = instance.ldap_cn
|
|
|
-
|
|
|
+
|
|
|
ldap_user.last_name = instance.last_name
|
|
|
- ldap_user.first_name = instance.first_name
|
|
|
+ ldap_user.first_name = instance.first_name
|
|
|
# ldap_user.password = instance.password
|
|
|
- ldap_user.save();
|
|
|
+ ldap_user.save()
|
|
|
|
|
|
|
|
|
-#===============================================================================
|
|
|
+#==============================================================================
|
|
|
# @receiver(pre_save, sender = LdapUser)
|
|
|
# def ssha_password(sender, **kwargs):
|
|
|
# if not kwargs['instance'].password.startswith('{SSHA}'):
|
|
|
# salt = os.urandom(8).encode('hex')
|
|
|
-# kwargs['instance'].password = '{SSHA}' + base64.b64encode(hashlib.sha1(obj.password + salt).digest() + salt)
|
|
|
-#===============================================================================
|
|
|
+# kwargs['instance'].password = '{SSHA}' + base64.b64encode(
|
|
|
+ # hashlib.sha1(obj.password + salt).digest() + salt)
|
|
|
+#==============================================================================
|