[lc_ldap, objets] Création des objets ldap avec un lockid bien a eux
This commit is contained in:
parent
4f88ae824a
commit
955a4f2820
2 changed files with 55 additions and 49 deletions
40
objets.py
40
objets.py
|
@ -72,7 +72,7 @@ crans_account_attribs = [attributs.uid, attributs.canonicalAlias, attributs.sold
|
|||
attributs.mailAlias, attributs.cn, attributs.rewriteMailHeaders,
|
||||
attributs.mailExt, attributs.compteWiki, attributs.droits]
|
||||
|
||||
def new_cransldapobject(conn, dn, mode='ro', uldif=None):
|
||||
def new_cransldapobject(conn, dn, mode='ro', uldif=None, lockId=None):
|
||||
"""Crée un objet :py:class:`CransLdapObject` en utilisant la classe correspondant à
|
||||
l'``objectClass`` du ``ldif``
|
||||
--pour usage interne à la librairie uniquement !"""
|
||||
|
@ -92,7 +92,7 @@ def new_cransldapobject(conn, dn, mode='ro', uldif=None):
|
|||
_, attrs = res[0]
|
||||
classe = ObjectFactory.get(attrs['objectClass'][0])
|
||||
|
||||
return classe(conn, dn, mode, uldif)
|
||||
return classe(conn, dn, mode, uldif, lockId=lockId)
|
||||
|
||||
class CransLdapObject(object):
|
||||
"""Classe de base des objets :py:class:`CransLdap`.
|
||||
|
@ -106,11 +106,7 @@ class CransLdapObject(object):
|
|||
|
||||
attribs = []
|
||||
|
||||
@property
|
||||
def lockId(self):
|
||||
return '%s_%s' % (os.getpid(), id(self))
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', uldif=None):
|
||||
def __init__(self, conn, dn, mode='ro', uldif=None, lockId=None):
|
||||
'''
|
||||
Créée une instance d'un objet Crans (machine, adhérent,
|
||||
etc...) à ce ``dn``, si ``uldif`` est précisé, n'effectue pas de
|
||||
|
@ -122,6 +118,11 @@ class CransLdapObject(object):
|
|||
self.in_context = False
|
||||
self.conn = conn
|
||||
|
||||
if lockId:
|
||||
self.lockId = lockId
|
||||
else:
|
||||
self.lockId = '%s_%s' % (os.getpid(), id(self))
|
||||
|
||||
self.attrs = attributs.AttrsDict(conn, Parent=self) # Contient un dico ldif qui doit représenter ce qui
|
||||
# est dans la base. On attrify paresseusement au moment où on utilise un attribut
|
||||
|
||||
|
@ -469,7 +470,8 @@ class CransLdapObject(object):
|
|||
return attributs.AttrsList(self, attr, [ v for v in self.attrs[attr] ])
|
||||
elif self.has_key(attr):
|
||||
return attributs.AttrsList(self, attr, []) if default is None else default
|
||||
raise KeyError(attr)
|
||||
else:
|
||||
raise KeyError(attr)
|
||||
|
||||
def has_key(self, attr):
|
||||
"""Est-ce que notre objet a l'attribut en question ?"""
|
||||
|
@ -648,8 +650,8 @@ class proprio(CransLdapObject):
|
|||
def __repr__(self):
|
||||
return str(self.__class__) + " : nom=" + str(self['nom'][0])
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', ldif=None):
|
||||
super(proprio, self).__init__(conn, dn, mode, ldif)
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(proprio, self).__init__(*args, **kwargs)
|
||||
self._machines = None
|
||||
self._factures = None
|
||||
if u'cransAccount' in self['objectClass']:
|
||||
|
@ -756,8 +758,8 @@ class machine(CransLdapObject):
|
|||
def __repr__(self):
|
||||
return str(self.__class__) + " : host=" + str(self['host'][0])
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', ldif = None):
|
||||
super(machine, self).__init__(conn, dn, mode, ldif)
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(machine, self).__init__(*args, **kwargs)
|
||||
self._proprio = None
|
||||
self._certificats = None
|
||||
|
||||
|
@ -946,8 +948,8 @@ class adherent(proprio):
|
|||
def __repr__(self):
|
||||
return str(self.__class__) + " : aid=" + str(self['aid'][0])
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', ldif=None):
|
||||
super(adherent, self).__init__(conn, dn, mode, ldif)
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(adherent, self).__init__(*args, **kwargs)
|
||||
self.full = False
|
||||
self._clubs = None
|
||||
self._imprimeur_clubs = None
|
||||
|
@ -1125,8 +1127,8 @@ class facture(CransLdapObject):
|
|||
return str(self.__class__) + " : fid=" + str(self['fid'][0])
|
||||
|
||||
#### GROS HACK pour rester comptatible avec ldap_crans où l'article representant les frais n'est ajouté qu'une fois le paiement reçu
|
||||
def __init__(self, conn, dn, mode='ro', ldif=None):
|
||||
super(facture, self).__init__(conn, dn, mode, ldif)
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(facture, self).__init__(*args, **kwargs)
|
||||
self._frais = []
|
||||
if not self.get('recuPaiement', []):
|
||||
if str(self['modePaiement'][0]) == 'paypal':
|
||||
|
@ -1177,13 +1179,13 @@ class baseCert(CransLdapObject):
|
|||
def __repr__(self):
|
||||
return str(self.__class__) + " : xid=" + str(self['xid'][0])
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', ldif=None):
|
||||
super(baseCert, self).__init__(conn, dn, 'ro', ldif)
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(baseCert, self).__init__(*args, **kwargs)
|
||||
if "TLSACert" in self['objectClass']:
|
||||
self.attribs.extend(self.tlsa_attribs)
|
||||
if 'x509Cert' in self['objectClass']:
|
||||
self.attribs.extend(self.x509_attribs)
|
||||
super(baseCert, self).__init__(conn, dn, mode, ldif)
|
||||
super(baseCert, self).__init__(*args, **kwargs)
|
||||
|
||||
def _check_setitem(self, attr, values):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue