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 rattail.db import model
from tailbone import forms2 as forms from tailbone.views.batch import BatchMasterView4 as BatchMasterView
from tailbone.views.batch import BatchMasterView3 as BatchMasterView
class ImporterBatchView(BatchMasterView): class ImporterBatchView(BatchMasterView):
@ -50,6 +49,12 @@ class ImporterBatchView(BatchMasterView):
rows_downloadable_csv = False rows_downloadable_csv = False
rows_bulk_deletable = True rows_bulk_deletable = True
labels = {
'host_title': "Source",
'local_title': "Target",
'importer_key': "Model",
}
grid_columns = [ grid_columns = [
'id', 'id',
'description', 'description',
@ -79,12 +84,6 @@ class ImporterBatchView(BatchMasterView):
'executed_by', 'executed_by',
] ]
labels = {
'host_title': "Source",
'local_title': "Target",
'importer_key': "Model",
}
row_grid_columns = [ row_grid_columns = [
'sequence', 'sequence',
'object_key', 'object_key',
@ -95,19 +94,11 @@ class ImporterBatchView(BatchMasterView):
def configure_form(self, f): def configure_form(self, f):
super(ImporterBatchView, self).configure_form(f) super(ImporterBatchView, self).configure_form(f)
# import_handler_spec # readonly fields
f.set_readonly('import_handler_spec') f.set_readonly('import_handler_spec')
# host_title
f.set_readonly('host_title') f.set_readonly('host_title')
# local_title
f.set_readonly('local_title') f.set_readonly('local_title')
# importer_key
f.set_readonly('importer_key') f.set_readonly('importer_key')
# row_table
f.set_readonly('row_table') f.set_readonly('row_table')
def delete_instance(self, batch): def delete_instance(self, batch):
@ -216,39 +207,14 @@ class ImporterBatchView(BatchMasterView):
kwargs['diff_new_values'] = new_values kwargs['diff_new_values'] = new_values
return kwargs return kwargs
def make_row_form(self, instance=None, factory=None, fields=None, schema=None, **kwargs): def make_row_form(self, instance=None, **kwargs):
""" if kwargs.get('fields') is None:
Creates a new form for the given model class/instance
"""
if factory is None:
factory = forms.Form
if 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)
kwargs['fields'] = fields
if not self.creating: return super(ImporterBatchView, self).make_row_form(instance=instance, **kwargs)
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
def configure_row_form(self, f): def configure_row_form(self, f):
""" """