Refactor importer batch views per master4

This commit is contained in:
Lance Edgar 2018-02-04 13:01:49 -06:00
parent 4ab41ba82e
commit dfc5e0f50e

View file

@ -30,8 +30,7 @@ import sqlalchemy as sa
from rattail.db import model
from tailbone import forms2 as forms
from tailbone.views.batch import BatchMasterView3 as BatchMasterView
from tailbone.views.batch import BatchMasterView4 as BatchMasterView
class ImporterBatchView(BatchMasterView):
@ -50,6 +49,12 @@ class ImporterBatchView(BatchMasterView):
rows_downloadable_csv = False
rows_bulk_deletable = True
labels = {
'host_title': "Source",
'local_title': "Target",
'importer_key': "Model",
}
grid_columns = [
'id',
'description',
@ -79,12 +84,6 @@ class ImporterBatchView(BatchMasterView):
'executed_by',
]
labels = {
'host_title': "Source",
'local_title': "Target",
'importer_key': "Model",
}
row_grid_columns = [
'sequence',
'object_key',
@ -95,19 +94,11 @@ class ImporterBatchView(BatchMasterView):
def configure_form(self, f):
super(ImporterBatchView, self).configure_form(f)
# import_handler_spec
# readonly fields
f.set_readonly('import_handler_spec')
# host_title
f.set_readonly('host_title')
# local_title
f.set_readonly('local_title')
# importer_key
f.set_readonly('importer_key')
# row_table
f.set_readonly('row_table')
def delete_instance(self, batch):
@ -216,39 +207,14 @@ class ImporterBatchView(BatchMasterView):
kwargs['diff_new_values'] = new_values
return kwargs
def make_row_form(self, instance=None, factory=None, fields=None, schema=None, **kwargs):
"""
Creates a new form for the given model class/instance
"""
if factory is None:
factory = forms.Form
if fields is None:
def make_row_form(self, instance=None, **kwargs):
if kwargs.get('fields') is None:
fields = ['sequence', 'object_key', 'object_str', 'status_code']
for col in self.current_row_table.c:
if col.name.startswith('key_'):
fields.append(col.name)
if not self.creating:
kwargs['model_instance'] = instance
kwargs = self.make_row_form_kwargs(**kwargs)
form = factory(fields, schema, **kwargs)
self.configure_row_form(form)
return form
def make_row_form_kwargs(self, **kwargs):
"""
Return a dictionary of kwargs to be passed to the factory when creating
new row form instances.
"""
defaults = {
'request': self.request,
'readonly': self.viewing,
'model_class': getattr(self, 'model_class', None),
'action_url': self.request.current_route_url(_query=None),
}
instance = kwargs['model_instance']
defaults.update(kwargs)
return defaults
kwargs['fields'] = fields
return super(ImporterBatchView, self).make_row_form(instance=instance, **kwargs)
def configure_row_form(self, f):
"""