Commit 2c167403 authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue
Browse files

PEP8 + un peu de nettoyage

parent 13555c73
......@@ -29,8 +29,8 @@ from whos import aff
import signal
import getopt
from time import strftime, strptime, localtime, mktime, time
from dateutil import relativedelta as rdelta
from datetime import date
import datetime
from dateutil.relativedelta import relativedelta
import re
import subprocess
import affich_tools
......@@ -54,6 +54,8 @@ iscontroleur = u'Tresorier' in droits
isbureau = u'Bureau' in droits
encoding = sys.stdin.encoding or 'UTF-8'
NAISSANCE_RE = re.compile(r"(?P<jour>[^ ]*)/(?P<mois>[^ ]*)/(?P<annee>[^ ]*)")
if u'Nounou' in droits:
# Si on est nounou
if os.path.exists(os.path.expanduser('~/.dialogrc')):
......@@ -113,14 +115,20 @@ def set_bases(adher):
# Traitement
err = ''
try: adher.nom(result[0])
except ValueError, c: err += c.args[0] + '\n'
try:
adher.nom(result[0])
except ValueError, c:
err += c.args[0] + '\n'
try: adher.prenom(result[1])
except ValueError, c: err += c.args[0] + '\n'
try:
adher.prenom(result[1])
except ValueError, c:
err += c.args[0] + '\n'
try: adher.tel(result[2])
except ValueError, c: err += c.args[0] + '\n'
try:
adher.tel(result[2])
except ValueError, c:
err += c.args[0] + '\n'
# Un adhérent du même nom existe-t-il déjà ?
req = 'nom=' + result[0] + '&prenom=' + result[1]
......@@ -133,15 +141,14 @@ def set_bases(adher):
return 1
# On controle que l'adh est majeur
Now = date.today()
naissance = re.compile(r"(?P<jour>[^ ]*)/(?P<mois>[^ ]*)/(?P<annee>[^ ]*)").match(unicode(result[4]))
naissance = NAISSANCE_RE.match(result[4].decode(config.in_encoding))
if naissance is None:
err += "La date est invalide"
else:
naissance = naissance.groupdict()
try:
naissance_date = date(int(naissance['annee']),int(naissance['mois']),int(naissance['jour']))
age = rdelta.relativedelta(Now, naissance_date).years
naissance_date = datetime.date(int(naissance['annee']), int(naissance['mois']), int(naissance['jour']))
age = relativedelta(datetime.date.today(), naissance_date).years
if age < 18:
arg = u'--title "Inscription adhérent" '
arg += u'--yesno "Cet adhérent est mineur, merci de demander un accord écrit des parents'
......@@ -149,7 +156,8 @@ def set_bases(adher):
no, res = dialog(arg)
if no:
return 1
except ValueError, c: err += c.args[0] + '\n'
except ValueError, c:
err += c.args[0] + '\n'
err += _set_chbre(adher, result[3])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment