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,47 +919,50 @@ 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:
|
||||||
modif[modif.index('solde')] = "debit %s Euros" % str(diff)
|
modif[modif.index('solde')] = "debit %s Euros" % str(diff)
|
||||||
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:
|
|
||||||
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
|
|
||||||
|
|
||||||
if 'controle' in self.modifs:
|
# Formate les entrées de l'historique de la forme champ (ancien -> nouveau)
|
||||||
ancien = (self._init_data.get('controle') or [''])[0]
|
# On suppose que le champ apparaît forcément dans l'enregistrement
|
||||||
nouveau = (self._data.get('controle') or [''])[0]
|
for champ in ['chbre', 'nom', 'prenom']:
|
||||||
plus = ''.join([ '+%s' % d for d in nouveau if d not in ancien ])
|
if champ in self.modifs:
|
||||||
moins = ''.join([ '-%s' % d for d in ancien if d not in nouveau ])
|
modif[modif.index(champ)] = '%s (%s -> %s)' % (champ,
|
||||||
modif[modif.index('controle')] = 'controle : ' + plus + moins
|
self._init_data[champ][0],
|
||||||
|
self._data[champ][0])
|
||||||
if 'nom' in self.modifs:
|
|
||||||
modif[modif.index('nom')] = 'nom %s -> %s' % (decode(self._init_data['nom'][0]),
|
# Formate les entrées de l'historique de la forme champ+diff-diff
|
||||||
decode(self._data['nom'][0]))
|
for champ in ['droits', 'controle', 'paiement', 'carteEtudiant']:
|
||||||
|
if champ in self.modifs:
|
||||||
if 'prenom' in self.modifs:
|
if champ == 'controle':
|
||||||
modif[modif.index('prenom')] = 'prenom %s -> %s' % (decode(self._init_data['prenom'][0]),
|
# Ce n'est pas pareil que self._init_data.get('controle', [''])
|
||||||
decode(self._data['prenom'][0]))
|
# 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, [])
|
||||||
|
|
||||||
|
# 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)
|
modif = ', '.join(modif)
|
||||||
|
|
||||||
timestamp = localtime()
|
timestamp = localtime()
|
||||||
hist = "%s, %s" % ( time.strftime(date_format, timestamp), script_utilisateur )
|
hist = "%s, %s" % ( time.strftime(date_format, timestamp), script_utilisateur )
|
||||||
|
|
||||||
# On loggue
|
# On loggue
|
||||||
try:
|
try:
|
||||||
fd = file('%s/%s_%s_%s' % ("%s/logs" % config.cimetiere, str(self.__class__).split('.')[-1],
|
fd = file('%s/%s_%s_%s' % ("%s/logs" % config.cimetiere, str(self.__class__).split('.')[-1],
|
||||||
|
@ -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()
|
|
||||||
new=[]
|
|
||||||
for an in trans:
|
|
||||||
new.append('%d' % an )
|
|
||||||
|
|
||||||
self._data[champ] = new
|
trans.sort()
|
||||||
|
self._data[champ] = map(str, trans)
|
||||||
|
|
||||||
return self._data[champ]
|
return self._data[champ]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue