diff --git a/objets.py b/objets.py index 961f257..cbbb217 100644 --- a/objets.py +++ b/objets.py @@ -616,7 +616,15 @@ class CransLdapObject(object): """ pass - def __setitem__(self, attr, values): + def replace_id(self, attr, realm=None): + ids = ["aid", "mid", "fid", "cid", "xid", "rid"] + if attr not in ids or not attr in self.keys(): + raise ValueError("On ne peut remplacer que les id suivant : %s" % ", ".join(attr for attr in ids if attr in self.keys())) + id = self.conn._find_id(attr, realm, lockId=self.lockId) + # Pas de lock sur l'unicité car _find_id vient d'en placer un + self.__setitem__(attr, unicode(id), no_uniq_lock=True) + + def __setitem__(self, attr, values, no_uniq_lock=False, no_concurrent_lock=False): """Permet d'affecter des valeurs à l'objet comme s'il était un dictionnaire.""" # Quand on est pas en mode d'écriture, ça plante. @@ -661,7 +669,7 @@ class CransLdapObject(object): raise ValueError("%s en double\n(%s)" % (attribut.legend if attribut.legend else attr, attribut)) # On lock les nouvelles valeurs globalement unique - if attribut.unique and not attribut in self._modifs.get(attr, []) and not attribut in attribut.unique_exclue: + if not no_uniq_lock and attribut.unique and not attribut in self._modifs.get(attr, []) and not attribut in attribut.unique_exclue: if not self.in_context: cranslib.deprecated.usage("Des locks ne devrait être ajoutés que dans un context manager", level=2) self.conn.lockholder.addlock(attr, str(attribut), self.lockId) @@ -675,7 +683,7 @@ class CransLdapObject(object): # On lock si l'attribut ne supporte pas les modifications concurrente (comme pour le solde) si : # * on effectue réellement un modification sur l'attribut # * on a pas déjà effectuer un modification qui nous a déjà fait acquérir le lock - if not attributs.AttributeFactory.get(attr).concurrent and self._modifs.get(attr, []) == self.attrs.get(attr, []) and attrs_before_verif != self.attrs.get(attr, []): + if not no_concurrent_lock and not attributs.AttributeFactory.get(attr).concurrent and self._modifs.get(attr, []) == self.attrs.get(attr, []) and attrs_before_verif != self.attrs.get(attr, []): if not self.in_context: cranslib.deprecated.usage("Des locks ne devrait être ajoutés que dans un context manager", level=2) self.conn.lockholder.addlock("dn", "%s_%s" % (self.dn.replace('=', '-').replace(',','_'), attr), self.lockId)