Refactor purchasing batch views to use master3
This commit is contained in:
parent
d20601c359
commit
eac59ba5c8
6 changed files with 233 additions and 154 deletions
|
@ -65,7 +65,6 @@ class BatchMasterView(MasterView):
|
|||
rows_downloadable_csv = True
|
||||
refreshable = True
|
||||
refresh_after_create = False
|
||||
edit_with_rows = False
|
||||
cloneable = False
|
||||
executable = True
|
||||
results_executable = False
|
||||
|
@ -311,53 +310,14 @@ class BatchMasterView(MasterView):
|
|||
else:
|
||||
return self.redirect(self.get_action_url('view', batch, mobile=mobile))
|
||||
|
||||
# TODO: some of this at least can go to master now right?
|
||||
def edit(self):
|
||||
"""
|
||||
Don't allow editing a batch which has already been executed.
|
||||
"""
|
||||
self.editing = True
|
||||
batch = self.get_instance()
|
||||
if not self.editable_instance(batch):
|
||||
return self.redirect(self.get_action_url('view', batch))
|
||||
|
||||
if self.edit_with_rows:
|
||||
grid = self.make_row_grid(batch=batch)
|
||||
|
||||
# If user just refreshed the page with a reset instruction, issue a
|
||||
# redirect in order to clear out the query string.
|
||||
if self.request.GET.get('reset-to-default-filters') == 'true':
|
||||
return self.redirect(self.request.current_route_url(_query=None))
|
||||
|
||||
if self.request.params.get('partial'):
|
||||
self.request.response.content_type = b'text/html'
|
||||
self.request.response.text = grid.render_grid()
|
||||
return self.request.response
|
||||
|
||||
form = self.make_form(batch)
|
||||
if self.request.method == 'POST':
|
||||
if self.validate_form(form):
|
||||
self.save_edit_form(form)
|
||||
self.request.session.flash("{} has been updated: {}".format(
|
||||
self.get_model_title(), self.get_instance_title(batch)))
|
||||
return self.redirect_after_edit(batch)
|
||||
|
||||
context = {
|
||||
'instance': batch,
|
||||
'instance_title': self.get_instance_title(batch),
|
||||
'instance_deletable': self.deletable_instance(batch),
|
||||
'form': form,
|
||||
'batch': batch,
|
||||
'execute_title': self.get_execute_title(batch),
|
||||
'execute_enabled': self.instance_executable(batch),
|
||||
}
|
||||
|
||||
if self.edit_with_rows:
|
||||
context['rows_grid'] = grid
|
||||
if context['execute_enabled'] and self.has_execution_options(batch):
|
||||
context['rendered_execution_options'] = self.render_execution_options(batch)
|
||||
|
||||
return self.render_to_response('edit', context)
|
||||
def template_kwargs_edit(self, **kwargs):
|
||||
batch = kwargs['instance']
|
||||
kwargs['batch'] = batch
|
||||
kwargs['execute_title'] = self.get_execute_title(batch)
|
||||
kwargs['execute_enabled'] = self.instance_executable(batch)
|
||||
if kwargs['execute_enabled'] and self.has_execution_options(batch):
|
||||
kwargs['rendered_execution_options'] = self.render_execution_options(batch)
|
||||
return kwargs
|
||||
|
||||
def mobile_mark_complete(self):
|
||||
batch = self.get_instance()
|
||||
|
@ -429,8 +389,6 @@ class BatchMasterView(MasterView):
|
|||
"""
|
||||
if self.request.params.get('refresh') == 'true':
|
||||
return self.redirect(self.get_action_url('refresh', batch))
|
||||
if self.edit_with_rows:
|
||||
return self.redirect(self.get_action_url('edit', batch))
|
||||
return self.redirect(self.get_action_url('view', batch))
|
||||
|
||||
def delete_instance(self, batch):
|
||||
|
|
|
@ -76,6 +76,7 @@ class BatchMasterView3(MasterView3, BatchMasterView2):
|
|||
f.set_label('rowcount', "Row Count")
|
||||
|
||||
# status_code
|
||||
f.set_readonly('status_code')
|
||||
f.set_renderer('status_code', self.make_status_renderer(self.model_class.STATUS))
|
||||
f.set_label('status_code', "Status")
|
||||
|
||||
|
@ -141,7 +142,7 @@ class BatchMasterView3(MasterView3, BatchMasterView2):
|
|||
return batch
|
||||
|
||||
def make_status_renderer(self, enum):
|
||||
def render_status(self, batch, field):
|
||||
def render_status(batch, field):
|
||||
value = batch.status_code
|
||||
if value is None:
|
||||
return ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue