From a51bf54e945506122ceb0f4e68736d16902a0ac4 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 6 Nov 2016 13:34:08 -0600 Subject: [PATCH] Prevent user from adding new rows to batch which has already been executed --- tailbone/views/batch.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tailbone/views/batch.py b/tailbone/views/batch.py index 05f66955..127e66dd 100644 --- a/tailbone/views/batch.py +++ b/tailbone/views/batch.py @@ -332,13 +332,29 @@ class BatchMasterView(MasterView): return self.render_to_response('edit', context) + def create_row(self): + """ + Only allow creating a new row if the batch hasn't yet been executed. + """ + batch = self.get_instance() + if batch.executed: + self.request.session.flash("You cannot add new rows to a batch which has been executed") + return self.redirect(self.get_action_url('view', batch)) + return super(BatchMasterView, self).create_row() + + def make_default_row_grid_tools(self, batch): + if self.rows_creatable and not batch.executed: + link = tags.link_to("Create a new {}".format(self.get_row_model_title()), + self.get_action_url('create_row', batch)) + return HTML.tag('p', c=link) + def make_batch_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 make_row_grid_tools(self, batch): - return self.make_batch_row_grid_tools(batch) + return self.make_default_row_grid_tools(obj) + self.make_batch_row_grid_tools(batch) def redirect_after_edit(self, batch): """