Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Add decorators to views akin to Flask Method views #2128

Open
sergioisidoro opened this issue Jul 15, 2021 · 1 comment
Open

Comments

@sergioisidoro
Copy link

sergioisidoro commented Jul 15, 2021

Flask allows method view decoration through a decorators attribute:

class UserAPI(MethodView):
    decorators = [user_required]

https://flask.palletsprojects.com/en/2.0.x/views/#decorating-views

Implementing this to flask admin would allow a more flexible decoration of the admin views :)

Could something like this work in Admin class, with BaseView having a default class attribute for decorators?

class Admin:
        ....
    def init_app
        ...
        for view in self._views:
            blueprint = view.create_blueprint(self)
            for decorator in view.decorators:
                blueprint.before_request(decorator(blueprint))
            app.register_blueprint(blueprint)
@sergioisidoro sergioisidoro changed the title [feature request] Add method views akin to Falsk [feature request] Add decorators to views akin to Flask Method views Jul 15, 2021
@caffeinatedMike
Copy link
Contributor

caffeinatedMike commented Oct 18, 2021

Decorators are already baked into ModelViews (note the @expose uses throughout the documentation). It doesn't make sense to expose decorators to all ModelView functions because most of the functions have nothing to do with routing. Since you have to explicitly use @expose on routes within a ModelView blueprint in order to make them accessible you might as well add the extra decorator to each function.

@mrjoes vetoed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants