pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.79k stars 1.57k forks source link

Set use_locale=True on DecimalField #1698

Open SBillion opened 6 years ago

SBillion commented 6 years ago

I would like to set use_locale on a DecimalField in form_extra_fields. Unfortunately, I got the following error:

ERROR:flask.app:Exception on /admin/product/edit/ [GET]
Traceback (most recent call last):
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/flask_debugtoolbar/__init__.py", line 125, in dispatch_request
    return view_func(**req.view_args)
  File "/usr/lib/python3.6/cProfile.py", line 109, in runcall
    return func(*args, **kw)
  File "/home/seb/.local/share/virtualenvs/backend-tg99NPua/src/flask-admin/flask_admin/base.py", line 69, in inner
    return self._run_view(f, *args, **kwargs)
  File "/home/seb/.local/share/virtualenvs/backend-tg99NPua/src/flask-admin/flask_admin/base.py", line 368, in _run_view
    return fn(self, *args, **kwargs)
  File "/home/seb/Work/auto/foodstack/backend/app/catalog/admin/product.py", line 265, in edit_view
    return super().edit_view()
  File "/home/seb/.local/share/virtualenvs/backend-tg99NPua/src/flask-admin/flask_admin/base.py", line 69, in inner
    return self._run_view(f, *args, **kwargs)
  File "/home/seb/.local/share/virtualenvs/backend-tg99NPua/src/flask-admin/flask_admin/base.py", line 368, in _run_view
    return fn(self, *args, **kwargs)
  File "/home/seb/.local/share/virtualenvs/backend-tg99NPua/src/flask-admin/flask_admin/model/base.py", line 2097, in edit_view
    form = self.edit_form(obj=model)
  File "/home/seb/Work/auto/foodstack/backend/app/catalog/admin/product.py", line 233, in edit_form
    form = super().edit_form(obj)
  File "/home/seb/.local/share/virtualenvs/backend-tg99NPua/src/flask-admin/flask_admin/model/base.py", line 1320, in edit_form
    return self._edit_form_class(get_form_data(), obj=obj)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/wtforms/form.py", line 215, in __call__
    return type.__call__(cls, *args, **kwargs)
  File "/home/seb/.local/share/virtualenvs/backend-tg99NPua/src/flask-admin/flask_admin/form/__init__.py", line 16, in __init__
    super(BaseForm, self).__init__(formdata=formdata, obj=obj, prefix=prefix, **kwargs)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/wtforms/form.py", line 275, in __init__
    super(Form, self).__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/wtforms/form.py", line 52, in __init__
    field = meta.bind_field(self, unbound_field, options)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/wtforms/meta.py", line 27, in bind_field
    return unbound_field.bind(form=form, **options)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/wtforms/fields/core.py", line 353, in bind
    return self.field_class(*self.args, **kw)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/wtforms/fields/core.py", line 615, in __init__
    super(DecimalField, self).__init__(label, validators, **kwargs)
  File "/home/seb/.virtualenvs/backend-tg99NPua/lib/python3.6/site-packages/wtforms/fields/core.py", line 550, in __init__
    self.locale = kwargs['_form'].meta.locales[0]
TypeError: 'bool' object is not subscriptable
laszlolaszlo commented 2 years ago

Problem still exists. pip list Package Version


cachelib 0.6.0 click 8.1.2 Flask 2.1.1 Flask-Session 0.4.0 Flask-WTF 1.0.1 gunicorn 20.1.0 importlib-metadata 4.11.3 itsdangerous 2.1.2 Jinja2 3.1.1 MarkupSafe 2.1.1 pip 22.0.4 setuptools 58.1.0 Werkzeug 2.1.1 WTForms 3.0.1 zipp 3.8.0

TypeError: 'bool' object is not subscriptable

inputfield1 = DecimalField(label='Take Profit1 Price', rounding=None, use_locale=True)

Workaround: remove use_locale=True. But I like to use locale. Please give advice. Thanks