Add support for bulk-delete of Pricing Batches
This commit is contained in:
parent
38d623bcf9
commit
cf8df76788
|
@ -138,8 +138,10 @@ class BatchMasterView(MasterView):
|
||||||
g.filters['executed'].default_active = True
|
g.filters['executed'].default_active = True
|
||||||
g.filters['executed'].default_verb = 'is_null'
|
g.filters['executed'].default_verb = 'is_null'
|
||||||
|
|
||||||
g.sorters['created_by'] = g.make_sorter(model.User.username)
|
# TODO: in some cases grid has no sorters yet..e.g. when building query for bulk-delete
|
||||||
g.sorters['executed_by'] = g.make_sorter(model.User.username)
|
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_sortkey = 'created'
|
||||||
g.default_sortdir = 'desc'
|
g.default_sortdir = 'desc'
|
||||||
|
|
|
@ -44,6 +44,7 @@ class PricingBatchView(BatchMasterView):
|
||||||
url_prefix = '/batches/pricing'
|
url_prefix = '/batches/pricing'
|
||||||
creatable = False
|
creatable = False
|
||||||
rows_editable = True
|
rows_editable = True
|
||||||
|
bulk_deletable = True
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def configure_fieldset(self, fs):
|
||||||
fs.configure(
|
fs.configure(
|
||||||
|
|
|
@ -675,12 +675,19 @@ class MasterView(View):
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
query = self.get_effective_query(sortable=False)
|
query = self.get_effective_query(sortable=False)
|
||||||
count = query.count()
|
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()))
|
self.request.session.flash("Deleted {:,d} {}".format(count, self.get_model_title_plural()))
|
||||||
else:
|
else:
|
||||||
self.request.session.flash("Sorry, you must POST to do a bulk delete operation")
|
self.request.session.flash("Sorry, you must POST to do a bulk delete operation")
|
||||||
return self.redirect(self.get_index_url())
|
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):
|
def get_merge_fields(self):
|
||||||
if hasattr(self, 'merge_fields'):
|
if hasattr(self, 'merge_fields'):
|
||||||
return self.merge_fields
|
return self.merge_fields
|
||||||
|
|
Loading…
Reference in a new issue