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

Move to Class-Based Views #361

Open
iambibhas opened this issue Aug 31, 2016 · 2 comments
Open

Move to Class-Based Views #361

iambibhas opened this issue Aug 31, 2016 · 2 comments

Comments

@iambibhas
Copy link
Contributor

iambibhas commented Aug 31, 2016

Flask supports CBVs. Moving to them might give us cleaner code as we can separate get() post() methods to handle requests. E.g. from Flask doc -

class CounterAPI(MethodView):
    def get(self):
        return session.get('counter', 0)

    def post(self):
        session['counter'] = session.get('counter', 0) + 1
        return 'OK'

app.add_url_rule('/counter', view_func=CounterAPI.as_view('counter'))

Some views handle forms during POST requests and right now we're just using request.method == 'POST' to handle them. We could do that better.

@jace
Copy link
Member

jace commented Sep 1, 2016

We actually have something better than this. Class-based views aren't particularly better than what we have (we could just split views into two methods). I've been working on a library named docflow that is available via Coaster. It provides workflows that sit between the model and the view and clean up a lot of cruft present in both. Docflow was written after Hasjob, so Hasjob hasn't been updated to use it.

@jace
Copy link
Member

jace commented Feb 15, 2018

This is now in Coaster's StateManager and ClassView.

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