hasjob icon indicating copy to clipboard operation
hasjob copied to clipboard

Move to Class-Based Views

Open iambibhas opened this issue 8 years ago • 2 comments

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.

iambibhas avatar Aug 31 '16 21:08 iambibhas

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 avatar Sep 01 '16 05:09 jace

This is now in Coaster's StateManager and ClassView.

jace avatar Feb 15 '18 10:02 jace