Add setup/teardown handler hooks when cloning a batch

also fix a small rowcount bug
This commit is contained in:
Lance Edgar 2018-07-03 18:53:24 -05:00
parent 3f924b14f0
commit f6775f5d8b
2 changed files with 19 additions and 2 deletions

View file

@ -451,10 +451,25 @@ class BatchHandler(object):
if hasattr(batch, 'data_rows'):
del batch.data_rows[:]
def setup_clone(self, oldbatch, progress=None):
"""
Perform any setup (caching etc.) necessary for cloning batch. Note
that the ``oldbatch`` arg is the "old" batch, i.e. the one from which a
clone is to be created.
"""
def teardown_clone(self, newbatch, progress=None):
"""
Perform any teardown (cleanup etc.) necessary after cloning a batch.
Note that the ``newbatch`` arg is the "new" batch, i.e. the one which
was just created by cloning the old batch.
"""
def clone(self, oldbatch, created_by, progress=None):
"""
Clone the given batch as a new batch, and return the new batch.
"""
self.setup_clone(oldbatch, progress=progress)
batch_class = self.batch_model_class
batch_mapper = orm.class_mapper(batch_class)
@ -462,7 +477,7 @@ class BatchHandler(object):
newbatch.created_by = created_by
newbatch.rowcount = 0
for name in batch_mapper.columns.keys():
if name not in ('uuid', 'id', 'created', 'created_by_uuid', 'executed', 'executed_by_uuid'):
if name not in ('uuid', 'id', 'created', 'created_by_uuid', 'rowcount', 'executed', 'executed_by_uuid'):
setattr(newbatch, name, getattr(oldbatch, name))
session = orm.object_session(oldbatch)
@ -480,6 +495,7 @@ class BatchHandler(object):
message="Cloning data rows for new batch")
self.refresh_batch_status(newbatch)
self.teardown_clone(newbatch, progress=progress)
return newbatch
def clone_row(self, oldrow):
@ -487,7 +503,7 @@ class BatchHandler(object):
row_mapper = orm.class_mapper(row_class)
newrow = row_class()
for name in row_mapper.columns.keys():
if name not in ('uuid', 'batch_uuid'):
if name not in ('uuid', 'batch_uuid', 'sequence'):
setattr(newrow, name, getattr(oldrow, name))
return newrow

View file

@ -59,6 +59,7 @@ class LabelBatchHandler(BatchHandler):
setup_populate = setup
setup_refresh = setup
setup_clone = setup
def make_batch(self, session, progress=None, **kwargs):
"""