hasjob
hasjob copied to clipboard
Move to Class-Based Views
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.
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.
This is now in Coaster's StateManager and ClassView.