diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index d5eb83f4..b0b8af49 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -919,47 +919,50 @@ 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: modif[modif.index('solde')] = "debit %s Euros" % str(diff) 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 - 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 - - 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])) - + # 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]) + + # 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, []) + + # 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() hist = "%s, %s" % ( time.strftime(date_format, timestamp), script_utilisateur ) - + # On loggue try: 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): """ 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) - - trans.sort() - new=[] - for an in trans: - new.append('%d' % an ) + touched = True + if touched and champ not in self.modifs: + self.modifs.append(champ) - self._data[champ] = new + trans.sort() + self._data[champ] = map(str, trans) return self._data[champ]