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

Commit

Permalink
Adds an error message for duplicate labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Nov 16, 2015
1 parent 9c29880 commit 049cb00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
Unreleased
~~~~~~~~~~

- Adds an error message for duplicate labels.
[href]

- Fixes fieldsets only showing up once on static forms.
[href]

Expand Down
6 changes: 5 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: 2015-10-15 09:43+0200\n"
"POT-Creation-Date: 2015-11-16 16:31+0100\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 @@ -36,6 +36,10 @@ msgstr ""
msgid "The syntax on line {line} is not valid."
msgstr "Der Syntax in der {line}. Zeile ist ungültig."

#, python-format
msgid "The field '{label}' exists more than once."
msgstr "Das Feld '{label}' kommt doppelt vor."

msgid "Uploaded file"
msgstr "Hochgeladene Datei"

Expand Down
7 changes: 6 additions & 1 deletion onegov/form/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mimetypes import types_map
from onegov.form import _
from onegov.form.core import with_options
from onegov.form.errors import InvalidFormSyntax
from onegov.form.errors import InvalidFormSyntax, DuplicateLabelError
from stdnum.exceptions import ValidationError as StdnumValidationError
from wtforms import ValidationError

Expand Down Expand Up @@ -111,6 +111,7 @@ class ValidFormDefinition(object):
message = _("The form could not be parsed.")
email = _("Define at least one required e-mail field ('E-Mail * = @@@')")
syntax = _("The syntax on line {line} is not valid.")
duplicate = _("The field '{label}' exists more than once.")

def __init__(self, require_email_field=True):
self.require_email_field = require_email_field
Expand All @@ -129,6 +130,10 @@ def __call__(self, form, field):
raise ValidationError(
field.gettext(self.syntax).format(line=e.line)
)
except DuplicateLabelError as e:
raise ValidationError(
field.gettext(self.duplicate).format(label=e.label)
)
except AttributeError:
raise ValidationError(field.gettext(self.message))
else:
Expand Down

0 comments on commit 049cb00

Please sign in to comment.