0001-misc-check-for-correct-number-of-digits-in-French-ph.patch
tests/test_widgets.py | ||
---|---|---|
698 | 698 |
mock_form_submission(req, widget, {'test': '0123456789'}) |
699 | 699 |
assert not widget.has_error() |
700 | 700 | |
701 |
widget = WcsExtraStringWidget('test', value='foo', required=False) |
|
702 |
widget.field = fakefield |
|
703 |
mock_form_submission(req, widget, {'test': '01 23 45 67 89'}) |
|
704 |
assert not widget.has_error() |
|
705 | ||
701 | 706 |
widget = WcsExtraStringWidget('test', value='foo', required=False) |
702 | 707 |
widget.field = fakefield |
703 | 708 |
mock_form_submission(req, widget, {'test': 'az'}) |
... | ... | |
708 | 713 |
mock_form_submission(req, widget, {'test': '0123'}) |
709 | 714 |
assert widget.has_error() |
710 | 715 | |
716 |
widget = WcsExtraStringWidget('test', value='foo', required=False) |
|
717 |
widget.field = fakefield |
|
718 |
mock_form_submission(req, widget, {'test': '01234567890123'}) |
|
719 |
assert widget.has_error() |
|
720 | ||
711 | 721 |
# and check it gets a special HTML input type |
712 | 722 |
assert 'type="tel"' in str(widget.render()) |
713 | 723 |
wcs/qommon/form.py | ||
---|---|---|
939 | 939 |
validation_methods = collections.OrderedDict([ |
940 | 940 |
('digits', {'title': N_('Digits'), 'regex': '\d+'}), |
941 | 941 |
('phone', {'title': N_('Phone Number'), 'regex': r'\+?[-\(\)\d\.\s/]+', 'html_input_type': 'tel'}), |
942 |
('phone-fr', {'title': N_('Phone Number (France)'), 'regex': '0[\d\.\s]{9}', 'html_input_type': 'tel'}),
|
|
942 |
('phone-fr', {'title': N_('Phone Number (France)'), 'function': 'validate_phone_fr', 'html_input_type': 'tel'}),
|
|
943 | 943 |
('zipcode-fr', {'title': N_('Zip Code (France)'), 'regex': '\d{5}'}), |
944 | 944 |
('siren-fr', {'title': N_('SIREN Code (France)'), 'function': 'validate_siren'}), |
945 | 945 |
('siret-fr', {'title': N_('SIRET Code (France)'), 'function': 'validate_siret'}), |
wcs/qommon/misc.py | ||
---|---|---|
705 | 705 |
return string_value and all((x in '0123456789' for x in string_value)) |
706 | 706 | |
707 | 707 | |
708 |
def validate_phone_fr(string_value): |
|
709 |
if not re.match(r'^0[\d\.\s]+$', string_value): |
|
710 |
# leading zero, then digits, dots, or spaces |
|
711 |
return False |
|
712 |
return len([x for x in string_value if is_ascii_digit(x)]) == 10 |
|
713 | ||
714 | ||
708 | 715 |
def validate_siren(string_value): |
709 | 716 |
return validate_luhn(string_value, length=9) |
710 | 717 | |
711 |
- |