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.8k stars 1.58k forks source link

Wrap field value with html tag #2048

Open kaldown opened 4 years ago

kaldown commented 4 years ago

I have a

class UserAdminView(ModelView):
    hidden_field = String()

and I need UserAdminView to contain a clickable URL defined by hidden_field.

Something like:

class UserAdminView(ModelView):
    hidden_field = String()
    an_url = URLField(href=build_url, value=hidden_field)

Tried

    form_overrides = {
        'an_url': MyField,
    }
    form_widget_args={
        "an_url": {
            "readonly": True,
            "href": 'http://example.com',
        },
    }

    class MyField(URLField):
        def _value(self):
            if self.data:
                self.data = build_url(self.data)
            return super()._value()

At least overridden _value gives some results. But how to safely make an URL from a resulted string. Such as it's just a text, no even I inherited from an URLField

kaldown commented 4 years ago

How to at least wrap a field with the html?