From 9b796642642b2059513de3051e999c798a8d2a31 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Sat, 16 Oct 2010 17:48:03 +0200 Subject: [PATCH] =?UTF-8?q?[attributs]=20Nettoyage=20de=20la=20validation?= =?UTF-8?q?=20du=20T=C3=A9l=C3=A9phone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributs.py | 2 ++ crans_utils.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/attributs.py b/attributs.py index 467b5ca..f1f6940 100644 --- a/attributs.py +++ b/attributs.py @@ -160,6 +160,8 @@ class tel(Attr): def parse_value(self, val): self.value = format_tel(val) + if len(self.value) == 0: + raise ValueError("Numéro de téléphone invalide ('%s')" % val) def __unicode__(self): return self.value diff --git a/crans_utils.py b/crans_utils.py index ed02c11..cf9a693 100644 --- a/crans_utils.py +++ b/crans_utils.py @@ -80,8 +80,8 @@ def format_tel(tel): Retourne le numéro formaté. """ tel_f = tel.strip() - if tel.startswith(u"+"): - tel_f = u"00" + tel[1:] + if tel_f.startswith(u"+"): + tel_f = u"00" + tel_f[1:] if u"(0)" in tel_f: tel_f = tel_f.replace(u"(0)", u"") tel_f = re.sub(r'\D', '', tel_f)