[TELE-1398]add is_valid_iban
This commit is contained in:
parent
b72cd08029
commit
da44dad325
|
@ -11,6 +11,11 @@ from wcs.qommon.templatetags.qommon import unlazy
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def clean_string(value):
|
||||||
|
return value.replace(" ", "").replace(".", "").replace("-", "")
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def check_class(value):
|
def check_class(value):
|
||||||
return str(type(value))
|
return str(type(value))
|
||||||
|
@ -66,7 +71,7 @@ def is_valid_tva_number(tva_number, formatage=True):
|
||||||
"""
|
"""
|
||||||
# si formatage alors enlève les espaces, points et tirets
|
# si formatage alors enlève les espaces, points et tirets
|
||||||
if formatage:
|
if formatage:
|
||||||
tva_number = tva_number.replace(" ", "").replace(".", "").replace("-", "")
|
tva_number = clean_string(tva_number)
|
||||||
|
|
||||||
if not tva_number[:2].upper() == "BE":
|
if not tva_number[:2].upper() == "BE":
|
||||||
return False
|
return False
|
||||||
|
@ -84,6 +89,39 @@ def is_valid_tva_number(tva_number, formatage=True):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def is_valid_iban(iban, formatage=True):
|
||||||
|
"""
|
||||||
|
iban : (str) iban
|
||||||
|
formatage : (bool) True/False
|
||||||
|
return : (bool) True si le numéro est valide
|
||||||
|
"""
|
||||||
|
iban_validation_modulo = 97
|
||||||
|
iban = iban.upper()
|
||||||
|
if formatage:
|
||||||
|
iban = clean_string(iban)
|
||||||
|
if len(iban) < 5:
|
||||||
|
return False
|
||||||
|
modified_iban = iban[4: len(iban)] + iban[0:4]
|
||||||
|
numeric_iban_string = ""
|
||||||
|
for c in modified_iban:
|
||||||
|
current_char_code = ord(c)
|
||||||
|
# Integer
|
||||||
|
if (current_char_code > 47) and (current_char_code < 58):
|
||||||
|
numeric_iban_string = numeric_iban_string + c
|
||||||
|
# Char
|
||||||
|
elif (current_char_code > 64) and (current_char_code < 91):
|
||||||
|
value = current_char_code - 65 + 10
|
||||||
|
numeric_iban_string = numeric_iban_string + str(value)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
previous_modulo = 0
|
||||||
|
for i in range(0, len(numeric_iban_string), 5):
|
||||||
|
subpart = str(previous_modulo) + "" + numeric_iban_string[i: i + 5]
|
||||||
|
previous_modulo = int(subpart) % iban_validation_modulo
|
||||||
|
return previous_modulo == 1
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def liste_type_rdv_plusieurs_personnes(value):
|
def liste_type_rdv_plusieurs_personnes(value):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue