From 8a6f4b6226228034a4b9076c0641fa19e8b15891 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Wed, 16 Oct 2013 22:18:49 +0200 Subject: Fix locale support for forms --- app/forms.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'app/forms.py') diff --git a/app/forms.py b/app/forms.py index e744934..8cf9b6e 100644 --- a/app/forms.py +++ b/app/forms.py @@ -6,6 +6,7 @@ from wtforms import validators as v from wtforms import fields from wtforms.ext.sqlalchemy.fields import QuerySelectField +from wtforms.ext.i18n.form import Form as i18nForm import datetime @@ -26,8 +27,10 @@ class DecimalField(fields.DecimalField): req = [v.input_required()] -class Form(_Form): - LOCALES = ['de_DE', 'de'] +class Form(_Form, i18nForm): + # docs say LOCALES, code says LANGUAGES ... use both :) + LANGUAGES = LOCALES = ['de_DE', 'de'] + def __init__ (self, *args, **kwargs): self._msg = kwargs.pop('flash', u"Fehler im Formular!") _Form.__init__(self, *args, **kwargs) @@ -45,6 +48,12 @@ class Form(_Form): def validate_on_submit (self): return self.is_submitted() and self.flash_validate() + def _get_translations(self): + # use WTForms builtin translation support instead of the flask-babael + # stuff added by flask-wtf + # FIXME: remove this, if flask-babel is used in the app + return i18nForm._get_translations(self) + class ExpenseForm(Form): date = DateField(u'Datum', req, format="%d.%m.%Y", -- cgit v1.2.3-70-g09d2