Add "bulk delete rows" feature to new batches view

This commit is contained in:
Lance Edgar 2016-10-04 15:12:30 -05:00
parent f41135a2e0
commit 894ee87591
2 changed files with 10 additions and 5 deletions

View file

@ -46,7 +46,7 @@ from pyramid import httpexceptions
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
from pyramid.response import FileResponse from pyramid.response import FileResponse
from pyramid_simpleform import Form from pyramid_simpleform import Form
from webhelpers.html import HTML from webhelpers.html import HTML, tags
from tailbone import forms, newgrids as grids from tailbone import forms, newgrids as grids
from tailbone.db import Session from tailbone.db import Session
@ -319,6 +319,11 @@ class BatchMasterView(MasterView):
return self.render_to_response('edit', context) return self.render_to_response('edit', context)
def make_row_grid_tools(self, batch):
if not batch.executed:
url = self.request.route_url('{}.delete_rows'.format(self.get_route_prefix()), uuid=batch.uuid)
return HTML.tag('p', c=tags.link_to("Delete all rows matching current search", url))
def redirect_after_edit(self, batch): def redirect_after_edit(self, batch):
""" """
Redirect back to edit batch page after editing a batch, unless the Redirect back to edit batch page after editing a batch, unless the
@ -701,8 +706,8 @@ class BatchMasterView(MasterView):
permission='{}.create'.format(permission_prefix)) permission='{}.create'.format(permission_prefix))
# bulk delete rows # bulk delete rows
config.add_route('{}.rows.bulk_delete'.format(route_prefix), '{}/{{uuid}}/rows/delete'.format(url_prefix)) config.add_route('{}.delete_rows'.format(route_prefix), '{}/{{uuid}}/rows/delete'.format(url_prefix))
config.add_view(cls, attr='bulk_delete_rows', route_name='{}.rows.bulk_delete'.format(route_prefix), config.add_view(cls, attr='bulk_delete_rows', route_name='{}.delete_rows'.format(route_prefix),
permission='{}.edit'.format(permission_prefix)) permission='{}.edit'.format(permission_prefix))
# execute batch # execute batch

View file

@ -175,10 +175,10 @@ class MasterView(View):
} }
if self.has_rows: if self.has_rows:
context['rows_grid'] = grid.render_complete(allow_save_defaults=False, context['rows_grid'] = grid.render_complete(allow_save_defaults=False,
tools=self.make_row_grid_tools()) tools=self.make_row_grid_tools(instance))
return self.render_to_response('view', context) return self.render_to_response('view', context)
def make_row_grid_tools(self): def make_row_grid_tools(self, instance):
pass pass
def make_row_grid(self, **kwargs): def make_row_grid(self, **kwargs):