Aération, indentation.

This commit is contained in:
Pierre-Elliott Bécue 2014-12-02 09:41:18 +01:00
parent cb71139d02
commit 4b99950f97

View file

@ -23,6 +23,9 @@ import proprio
from CPS import TailCall, tailcaller, Continue
class Dialog(proprio.Dialog):
"""
Classe Dialog spécifique aux adhérents pour gest_crans_lc
"""
def modif_adherent_blacklist(self, adherent, cont):
"""Raccourci vers edit_blacklist spécifique aux adherent"""
return self.edit_blacklist(obj=adherent, title="Éditions des blacklist de %s %s" % (adherent['prenom'][0], adherent['nom'][0]), update_obj='adherent', cont=cont)
@ -216,9 +219,9 @@ class Dialog(proprio.Dialog):
def box_adherer(end=None):
if end:
t_end = time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(end))
adherer=self.confirm(text="Adhésion jusqu'au %s. Réadhérer ?" % t_end, title="Adhésion de %s %s" % (adherent.get("prenom", [''])[0], adherent["nom"][0]))
adherer = self.confirm(text="Adhésion jusqu'au %s. Réadhérer ?" % t_end, title="Adhésion de %s %s" % (adherent.get("prenom", [''])[0], adherent["nom"][0]))
else:
adherer=self.confirm(text="Adhésion pour un an, continuer ?", title="Adhésion de %s %s" % (adherent.get("prenom", [''])[0], adherent["nom"][0]))
adherer = self.confirm(text="Adhésion pour un an, continuer ?", title="Adhésion de %s %s" % (adherent.get("prenom", [''])[0], adherent["nom"][0]))
return adherer
def delete_facture(facture, cont):
@ -226,7 +229,7 @@ class Dialog(proprio.Dialog):
with self.conn.search(dn=facture.dn, scope=0, mode='rw')[0] as facture:
facture.delete()
raise Continue(cont)
# Génération de la facture pour adhésion
def paiement(tag_paiement, adherent, finadhesion, comment, cancel_cont, cont):
now = time.time()
@ -234,11 +237,11 @@ class Dialog(proprio.Dialog):
new_finadhesion = time.mktime(new_finadhesion.replace(year=new_finadhesion.year + config.cotisation.duree_adh_an).timetuple()) + 86400
new_debutadhesion = now
with self.conn.newFacture(adherent.dn, {}) as facture:
facture['modePaiement']=unicode(tag_paiement, 'utf-8')
facture['modePaiement'] = unicode(tag_paiement, 'utf-8')
facture['article'].append(config.cotisation.dico_adh)
facture['info']=unicode(comment, 'utf-8')
facture["finAdhesion"]=unicode(new_finadhesion)
facture["debutAdhesion"]=unicode(new_debutadhesion)
facture['info'] = unicode(comment, 'utf-8')
facture["finAdhesion"] = unicode(new_finadhesion)
facture["debutAdhesion"] = unicode(new_debutadhesion)
if crediter:
if self.confirm_item(item=facture,
text=u"Le paiement de %sEUR a-t-il bien été reçu (mode : %s) ?\n" % (facture.total(), tag_paiement),
@ -324,8 +327,8 @@ class Dialog(proprio.Dialog):
if facture:
with self.conn.search(dn=facture.dn, scope=0, mode='rw')[0] as facture:
if mois:
facture["finConnexion"]=unicode(new_finconnexion)
facture["debutConnexion"]=unicode(new_debutconnexion)
facture["finConnexion"] = unicode(new_finconnexion)
facture["debutConnexion"] = unicode(new_debutconnexion)
facture["article"].append(config.cotisation.dico_cotis(mois))
if self.confirm_item(item=facture,
text=u"Le paiement de %sEUR a-t-il bien été reçu (mode : %s) ?\n" % (facture.total(), facture['modePaiement'][0]),
@ -345,11 +348,11 @@ class Dialog(proprio.Dialog):
if not mois:
raise ValueError("Il faut prolonger la connexion d'un nombre de mois strictement positif")
with self.conn.newFacture(adherent.dn, {}) as facture:
facture['modePaiement']=unicode(tag_paiment, 'utf-8')
facture['modePaiement'] = unicode(tag_paiment, 'utf-8')
facture['article'].append(config.cotisation.dico_cotis(mois))
facture['info']=unicode(comment, 'utf-8')
facture["finConnexion"]=unicode(new_finconnexion)
facture["debutConnexion"]=unicode(new_debutconnexion)
facture['info'] = unicode(comment, 'utf-8')
facture["finConnexion"] = unicode(new_finconnexion)
facture["debutConnexion"] = unicode(new_debutconnexion)
if self.confirm_item(item=facture,
text=u"Le paiement de %sEUR a-t-il bien été reçu (mode : %s) ?\n" % (facture.total(), tag_paiment),
title=u"Validation du paiement",
@ -365,7 +368,7 @@ class Dialog(proprio.Dialog):
if tag == 'An':
mois = 12
else:
mois = int(tag.split(' ',1)[0])
mois = int(tag.split(' ', 1)[0])
raise Continue(self_cont(mois=mois, default_item=tag))
self_cont = TailCall(self.adherent_connexion, cont=cont, adherent=adherent, cancel_cont=cancel_cont, facture=facture, mois=mois, default_item=default_item, tag_paiment=tag_paiment, comment_paiement=comment_paiement)
@ -378,10 +381,10 @@ class Dialog(proprio.Dialog):
# Si l'adhésion fini avant la connexion
if finadhesion <= time.time() or finadhesion < finconnexion:
if finadhesion:
if finadhesion <= time.time():
self.dialog.msgbox(text=u"L'adhésion a expiré, il va falloir réadhérer d'abord", title="Réadhésion nécessaire", width=0, height=0, timeout=self.timeout)
elif finadhesion < finconnexion:
self.dialog.msgbox(text=u"L'adhésion de termine avant la fin de la connexion, il va falloir réadhérer d'abord", title="Réadhésion nécessaire", width=0, height=0, timeout=self.timeout)
if finadhesion <= time.time():
self.dialog.msgbox(text=u"L'adhésion a expiré, il va falloir réadhérer d'abord", title="Réadhésion nécessaire", width=0, height=0, timeout=self.timeout)
elif finadhesion < finconnexion:
self.dialog.msgbox(text=u"L'adhésion de termine avant la fin de la connexion, il va falloir réadhérer d'abord", title="Réadhésion nécessaire", width=0, height=0, timeout=self.timeout)
# Échouera si on essaie de prolonger la connexion au dela de l'adhésion et que l'adhésion est encore valable plus de quinze jours
return self.adherent_adhesion(cont=self_cont, cancel_cont=cont, adherent=adherent, crediter=False)
if facture:
@ -397,7 +400,7 @@ class Dialog(proprio.Dialog):
codes_todo=[([self.dialog.DIALOG_OK], todo_mois, [tag, self_cont])]
)
elif tag_paiment or facture:
lcont=self_cont.copy()
lcont = self_cont.copy()
if facture:
lcont(mois=None)
else:
@ -410,7 +413,7 @@ class Dialog(proprio.Dialog):
codes_todo=[([self.dialog.DIALOG_OK], todo, [adherent, mois, finconnexion, lcont, cont, facture, tag_paiment, comment_paiement])]
)
else:
lcont=self_cont.copy()
lcont = self_cont.copy()
lcont(mois=None)
return self.proprio_choose_paiement(proprio=adherent, cont=self_cont, cancel_cont=lcont)
return cont
@ -453,7 +456,7 @@ class Dialog(proprio.Dialog):
else:
adherent["controle"] = u"c"
elif self.has_right(a.tresorier, adherent) and not values["controleCarte"] and adherent.carte_controle():
adherent["controle"]=unicode(adherent["controle"][0]).replace('c','')
adherent["controle"] = unicode(adherent["controle"][0]).replace('c','')
if not adherent["controle"][0]:
adherent["controle"] = []
# Si la carte n'est pas validé ou qu'on est trésorier, on sauvegarde les changements
@ -462,7 +465,7 @@ class Dialog(proprio.Dialog):
elif not values[a.carteEtudiant.ldap_name] and adherent[a.carteEtudiant.ldap_name] and (not adherent.carte_controle() or self.has_right(a.tresorier, adherent)):
adherent[a.carteEtudiant.ldap_name] = []
if adherent["controle"]:
adherent["controle"]=unicode(adherent["controle"][0]).replace('c','')
adherent["controle"] = unicode(adherent["controle"][0]).replace('c','')
if not adherent["controle"][0]:
adherent["controle"] = []
adherent.validate_changes()
@ -512,9 +515,9 @@ class Dialog(proprio.Dialog):
def box(make_compte_crans):
if force_create and adherent is None and fields_attrs and make_compte_crans is not None:
return (self.dialog.DIALOG_OK, [fields_attrs[a] for a,l in to_display], make_compte_crans)
return (self.dialog.DIALOG_OK, [fields_attrs[a] for (a, l) in to_display], make_compte_crans)
if adherent:
attrs = dict((k,[str(a) for a in at]) for k,at in adherent.items())
attrs = dict((k, [str(a) for a in at]) for (k, at) in adherent.items())
if 'cransAccount' in adherent['objectClass']:
input_type[attributs.mail] = 2
to_display.append((attributs.mailExt, 30))
@ -547,7 +550,7 @@ class Dialog(proprio.Dialog):
def modif_adherent(adherent, attrs):
with self.conn.search(dn=adherent.dn, scope=0, mode='rw')[0] as adherent:
for (key, values) in attrs.items():
adherent[key]=values
adherent[key] = values
adherent.validate_changes()
adherent.history_gen()
adherent.save()
@ -560,13 +563,13 @@ class Dialog(proprio.Dialog):
newadherent = self.select_one(items, title="Choisir un adhérant existant", text="Des adhérent avec les même noms et prénoms existent déjà, en utiliser un ?\n(Annuler pour continuer la création)", cont=self_cont(make_compte_crans=make_compte_crans, force_create=True))
raise Continue(cont(adherent=newadherent))
with self.conn.newAdherent({}) as adherent:
delay={}
delay = {}
for (key, values) in attrs.items():
try:
adherent[key]=values
adherent[key] = values
# En cas d'erreur, on a peut être besoin du compte crans
except ValueError:
delay[key]=values
delay[key] = values
print delay
# on récupère la chambre
adherent = self.adherent_chambre_campus(success_cont=None, cont=self_cont(make_compte_crans=make_compte_crans), adherent=adherent, create=True)
@ -580,7 +583,7 @@ class Dialog(proprio.Dialog):
adherent = self.proprio_compte_create(proprio=adherent, cont=self_cont(make_compte_crans=None, force_create=False, adherent=None), update_obj='adherent', return_obj=True)
# On réeaffecte les attributs de tout à l'heure
for (key, values) in delay.items():
adherent[key]=values
adherent[key] = values
# On confirme la création
if self.confirm_item(adherent, title="Créer l'adhérent suivant ?"):
adherent.validate_changes()
@ -592,7 +595,7 @@ class Dialog(proprio.Dialog):
def todo(to_display, non_empty, tags, adherent, separateur, make_compte_crans, force_create, self_cont, cont):
attrs = {}
# On traite les valeurs reçues
for ((a,l),values) in zip(to_display, tags):
for ((a, l), values) in zip(to_display, tags):
if not values and a in non_empty:
raise ValueError(u"%s ne devrait pas être vide" % a.legend)
values = unicode(values, 'utf-8')
@ -600,7 +603,7 @@ class Dialog(proprio.Dialog):
# et on ne garde que les valeurs non vides
if not a.singlevalue:
values = [v for v in values.split(separateur) if v]
attrs[a.ldap_name]=values
attrs[a.ldap_name] = values
if adherent:
adherent = modif_adherent(adherent, attrs)
else:
@ -613,7 +616,7 @@ class Dialog(proprio.Dialog):
# On prépare les fiels à afficher à l'utilisateur si une erreure à lieu
# pendant le traitement des donnée (on n'éfface pas ce qui a déjà été entré
# c'est au cableur de corriger ou d'annuler
fields_attrs = dict((a, values) for ((a,l),values) in zip(to_display, tags))
fields_attrs = dict((a, values) for ((a, l), values) in zip(to_display, tags))
retry_cont = TailCall(self.adherent_personnel, adherent=adherent, cont=cont, fields_attrs=fields_attrs)
return self.handle_dialog_result(
@ -644,7 +647,7 @@ class Dialog(proprio.Dialog):
text=u"L'adhérent ci-dessous occupé déjà la chambre %s :\n" % output,
text_bottom=u"\nPasser la chambre de cet adhérent en chambre inconnue ?"
):
squatteur['chbre']=u'????'
squatteur['chbre'] = u'????'
squatteur.validate_changes()
squatteur.history_gen()
squatteur.save()
@ -654,12 +657,12 @@ class Dialog(proprio.Dialog):
def set_chambre(adherent, chbre):
try:
adherent['postalAddress']=[]
adherent['chbre']=unicode(output, 'utf-8')
adherent['postalAddress'] = []
adherent['chbre'] = unicode(output, 'utf-8')
except UniquenessError:
if expulse_squatteur(adherent, chbre):
# La chambre est maintenant normalement libre
adherent['chbre']=unicode(output, 'utf-8')
adherent['chbre'] = unicode(output, 'utf-8')
else:
raise Continue(self_cont)
return adherent
@ -698,7 +701,7 @@ class Dialog(proprio.Dialog):
elif keep_machine and keep_compte:
def box(values={}):
form = [("Adresse", 40), ("Compl. adr.", 40), ("Code postal", 7), ("Ville", 16)]
fields = [("%s :" % k, values.get(k, ""), l, 50) for k,l in form]
fields = [("%s :" % k, values.get(k, ""), l, 50) for (k, l) in form]
return self.dialog.form(
text="",
timeout=self.timeout,
@ -711,19 +714,19 @@ class Dialog(proprio.Dialog):
if self.dialog.yesno("changer l'adresse de l'adhérent pour %s ?" % ", ".join([o for o in output if o]),
title=u"Déménagement de %s %s" % (adherent['prenom'][0], adherent["nom"][0]),
defaultno=True, timeout=self.timeout) == self.dialog.DIALOG_OK:
with self.conn.search(dn=adherent.dn, scope=0, mode='rw')[0] as adherent:
adherent['postalAddress']=[unicode(pa, 'utf-8') for pa in output]
adherent['chbre']=u'EXT'
adherent.validate_changes()
adherent.history_gen()
adherent.save()
self.display_item(item=adherent, title="Adhérent déménégé hors campus, machines conservées")
raise Continue(success_cont(adherent=adherent))
with self.conn.search(dn=adherent.dn, scope=0, mode='rw')[0] as adherent:
adherent['postalAddress'] = [unicode(pa, 'utf-8') for pa in output]
adherent['chbre'] = u'EXT'
adherent.validate_changes()
adherent.history_gen()
adherent.save()
self.display_item(item=adherent, title="Adhérent déménégé hors campus, machines conservées")
raise Continue(success_cont(adherent=adherent))
else:
raise Continue(cont)
else:
adherent['postalAddress']=[unicode(pa, 'utf-8') for pa in output]
adherent['chbre']=u'EXT'
adherent['postalAddress'] = [unicode(pa, 'utf-8') for pa in output]
adherent['chbre'] = u'EXT'
return adherent
elif not keep_machine and keep_compte:
if create:
@ -741,7 +744,7 @@ class Dialog(proprio.Dialog):
for machine in adherent.machines():
with machine:
machine.delete()
adherent['chbre']=u'EXT'
adherent['chbre'] = u'EXT'
adherent.validate_changes()
adherent.history_gen()
adherent.save()
@ -770,7 +773,7 @@ class Dialog(proprio.Dialog):
for machine in adherent.machines():
with machine:
machine.delete()
adherent['chbre']=u'EXT'
adherent['chbre'] = u'EXT'
adherent.validate_changes()
adherent.history_gen()
adherent.save()
@ -842,7 +845,7 @@ class Dialog(proprio.Dialog):
cancel_cont=cont,
error_cont=self_cont,
codes_todo=[([self.dialog.DIALOG_OK], todo, [tag, menu, adherent, self_cont, cont])]
)
)
def create_adherent(self, cont):
"""Crée un adhérent et potentiellement son compte crans avec lui"""
@ -897,7 +900,7 @@ class Dialog(proprio.Dialog):
def todo(droits, adherent, self_cont, cont):
# Les vérifications de sécurité sont faites dans lc_ldap
with self.conn.search(dn=adherent.dn, scope=0, mode='rw')[0] as adherent:
adherent['droits']=[unicode(d) for d in droits]
adherent['droits'] = [unicode(d) for d in droits]
adherent.validate_changes()
adherent.history_gen()
adherent.save()
@ -949,7 +952,7 @@ class Dialog(proprio.Dialog):
def choices(max_annee):
c = []
if max_annee>=1:
if max_annee >= 1:
c.append(('1', '1ère année'))
for i in range(2, max_annee+1):
c.append((str(i), "%sème année" % i))
@ -1005,16 +1008,16 @@ class Dialog(proprio.Dialog):
]
def box_etablissement(default_item):
if etablissement == 'Autre' or \
if etablissement == 'Autre' or \
(etablissement is not None and etablissement not in [i[0] for i in choices_etablissement]) or \
(default_item is not None and default_item not in [i[0] for i in choices_etablissement]):
return self.dialog.inputbox(
return self.dialog.inputbox(
text="Choisissez l'établissement :",
title="Études de %s %s" % (adherent['prenom'][0], adherent["nom"][0]),
timeout=self.timeout,
init=str(default_item) if default_item else "")
else:
return self.dialog.menu(
else:
return self.dialog.menu(
"Choisissez l'établissement :",
width=0,
height=0,
@ -1029,26 +1032,26 @@ class Dialog(proprio.Dialog):
choices=choices_etablissement)
def box_annee(default_item):
if etablissement in LMD:
box_choice = choices_LMD
elif etablissement in LM:
box_choice = choices_LM
elif etablissement in LYCEE:
box_choice = choices_LYCEE
elif etablissement == 'ENS':
box_choice = choices_ENS
else:
box_choice = choices(7)
if not box_choice or annee == 'Autre' or \
if etablissement in LMD:
box_choice = choices_LMD
elif etablissement in LM:
box_choice = choices_LM
elif etablissement in LYCEE:
box_choice = choices_LYCEE
elif etablissement == 'ENS':
box_choice = choices_ENS
else:
box_choice = choices(7)
if not box_choice or annee == 'Autre' or \
(annee is not None and annee not in [i[0] for i in box_choice]) or \
(default_item is not None and default_item not in [i[0] for i in box_choice]):
return self.dialog.inputbox(
return self.dialog.inputbox(
text="Choisissez l'année administrative :",
title="Études de %s %s" % (adherent['prenom'][0], adherent["nom"][0]),
timeout=self.timeout,
init=str(default_item) if default_item else "")
else:
return self.dialog.menu(
else:
return self.dialog.menu(
"Choisissez l'année administrative :",
width=0,
height=0,
@ -1072,7 +1075,7 @@ class Dialog(proprio.Dialog):
timeout=self.timeout,
init=str(default_item) if default_item else "")
else:
return self.dialog.menu(
return self.dialog.menu(
"Choisissez la section :",
width=0,
height=0,
@ -1123,7 +1126,7 @@ class Dialog(proprio.Dialog):
else:
if not adherent["etudes"] or adherent["etudes"][0] != etablissement or adherent["etudes"][1] != annee or adherent["etudes"][2] != section:
with self.conn.search(dn=adherent.dn, scope=0, mode='rw')[0] as adherent:
adherent["etudes"]=[unicode(etablissement), unicode(annee), unicode(section)]
adherent["etudes"] = [unicode(etablissement), unicode(annee), unicode(section)]
adherent.validate_changes()
adherent.history_gen()
adherent.save()