Changeset - fef61b5aa32e
[Not reviewed]
0 2 0
Lance Edgar (lance) - 7 years ago 2017-11-11 09:50:44
lance@edbob.org
Add "re-populate on refresh" flag for batch handlers

to handle the common case where a batch refresh should really be a rebuild,
as opposed to refreshing existing rows in-place
2 files changed with 26 insertions and 18 deletions:
0 comments (0 inline, 0 general)
rattail/batch/handlers.py
Show inline comments
 
@@ -51,8 +51,16 @@ class BatchHandler(object):
 
       flag should be set to ``True`` if *any* batches may need population.
 
       Whether or not a given batch actually needs to be populated, is
 
       ultimately determined by the :meth:`should_populate()` method.
 

	
 
    .. attribute:: repopulate_when_refresh
 

	
 
       Flag to indicate that when a batch is refreshed, the first step of that
 
       should be to re-populate the batch.  The flag is ``False`` by default,
 
       in which case the batch is *not* repopulated, i.e. the refresh will work
 
       with existing batch rows.
 
    """
 
    populate_batches = False
 
    repopulate_when_refresh = False
 

	
 
    def __init__(self, config):
 
        self.config = config
 
@@ -248,19 +256,25 @@ class BatchHandler(object):
 
        """
 
        session = orm.object_session(batch)
 
        self.setup_refresh(batch, progress=progress)
 
        batch.rowcount = 0
 

	
 
        def refresh(row, i):
 
            with session.no_autoflush:
 
                self.refresh_row(row)
 
            if not row.removed:
 
                batch.rowcount += 1
 

	
 
        success = self.progress_loop(refresh, batch.active_rows(), progress,
 
                                     message="Refreshing batch data rows")
 
        if self.repopulate_when_refresh:
 
            del batch.data_rows[:]
 
            batch.rowcount = 0
 
            session.flush()
 
            self.populate(batch, progress=progress)
 
        else:
 
            batch.rowcount = 0
 

	
 
            def refresh(row, i):
 
                with session.no_autoflush:
 
                    self.refresh_row(row)
 
                if not row.removed:
 
                    batch.rowcount += 1
 

	
 
            self.progress_loop(refresh, batch.active_rows(), progress,
 
                               message="Refreshing batch data rows")
 
        self.refresh_batch_status(batch)
 
        self.teardown_refresh(batch, progress=progress)
 
        return success
 
        return True
 

	
 
    def refresh_row(self, row):
 
        """
rattail/data/new-batch/handler.py
Show inline comments
 
@@ -16,13 +16,7 @@ class ${model_name}Handler(BatchHandler):
 
    """
 
    batch_model_class = model.${model_name}
 

	
 
    def refresh_data(self, session, batch, progress=None):
 
        """
 
        Refresh all data for the batch.
 
        """
 
        super(${model_name}Handler, self).refresh_data(session, batch, progress=progress)
 

	
 
    def cognize_row(self, session, row):
 
    def refresh_row(self, row):
 
        """
 
        Inspect a single row from the batch, and set its attributes based on
 
        various lookups and business rules, as needed.
0 comments (0 inline, 0 general)