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

BaseView and excluding methods #117

Open
btoconnor opened this issue Dec 19, 2019 · 0 comments
Open

BaseView and excluding methods #117

btoconnor opened this issue Dec 19, 2019 · 0 comments

Comments

@btoconnor
Copy link

I was just implementing a project and read up on the documentation about specifying base views. While this works, it seems a little clunky and prone to errors. I was wondering if the project would be open to inferring the routes from the class' __dict__?

Something akin to this (could be cleaned up a little, but as an example works fine:

# foo.py
from flask_classful import FlaskView

class FooView(FlaskView):
    def get(self, id):
        pass # etc

# somewhere_else.py
def routes(view):
    routes = []
    for k, v in view.__dict__.items():
        if callable(v) and not k.startswith('_'):
            routes.append(k)
    return routes

The above example would return ['get'], avoids gathering any methods defined on parent classes, and works for larger inheritance chains AFAICT.

(I added the bit obviously about not starting with _, but it seems like a reasonable addition?)

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

No branches or pull requests

1 participant