level12 / keg-app-cookiecutter

0 stars 0 forks source link

Add grid support #41

Closed rsyring closed 4 years ago

rsyring commented 6 years ago

Should probably put GridView and company in Keg Elements and then put example usage in this cookiecutter:

class GridView(AuthenticatedView):
    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':
            if g.xls is None:
                raise DependencyError('The xlwt library has to be installed for Excel export.')
            raise ImmediateResponse(g.xls.as_response())

        template_args = {
            'grid': g,
            'title': self.title,
        }

        return flask.render_template(self.template, **template_args)

The example above is from RaceBetter.

rsyring commented 5 years ago

There is a grid now and a CrudView, which uses a grid, but no GridView instantiated directly.