Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Adds a phone number validator
Browse files Browse the repository at this point in the history
  • Loading branch information
msom committed Sep 18, 2018
1 parent 44fc802 commit 4032af6
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
---------

- Adds a phone number validator.
[msom]

0.35.0 (2018-09-12)
~~~~~~~~~~~~~~~~~~~

Expand Down
8 changes: 7 additions & 1 deletion onegov/form/locale/de_ch/LC_MESSAGES/onegov.form.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2017-10-19 14:34+0200\n"
"POT-Creation-Date: 2018-09-18 15:53+0200\n"
"PO-Revision-Date: 2015-10-15 09:43+0200\n"
"Last-Translator: Denis Krienbühl <denis.krienbuehl@seantis.ch>\n"
"Language-Team: German\n"
Expand Down Expand Up @@ -51,6 +51,9 @@ msgid "'{label}' is a reserved name. Please use a different name."
msgstr ""
"'{label}' ist ein reservierter Name. Bitte verwenden Sie einen anderen Namen."

msgid "Not a valid phone number."
msgstr "Ungültige Telefonnummer."

msgid "Uploaded file"
msgstr "Hochgeladene Datei"

Expand Down Expand Up @@ -131,3 +134,6 @@ msgstr "UID Nummer"

msgid "Swiss vat number"
msgstr "MWST Nummer"

msgid "Markdown"
msgstr ""
8 changes: 7 additions & 1 deletion onegov/form/locale/fr_CH/LC_MESSAGES/onegov.form.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2017-10-19 14:34+0200\n"
"POT-Creation-Date: 2018-09-18 15:53+0200\n"
"PO-Revision-Date: 2015-10-15 09:43+0200\n"
"Last-Translator: Denis Krienbühl <denis.krienbuehl@seantis.ch>\n"
"Language-Team: French\n"
Expand Down Expand Up @@ -49,6 +49,9 @@ msgstr "Le champ '{label}' existe plus d'une fois."
msgid "'{label}' is a reserved name. Please use a different name."
msgstr "'{label}' est un nom réservé. Veuillez utiliser un nom différent."

msgid "Not a valid phone number."
msgstr "N'est pas un numéro de téléphone valide."

msgid "Uploaded file"
msgstr "Fichier téléchargé"

Expand Down Expand Up @@ -129,3 +132,6 @@ msgstr "Identificateur suisse d'entreprise"

msgid "Swiss vat number"
msgstr "Numéro de TVA suisse"

msgid "Markdown"
msgstr ""
135 changes: 135 additions & 0 deletions onegov/form/locale/it_CH/LC_MESSAGES/onegov.form.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#
# Italian translations for PACKAGE package
# Traduzioni italiane per il pacchetto PACKAGE.
# This file is distributed under the same license as the PACKAGE package.
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2018-09-18 15:53+0200\n"
"PO-Revision-Date: 2018-09-18 15:45+0200\n"
"Last-Translator: Marc Sommerhalder <marc.sommerhalder@seantis.ch>\n"
"Language-Team: Italian\n"
"Language: it_CH\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Lingua 3.12\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Required"
msgstr ""

msgid "Optional"
msgstr ""

#, python-format
msgid "The file is too large, please provide a file smaller than {}."
msgstr ""

msgid "Files of this type are not supported."
msgstr ""

msgid "The form could not be parsed."
msgstr ""

msgid "Define at least one required e-mail field ('E-Mail * = @@@')"
msgstr ""

#, python-format
msgid "The syntax on line {line} is not valid."
msgstr ""

#, python-format
msgid "The field '{label}' exists more than once."
msgstr ""

#, python-format
msgid "'{label}' is a reserved name. Please use a different name."
msgstr ""

msgid "Not a valid phone number."
msgstr "Non è un numero di telefono valido."

msgid "Uploaded file"
msgstr ""

msgid "Keep file"
msgstr ""

msgid "Delete file"
msgstr ""

msgid "Replace file"
msgstr ""

msgid "General"
msgstr ""

msgid "Title"
msgstr ""

msgid "Text"
msgstr ""

msgid "Multiline"
msgstr ""

msgid "E-Mail"
msgstr ""

msgid "Website"
msgstr ""

msgid "Date and time"
msgstr ""

msgid "Date"
msgstr ""

msgid "Time"
msgstr ""

msgid "Choices"
msgstr ""

msgid "Choice"
msgstr ""

msgid "Multiple Choice"
msgstr ""

msgid "Files"
msgstr ""

msgid "Image"
msgstr ""

msgid "Document"
msgstr ""

msgid "Numbers"
msgstr ""

msgid "Age"
msgstr ""

msgid "Percentage"
msgstr ""

msgid "Extended"
msgstr ""

msgid "IBAN"
msgstr ""

msgid "Swiss social security number"
msgstr ""

msgid "Swiss business identifier"
msgstr ""

msgid "Swiss vat number"
msgstr ""

msgid "Markdown"
msgstr ""
135 changes: 135 additions & 0 deletions onegov/form/locale/rm_CH/LC_MESSAGES/onegov.form.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#
# Romansh translations for PACKAGE package
# This file is distributed under the same license as the PACKAGE package.
# Marc Sommerhalder <marc.sommerhalder@seantis.c>, 2018.
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2018-09-18 15:53+0200\n"
"PO-Revision-Date: 2017-06-28 12:03+0200\n"
"Last-Translator: Marc Sommerhalder <marc.sommerhalder@seantis.ch>\n"
"Language-Team: Romansh\n"
"Language: rm\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Lingua 3.12\n"
"X-Generator: Poedit 2.0.2\n"

msgid "Required"
msgstr ""

msgid "Optional"
msgstr ""

#, python-format
msgid "The file is too large, please provide a file smaller than {}."
msgstr ""

msgid "Files of this type are not supported."
msgstr ""

msgid "The form could not be parsed."
msgstr ""

msgid "Define at least one required e-mail field ('E-Mail * = @@@')"
msgstr ""

#, python-format
msgid "The syntax on line {line} is not valid."
msgstr ""

#, python-format
msgid "The field '{label}' exists more than once."
msgstr ""

#, python-format
msgid "'{label}' is a reserved name. Please use a different name."
msgstr ""

msgid "Not a valid phone number."
msgstr "Numer da telefon nunvalaivel."

msgid "Uploaded file"
msgstr ""

msgid "Keep file"
msgstr ""

msgid "Delete file"
msgstr ""

msgid "Replace file"
msgstr ""

msgid "General"
msgstr ""

msgid "Title"
msgstr ""

msgid "Text"
msgstr ""

msgid "Multiline"
msgstr ""

msgid "E-Mail"
msgstr ""

msgid "Website"
msgstr ""

msgid "Date and time"
msgstr ""

msgid "Date"
msgstr ""

msgid "Time"
msgstr ""

msgid "Choices"
msgstr ""

msgid "Choice"
msgstr ""

msgid "Multiple Choice"
msgstr ""

msgid "Files"
msgstr ""

msgid "Image"
msgstr ""

msgid "Document"
msgstr ""

msgid "Numbers"
msgstr ""

msgid "Age"
msgstr ""

msgid "Percentage"
msgstr ""

msgid "Extended"
msgstr ""

msgid "IBAN"
msgstr ""

msgid "Swiss social security number"
msgstr ""

msgid "Swiss business identifier"
msgstr ""

msgid "Swiss vat number"
msgstr ""

msgid "Markdown"
msgstr ""
33 changes: 33 additions & 0 deletions onegov/form/tests/test_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from onegov.form.validators import ValidPhoneNumber
from pytest import raises
from wtforms.validators import ValidationError


def test_phone_number_validator():

class Field(object):
def __init__(self, data):
self.data = data

validator = ValidPhoneNumber()

validator(None, Field(None))
validator(None, Field(''))

validator(None, Field('+41791112233'))
validator(None, Field('0041791112233'))
validator(None, Field('0791112233'))

with raises(ValidationError):
validator(None, Field(1234))
with raises(ValidationError):
validator(None, Field('1234'))

with raises(ValidationError):
validator(None, Field('+417911122333'))
with raises(ValidationError):
validator(None, Field('041791112233'))
with raises(ValidationError):
validator(None, Field('041791112233'))
with raises(ValidationError):
validator(None, Field('00791112233'))
Loading

0 comments on commit 4032af6

Please sign in to comment.