normalize -> __unicode__, parsing du numéro de téléphone
This commit is contained in:
parent
8ddc74068c
commit
4bbb0ed051
2 changed files with 26 additions and 8 deletions
18
attributs.py
18
attributs.py
|
@ -32,6 +32,7 @@
|
|||
|
||||
import re
|
||||
from unicodedata import normalize
|
||||
from crans_utils import format_tel
|
||||
|
||||
def normalize_and_validate(attr, vals, ctxt):
|
||||
"""Vérifie que attr peut se voir attribuer les valeurs vals"""
|
||||
|
@ -143,7 +144,7 @@ class nom(Attr):
|
|||
def _check_type(self, values):
|
||||
return [ validate_name(v) for v in values]
|
||||
|
||||
def normalize(self, values, uldif):
|
||||
def __unicode__(self, values, uldif):
|
||||
return [ v.strip().capitalize() for v in values ]
|
||||
|
||||
class prenom(Attr):
|
||||
|
@ -153,23 +154,26 @@ class prenom(Attr):
|
|||
def _check_type(self, values):
|
||||
return [ validate_name(v) for v in values ]
|
||||
|
||||
def normalize(self, values, uldif):
|
||||
return [ values.strip().capitalize() for v in values ]
|
||||
def __unicode__(self, values, uldif):
|
||||
return [ v.strip().capitalize() for v in values ]
|
||||
|
||||
class tel(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = u"Téléphone"
|
||||
|
||||
def normalize(self, value, uldif):
|
||||
return value # XXX - To implement
|
||||
def parse_value(self, val):
|
||||
self.value = format_tel(val)
|
||||
|
||||
def __unicode__(self, value, uldif):
|
||||
return value
|
||||
|
||||
class paiement(Attr):
|
||||
singlevallue = False
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Paiement"
|
||||
|
||||
def normalize(self, values, uldif):
|
||||
def __unicode__(self, values, uldif):
|
||||
return values # XXX - To implement
|
||||
|
||||
class carteEtudiant(Attr):
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import netaddr, time, smtplib
|
||||
import netaddr, re, time, smtplib
|
||||
import config
|
||||
from unicodedata import normalize
|
||||
|
||||
|
@ -73,3 +73,17 @@ def format_mac(mac):
|
|||
raise ValueError(u"MAC nulle interdite\nIl doit être possible de modifier l'adresse de la carte.")
|
||||
return mac
|
||||
|
||||
def format_tel(tel):
|
||||
u"""Formatage des numéros de téléphone
|
||||
Transforme un numéro de téléphone pour ne contenir que des chiffres
|
||||
(00ii... pour les numéros internationaux)
|
||||
Retourne le numéro formaté.
|
||||
"""
|
||||
tel_f = tel.strip()
|
||||
if tel.startswith(u"+"):
|
||||
tel_f = u"00" + tel[1:]
|
||||
if u"(0)" in tel_f:
|
||||
tel_f = tel_f.replace(u"(0)", u"")
|
||||
tel_f = re.sub(r'\D', '', tel_f)
|
||||
return tel_f
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue