Skip to content

Instantly share code, notes, and snippets.

@hbradio
Created August 22, 2017 20:17
Show Gist options
  • Save hbradio/ef1ef6d47de5a1c8964e294d94c0535f to your computer and use it in GitHub Desktop.
Save hbradio/ef1ef6d47de5a1c8964e294d94c0535f to your computer and use it in GitHub Desktop.
class GridView(BaseView):
grid_cls = None
template = 'grid-view.html'
title = None
def get(self):
return self.render_grid()
def render_grid(self):
if self.grid_cls is None:
raise NotImplementedError(
'You must set {}.grid_cls to render a grid'.format(self.__class__.__name__)
)
g = self.grid_cls()
g.apply_qs_args()
if hasattr(self, 'setup_grid'):
self.setup_grid(g)
if g.export_to == 'xls':
raise ImmediateResponse(g.xls.as_response())
template_args = {
'grid': g,
'title': self.title,
}
return flask.render_template(
self.template,
**template_args
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment