From 545f3492723ac2e3eafcae59cde8150565e37788 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Wed, 8 Feb 2023 19:22:37 +0000 Subject: [PATCH] Fix translating after WTForms 3 removed form._get_translations --- flask_admin/form/__init__.py | 9 +++++---- flask_admin/tests/sqla/test_inlineform.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/flask_admin/form/__init__.py b/flask_admin/form/__init__.py index 6fbbd1f606..b1e7a38b4e 100644 --- a/flask_admin/form/__init__.py +++ b/flask_admin/form/__init__.py @@ -14,16 +14,17 @@ class BaseForm(form.Form): - _translations = Translations() + class Meta: + _translations = Translations() + + def get_translations(self, form): + return self._translations def __init__(self, formdata=None, obj=None, prefix=u'', **kwargs): self._obj = obj super(BaseForm, self).__init__(formdata=formdata, obj=obj, prefix=prefix, **kwargs) - def _get_translations(self): - return self._translations - class FormOpts(object): __slots__ = ['widget_args', 'form_rules'] diff --git a/flask_admin/tests/sqla/test_inlineform.py b/flask_admin/tests/sqla/test_inlineform.py index 8523b1f63c..80d62c85db 100644 --- a/flask_admin/tests/sqla/test_inlineform.py +++ b/flask_admin/tests/sqla/test_inlineform.py @@ -283,8 +283,9 @@ def ngettext(self, *args): return 'success!' class StubBaseForm(form.BaseForm): - def _get_translations(self): - return StubTranslation() + class Meta: + def get_translations(self, form): + return StubTranslation() # Set up Admin class UserModelView(ModelView):