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:
parent
5bbac7c0ba
commit
c388ce20fb
1 changed files with 53 additions and 49 deletions
|
@ -919,13 +919,10 @@ class base_classes_crans(crans_ldap):
|
|||
modif='inscription'
|
||||
else:
|
||||
### ON NE TOUCHE PAS A SELF.MODIFS, IL EST UTILISÉ PLUS LOIN !!!!!!!
|
||||
# Copie de la liste
|
||||
# Copie locale de la liste
|
||||
modif = self.modifs[:]
|
||||
|
||||
if "chbre" in self.modifs:
|
||||
modif[modif.index('chbre')] = "chbre %s -> %s" % (self._init_data["chbre"][0],
|
||||
self._data["chbre"][0])
|
||||
|
||||
# Cas spécial
|
||||
if "solde" in self.modifs:
|
||||
diff = float(self._init_data.get('solde',[0])[0]) - float(self._data.get('solde',[0])[0])
|
||||
if diff > 0:
|
||||
|
@ -933,28 +930,34 @@ class base_classes_crans(crans_ldap):
|
|||
else:
|
||||
modif[modif.index('solde')] = "credit %s Euros" % str(-diff)
|
||||
|
||||
if 'droits' in self.modifs:
|
||||
anciens_droits = self._init_data.get('droits',[])
|
||||
nouveaux_droits = self._data.get('droits',[])
|
||||
droits_ajoutes = ''.join( [ '+%s' % decode(d) for d in nouveaux_droits if d not in anciens_droits ] )
|
||||
droits_enleves = ''.join( [ '-%s' % decode(d) for d in anciens_droits if d not in nouveaux_droits ] )
|
||||
modif[modif.index('droits')] = "droits : " + droits_ajoutes + droits_enleves
|
||||
# Formate les entrées de l'historique de la forme champ (ancien -> nouveau)
|
||||
# On suppose que le champ apparaît forcément dans l'enregistrement
|
||||
for champ in ['chbre', 'nom', 'prenom']:
|
||||
if champ in self.modifs:
|
||||
modif[modif.index(champ)] = '%s (%s -> %s)' % (champ,
|
||||
self._init_data[champ][0],
|
||||
self._data[champ][0])
|
||||
|
||||
if 'controle' in self.modifs:
|
||||
ancien = (self._init_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 ])
|
||||
moins = ''.join([ '-%s' % d for d in ancien if d not in nouveau ])
|
||||
modif[modif.index('controle')] = 'controle : ' + plus + moins
|
||||
# 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]
|
||||
nouveau = (self._data.get('controle') or [''])[0]
|
||||
else:
|
||||
# Là, on bosse directement sur les listes renvoyées par get
|
||||
ancien = self._init_data.get(champ, [])
|
||||
nouveau = self._data.get(champ, [])
|
||||
|
||||
if 'nom' in self.modifs:
|
||||
modif[modif.index('nom')] = 'nom %s -> %s' % (decode(self._init_data['nom'][0]),
|
||||
decode(self._data['nom'][0]))
|
||||
|
||||
if 'prenom' in self.modifs:
|
||||
modif[modif.index('prenom')] = 'prenom %s -> %s' % (decode(self._init_data['prenom'][0]),
|
||||
decode(self._data['prenom'][0]))
|
||||
# On établit le diff
|
||||
diff = ''.join([ '+%s' % decode(d) for d in nouveau if d not in ancien ])
|
||||
diff += ''.join([ '-%s' % decode(d) for d in ancien if d not in nouveau ])
|
||||
modif[modif.index(champ)] = champ + diff
|
||||
|
||||
# On recolle tous les morceaux
|
||||
modif = ', '.join(modif)
|
||||
|
||||
timestamp = localtime()
|
||||
|
@ -1214,7 +1217,7 @@ class base_proprietaire(base_classes_crans):
|
|||
def controle(self,new=None):
|
||||
"""
|
||||
Controle du tresorier
|
||||
New est de la forme {+-}{pc}
|
||||
New est de la forme [+-][pc]
|
||||
(p pour le paiement, c pour la carte
|
||||
Retourne une chaine contenant p ou c ou les deux
|
||||
"""
|
||||
|
@ -1236,8 +1239,17 @@ class base_proprietaire(base_classes_crans):
|
|||
if new == '-%s' % c:
|
||||
actuel = actuel.replace(c, '')
|
||||
|
||||
if actuel == '': self._set('controle',[])
|
||||
else: self._set('controle',[actuel])
|
||||
if 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
|
||||
|
||||
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')
|
||||
|
||||
# Changements administratifs
|
||||
test_carte = 'carteEtudiant+%s' % ann_scol in self.modifs \
|
||||
or 'carteEtudiant-%s' % ann_scol in self.modifs
|
||||
test_carte = 'carteEtudiant' in self.modifs
|
||||
|
||||
if test_carte and self.machines():
|
||||
self.services_to_restart('bl_carte_etudiant')
|
||||
|
||||
if 'paiement+%s' % ann_scol in self.modifs \
|
||||
or 'paiement-%s' % ann_scol in self.modifs \
|
||||
or ( config.bl_carte_et_definitif and test_carte ):
|
||||
if 'paiement' in self.modifs or (config.bl_carte_et_definitif and test_carte):
|
||||
for m in self.machines():
|
||||
self.services_to_restart('macip',[m.ip()] )
|
||||
self.services_to_restart('dns')
|
||||
|
@ -1421,23 +1430,18 @@ class base_proprietaire(base_classes_crans):
|
|||
|
||||
if type(action)!=int: raise TypeError
|
||||
|
||||
touched = False
|
||||
if action>0 and action not in trans:
|
||||
trans.append(action)
|
||||
act = '%s+%d' % (champ,action)
|
||||
if act not in self.modifs:
|
||||
self.modifs.append(act)
|
||||
touched = True
|
||||
elif action<0 and -action in trans:
|
||||
trans.remove(-action)
|
||||
act = '%s%s' % (champ,action)
|
||||
if act not in self.modifs:
|
||||
self.modifs.append(act)
|
||||
touched = True
|
||||
if touched and champ not in self.modifs:
|
||||
self.modifs.append(champ)
|
||||
|
||||
trans.sort()
|
||||
new=[]
|
||||
for an in trans:
|
||||
new.append('%d' % an )
|
||||
|
||||
self._data[champ] = new
|
||||
self._data[champ] = map(str, trans)
|
||||
|
||||
return self._data[champ]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue