Modifs conseillees par Etienne sur la factorisation des fonctions de

l'historique. Par Stphane.

darcs-hash:20051112201647-d1718-fb7dd3ccd00192508670f3fce41bcf61349e8bcd.gz
This commit is contained in:
bernat 2005-11-12 21:16:47 +01:00
parent 5bbac7c0ba
commit c388ce20fb

View file

@ -919,13 +919,10 @@ class base_classes_crans(crans_ldap):
modif='inscription' modif='inscription'
else: else:
### ON NE TOUCHE PAS A SELF.MODIFS, IL EST UTILISÉ PLUS LOIN !!!!!!! ### ON NE TOUCHE PAS A SELF.MODIFS, IL EST UTILISÉ PLUS LOIN !!!!!!!
# Copie de la liste # Copie locale de la liste
modif = self.modifs[:] modif = self.modifs[:]
if "chbre" in self.modifs: # Cas spécial
modif[modif.index('chbre')] = "chbre %s -> %s" % (self._init_data["chbre"][0],
self._data["chbre"][0])
if "solde" in self.modifs: if "solde" in self.modifs:
diff = float(self._init_data.get('solde',[0])[0]) - float(self._data.get('solde',[0])[0]) diff = float(self._init_data.get('solde',[0])[0]) - float(self._data.get('solde',[0])[0])
if diff > 0: if diff > 0:
@ -933,28 +930,34 @@ class base_classes_crans(crans_ldap):
else: else:
modif[modif.index('solde')] = "credit %s Euros" % str(-diff) modif[modif.index('solde')] = "credit %s Euros" % str(-diff)
if 'droits' in self.modifs: # Formate les entrées de l'historique de la forme champ (ancien -> nouveau)
anciens_droits = self._init_data.get('droits',[]) # On suppose que le champ apparaît forcément dans l'enregistrement
nouveaux_droits = self._data.get('droits',[]) for champ in ['chbre', 'nom', 'prenom']:
droits_ajoutes = ''.join( [ '+%s' % decode(d) for d in nouveaux_droits if d not in anciens_droits ] ) if champ in self.modifs:
droits_enleves = ''.join( [ '-%s' % decode(d) for d in anciens_droits if d not in nouveaux_droits ] ) modif[modif.index(champ)] = '%s (%s -> %s)' % (champ,
modif[modif.index('droits')] = "droits : " + droits_ajoutes + droits_enleves self._init_data[champ][0],
self._data[champ][0])
if 'controle' in self.modifs: # Formate les entrées de l'historique de la forme champ+diff-diff
for champ in ['droits', 'controle', 'paiement', 'carteEtudiant']:
if champ in self.modifs:
if champ == 'controle':
# Ce n'est pas pareil que self._init_data.get('controle', [''])
# qui peut renvoyer une liste vide (petite erreur de choix
# dans la première implémentation de controle)
ancien = (self._init_data.get('controle') or [''])[0] ancien = (self._init_data.get('controle') or [''])[0]
nouveau = (self._data.get('controle') or [''])[0] nouveau = (self._data.get('controle') or [''])[0]
plus = ''.join([ '+%s' % d for d in nouveau if d not in ancien ]) else:
moins = ''.join([ '-%s' % d for d in ancien if d not in nouveau ]) # Là, on bosse directement sur les listes renvoyées par get
modif[modif.index('controle')] = 'controle : ' + plus + moins ancien = self._init_data.get(champ, [])
nouveau = self._data.get(champ, [])
if 'nom' in self.modifs: # On établit le diff
modif[modif.index('nom')] = 'nom %s -> %s' % (decode(self._init_data['nom'][0]), diff = ''.join([ '+%s' % decode(d) for d in nouveau if d not in ancien ])
decode(self._data['nom'][0])) diff += ''.join([ '-%s' % decode(d) for d in ancien if d not in nouveau ])
modif[modif.index(champ)] = champ + diff
if 'prenom' in self.modifs:
modif[modif.index('prenom')] = 'prenom %s -> %s' % (decode(self._init_data['prenom'][0]),
decode(self._data['prenom'][0]))
# On recolle tous les morceaux
modif = ', '.join(modif) modif = ', '.join(modif)
timestamp = localtime() timestamp = localtime()
@ -1214,7 +1217,7 @@ class base_proprietaire(base_classes_crans):
def controle(self,new=None): def controle(self,new=None):
""" """
Controle du tresorier Controle du tresorier
New est de la forme {+-}{pc} New est de la forme [+-][pc]
(p pour le paiement, c pour la carte (p pour le paiement, c pour la carte
Retourne une chaine contenant p ou c ou les deux Retourne une chaine contenant p ou c ou les deux
""" """
@ -1236,8 +1239,17 @@ class base_proprietaire(base_classes_crans):
if new == '-%s' % c: if new == '-%s' % c:
actuel = actuel.replace(c, '') actuel = actuel.replace(c, '')
if actuel == '': self._set('controle',[]) if actuel == '':
else: self._set('controle',[actuel]) # La base LDAP n'accepte pas les chaînes vides.
# On supprime directement le champ controle
if self._data.has_key('controle'):
if self._data.pop('controle') != []:
# Il y avait vraiment qqch avant
if 'controle' not in self.modifs:
self.modifs.append('controle')
else:
self._set('controle',[actuel])
return actuel return actuel
def contourneGreylist(self,contourneGreylist=None): def contourneGreylist(self,contourneGreylist=None):
@ -1336,15 +1348,12 @@ class base_proprietaire(base_classes_crans):
ret += coul(u"Modification %s effectuée avec succès." % self.Nom(), 'vert') ret += coul(u"Modification %s effectuée avec succès." % self.Nom(), 'vert')
# Changements administratifs # Changements administratifs
test_carte = 'carteEtudiant+%s' % ann_scol in self.modifs \ test_carte = 'carteEtudiant' in self.modifs
or 'carteEtudiant-%s' % ann_scol in self.modifs
if test_carte and self.machines(): if test_carte and self.machines():
self.services_to_restart('bl_carte_etudiant') self.services_to_restart('bl_carte_etudiant')
if 'paiement+%s' % ann_scol in self.modifs \ if 'paiement' in self.modifs or (config.bl_carte_et_definitif and test_carte):
or 'paiement-%s' % ann_scol in self.modifs \
or ( config.bl_carte_et_definitif and test_carte ):
for m in self.machines(): for m in self.machines():
self.services_to_restart('macip',[m.ip()] ) self.services_to_restart('macip',[m.ip()] )
self.services_to_restart('dns') self.services_to_restart('dns')
@ -1421,23 +1430,18 @@ class base_proprietaire(base_classes_crans):
if type(action)!=int: raise TypeError if type(action)!=int: raise TypeError
touched = False
if action>0 and action not in trans: if action>0 and action not in trans:
trans.append(action) trans.append(action)
act = '%s+%d' % (champ,action) touched = True
if act not in self.modifs:
self.modifs.append(act)
elif action<0 and -action in trans: elif action<0 and -action in trans:
trans.remove(-action) trans.remove(-action)
act = '%s%s' % (champ,action) touched = True
if act not in self.modifs: if touched and champ not in self.modifs:
self.modifs.append(act) self.modifs.append(champ)
trans.sort() trans.sort()
new=[] self._data[champ] = map(str, trans)
for an in trans:
new.append('%d' % an )
self._data[champ] = new
return self._data[champ] return self._data[champ]