Add refresh_many() method for batch handlers

This commit is contained in:
Lance Edgar 2020-03-02 18:08:17 -06:00
parent 20a14ca39f
commit 2cbbbfdb37
2 changed files with 23 additions and 0 deletions

View file

@ -99,6 +99,8 @@
.. automethod:: refresh
.. automethod:: refresh_many
.. automethod:: refresh_row
.. automethod:: locate_product_for_entry

View file

@ -411,6 +411,27 @@ class BatchHandler(object):
self.teardown_refresh(batch, progress=progress)
return True
def refresh_many(self, batches, user=None, progress=None):
"""
Refresh a set of batches, with given progress. Default behavior is to
simply refresh each batch in succession. Any batches which are already
executed are skipped.
Handlers may have to override this method if "grouping" or other
special behavior is needed.
"""
needs_refresh = [batch for batch in batches
if not batch.executed]
if not needs_refresh:
return
# TODO: should perhaps try to make the progress indicator reflect the
# "total" number of rows across all batches being refreshed? seems
# like that might be more accurate, for the user. but also harder.
for batch in needs_refresh:
self.do_refresh(batch, user, progress=progress)
def refresh_row(self, row):
"""
This method will be passed a row object which has already been properly