Skip to content
Snippets Groups Projects
Commit 8c77e29f authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Use better validation for duration(s)

parent 2367e3cd
Branches
No related tags found
1 merge request!4Submission form
from django import forms from django import forms
from django.core.exceptions import ValidationError
from AKModel.models import AK, AKOwner from AKModel.models import AK, AKOwner
...@@ -51,6 +52,16 @@ class AKForm(forms.ModelForm): ...@@ -51,6 +52,16 @@ class AKForm(forms.ModelForm):
duration = int(h) + int(m) / 60 duration = int(h) + int(m) / 60
if "," in str(duration): if "," in str(duration):
duration = float(duration.replace(",", ".")) duration = float(duration.replace(",", "."))
try:
float(duration)
except ValueError:
raise ValidationError(
_('"%(duration)s" is not a valid duration'),
code='invalid',
params={'duration': duration},
)
return duration return duration
def clean(self): def clean(self):
......
...@@ -8,7 +8,7 @@ msgid "" ...@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-10-24 21:34+0000\n" "POT-Creation-Date: 2019-10-24 23:21+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
...@@ -17,15 +17,20 @@ msgstr "" ...@@ -17,15 +17,20 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: forms.py:38 #: forms.py:39
msgid "Separate multiple tags with semicolon" msgid "Separate multiple tags with semicolon"
msgstr "Mehrere Tags mit Semikolon trennen" msgstr "Mehrere Tags mit Semikolon trennen"
#: forms.py:80 #: forms.py:60
#, python-format
msgid "\"%(duration)s\" is not a valid duration"
msgstr "\"%(duration)s\" ist keine gültige Dauer"
#: forms.py:94
msgid "Duration(s)" msgid "Duration(s)"
msgstr "Dauer(n)" msgstr "Dauer(n)"
#: forms.py:81 #: forms.py:95
msgid "" msgid ""
"Enter at least one planned duration (in hours). If your AK should have " "Enter at least one planned duration (in hours). If your AK should have "
"multiple slots, use multiple lines" "multiple slots, use multiple lines"
...@@ -188,14 +193,14 @@ msgstr "" ...@@ -188,14 +193,14 @@ msgstr ""
msgid "AK successfully created" msgid "AK successfully created"
msgstr "AK erfolgreich angelegt" msgstr "AK erfolgreich angelegt"
#: views.py:151 #: views.py:152
msgid "AK successfully updated" msgid "AK successfully updated"
msgstr "AK erfolgreich bearbeitet" msgstr "AK erfolgreich bearbeitet"
#: views.py:208 #: views.py:209
msgid "Person Info successfully updated" msgid "Person Info successfully updated"
msgstr "Personen-Info erfolgreich bearbeitet" msgstr "Personen-Info erfolgreich bearbeitet"
#: views.py:220 #: views.py:221
msgid "No user selected" msgid "No user selected"
msgstr "Keine Person ausgewählt" msgstr "Keine Person ausgewählt"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment