Add cache_model() convenience method for problem reports

This commit is contained in:
Lance Edgar 2020-07-20 16:19:49 -05:00
parent 3d85857ea1
commit 06ea22ae58

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2020 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -27,6 +27,7 @@ Problem Reports Framework
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
from rattail.util import progress_loop from rattail.util import progress_loop
from rattail.db import cache
class ProblemReport(object): class ProblemReport(object):
@ -53,6 +54,16 @@ class ProblemReport(object):
factory = factory or self.progress factory = factory or self.progress
return progress_loop(func, items, factory, **kwargs) return progress_loop(func, items, factory, **kwargs)
def cache_model(self, session, model, **kwargs):
"""
Convenience method which invokes
:func:`~rattail.db.cache.cache_model()` with the given model and
keyword arguments. This method will provide the ``progress`` parameter
by default.
"""
kwargs.setdefault('progress', self.progress)
return cache.cache_model(session, model, **kwargs)
def find_problems(self, **kwargs): def find_problems(self, **kwargs):
""" """
Find all problems for which this report is responsible. This should Find all problems for which this report is responsible. This should