[attributs, objets] Possibilité d'avoir un attribut unique sauf pour une liste de valeur prédéfini
Je pense particulièrement à chambre qui est unique sauf pour ???? et EXT On en a besoin pour détecter, quand on affecte quelqu'un a une chambre, que la chambre est déjà occupée
This commit is contained in:
parent
ad83a5aaa3
commit
7e55e8325d
2 changed files with 7 additions and 4 deletions
|
@ -248,10 +248,12 @@ class Attr(object):
|
|||
optional = True
|
||||
conn = None
|
||||
unique = False
|
||||
unique_exclue = []
|
||||
#: Le nom de l'attribut dans le schéma LDAP
|
||||
ldap_name = None
|
||||
python_type = None
|
||||
binary = False
|
||||
default = None
|
||||
|
||||
"""La liste des droits qui suffisent à avoir le droit de modifier la valeur"""
|
||||
can_modify = [nounou]
|
||||
|
@ -334,7 +336,7 @@ class Attr(object):
|
|||
"""Vérifie l'unicité dans la base de la valeur (``mailAlias``, ``chbre``,
|
||||
etc...)"""
|
||||
attr = self.__class__.__name__
|
||||
if unicode(self) in liste_exclue:
|
||||
if unicode(self) in liste_exclue + self.unique_exclue:
|
||||
return
|
||||
if self.unique:
|
||||
res = self.conn.search(u'%s=%s' % (attr, str(self)))
|
||||
|
@ -671,7 +673,8 @@ class etudes(Attr):
|
|||
class chbre(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
unique = False
|
||||
unique = True
|
||||
unique_exclue = [u'????', u'EXT']
|
||||
legend = u"Chambre sur le campus"
|
||||
can_modify = [soi, cableur, nounou]
|
||||
category = 'perso'
|
||||
|
|
|
@ -533,7 +533,7 @@ class CransLdapObject(object):
|
|||
locked = []
|
||||
try:
|
||||
for attribut in attrs_before_verif:
|
||||
if attribut.unique and not attribut in self._modifs.get(attr, []):
|
||||
if 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)
|
||||
|
@ -548,7 +548,7 @@ class CransLdapObject(object):
|
|||
|
||||
# On retire les locks des attributs que l'on ne va plus utiliser
|
||||
for attribut in self._modifs.get(attr, []):
|
||||
if attribut.unique and not attribut in attrs_before_verif:
|
||||
if attribut.unique and not attribut in attrs_before_verif and not attribut in attribut.unique_exclue:
|
||||
self.conn.lockholder.removelock(attr, str(attribut), self.lockId)
|
||||
|
||||
# On met à jour self._modifs avec les nouvelles valeurs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue