Add support for bulk-delete of Pricing Batches

This commit is contained in:
Lance Edgar 2017-05-24 18:10:38 -05:00
parent 38d623bcf9
commit cf8df76788
3 changed files with 13 additions and 3 deletions

View file

@ -138,8 +138,10 @@ class BatchMasterView(MasterView):
g.filters['executed'].default_active = True
g.filters['executed'].default_verb = 'is_null'
g.sorters['created_by'] = g.make_sorter(model.User.username)
g.sorters['executed_by'] = g.make_sorter(model.User.username)
# TODO: in some cases grid has no sorters yet..e.g. when building query for bulk-delete
if hasattr(g, 'sorters'):
g.sorters['created_by'] = g.make_sorter(model.User.username)
g.sorters['executed_by'] = g.make_sorter(model.User.username)
g.default_sortkey = 'created'
g.default_sortdir = 'desc'

View file

@ -44,6 +44,7 @@ class PricingBatchView(BatchMasterView):
url_prefix = '/batches/pricing'
creatable = False
rows_editable = True
bulk_deletable = True
def configure_fieldset(self, fs):
fs.configure(

View file

@ -675,12 +675,19 @@ class MasterView(View):
if self.request.method == 'POST':
query = self.get_effective_query(sortable=False)
count = query.count()
query.delete(synchronize_session=False)
self.bulk_delete_objects(query)
self.request.session.flash("Deleted {:,d} {}".format(count, self.get_model_title_plural()))
else:
self.request.session.flash("Sorry, you must POST to do a bulk delete operation")
return self.redirect(self.get_index_url())
def bulk_delete_objects(self, query):
# TODO: sometimes the first makes sense, and would be preferred for
# efficiency's sake. might even need to add progress to latter?
# query.delete(synchronize_session=False)
for obj in query:
self.Session.delete(obj)
def get_merge_fields(self):
if hasattr(self, 'merge_fields'):
return self.merge_fields