Fix some bugs with importer batch views

This commit is contained in:
Lance Edgar 2018-02-10 17:14:32 -06:00
parent ec438ead51
commit 4191a56bfb
2 changed files with 20 additions and 9 deletions

View file

@ -30,6 +30,8 @@ import sqlalchemy as sa
from rattail.db import model from rattail.db import model
import colander
from tailbone.views.batch import BatchMasterView from tailbone.views.batch import BatchMasterView
@ -208,13 +210,21 @@ class ImporterBatchView(BatchMasterView):
return kwargs return kwargs
def make_row_form(self, instance=None, **kwargs): def make_row_form(self, instance=None, **kwargs):
if kwargs.get('fields') is None:
fields = ['sequence', 'object_key', 'object_str', 'status_code'] fields = ['sequence', 'object_key', 'object_str', 'status_code']
for col in self.current_row_table.c: for col in self.current_row_table.c:
if col.name.startswith('key_'): if col.name.startswith('key_'):
fields.append(col.name) fields.append(col.name)
if kwargs.get('fields') is None:
kwargs['fields'] = fields kwargs['fields'] = fields
return super(ImporterBatchView, self).make_row_form(instance=instance, **kwargs)
row = dict([(field, getattr(instance, field))
for field in fields])
row['status_text'] = instance.status_text
kwargs.setdefault('schema', colander.Schema())
kwargs.setdefault('cancel_url', None)
return super(ImporterBatchView, self).make_row_form(instance=row, **kwargs)
def configure_row_form(self, f): def configure_row_form(self, f):
""" """
@ -228,9 +238,9 @@ class ImporterBatchView(BatchMasterView):
f.set_label('status_code', "Status") f.set_label('status_code', "Status")
def render_row_status_code(self, row, field): def render_row_status_code(self, row, field):
status = self.enum.IMPORTER_BATCH_ROW_STATUS[row.status_code] status = self.enum.IMPORTER_BATCH_ROW_STATUS[row['status_code']]
if row.status_code == self.enum.IMPORTER_BATCH_ROW_STATUS_UPDATE and row.status_text: if row['status_code'] == self.enum.IMPORTER_BATCH_ROW_STATUS_UPDATE and row['status_text']:
return "{} ({})".format(status, row.status_text) return "{} ({})".format(status, row['status_text'])
return status return status
def delete_row(self): def delete_row(self):

View file

@ -2547,7 +2547,8 @@ class MasterView(View):
kwargs.setdefault('cancel_url', self.request.get_referrer()) kwargs.setdefault('cancel_url', self.request.get_referrer())
else: else:
instance = kwargs['model_instance'] instance = kwargs['model_instance']
kwargs.setdefault('cancel_url', self.get_row_action_url('view', instance)) if 'cancel_url' not in kwargs:
kwargs['cancel_url'] = self.get_row_action_url('view', instance)
defaults.update(kwargs) defaults.update(kwargs)
return defaults return defaults