azavea/OTM2 — pull request #62 by ahinz (2013-07-17 17:10:07+00:00)
Title: Reorganize views to avoid untestable functions (also, whitespace cleanups from 2638112 and https://github.com/azavea/OTM2/pull/57)

Standard django view practice recommends decorators and
'render_to_response' similar to:

@etag(hasher)
@json_api
def create_some_object(request):
....
return render_to_response('template', {...}, RequestContext(...))

This, however, makes it very hard to test view methods in safe and
reliable way. This commit adjusts the standard paradigm to separate the
view from the code that generates the backing data.

The general transformation is to apply decorators directly and rename
the view (continuing example from above):

create_some_object_view = etag(hasher)(json_api(create_some_object))

This solves the problem of decoupling decorators but doesn't really help
with the main template problem. To do that a new 'decorator' has been
added that allows developers to wrap a function and automatically render
a template:

plot_detail_view = instance_request(etag(_plot_hash)(
render_template('treemap/plot_detail.html', plot_detail)))

The `plot_detail` function now only needs to return `{'plot': the_plot}`