Add core View.make_progress() method

so callers no longer need to import `SessionProgress` and create directly
This commit is contained in:
Lance Edgar 2019-09-25 00:10:17 -05:00
parent f0a5265a65
commit ff9700e23a
10 changed files with 31 additions and 14 deletions

6
docs/api/progress.rst Normal file
View file

@ -0,0 +1,6 @@
``tailbone.progress``
=====================
.. automodule:: tailbone.progress
:members:

6
docs/api/views/core.rst Normal file
View file

@ -0,0 +1,6 @@
``tailbone.views.core``
=======================
.. automodule:: tailbone.views.core
:members:

View file

@ -44,8 +44,10 @@ Package API:
api/forms
api/grids
api/progress
api/subscribers
api/views/batch
api/views/core
api/views/master
api/views/vendors.catalogs

View file

@ -56,7 +56,6 @@ from webhelpers2.html import HTML, tags
from tailbone import forms, grids
from tailbone.db import Session
from tailbone.views import MasterView
from tailbone.progress import SessionProgress
from tailbone.util import csrf_token
@ -824,7 +823,7 @@ class BatchMasterView(MasterView):
username = user.username if user else None
key = '{}.{}'.format(self.model_class.__tablename__, batch_action)
progress = SessionProgress(self.request, key)
progress = self.make_progress(key)
# must ensure versioning is *disabled* during action, if handler says so
allow_versioning = self.handler.allow_versioning(batch_action)
@ -1329,7 +1328,7 @@ class BatchMasterView(MasterView):
key = '{}.execute_results'.format(self.model_class.__tablename__)
batches = self.get_effective_data()
progress = SessionProgress(self.request, key)
progress = self.make_progress(key)
kwargs['progress'] = progress
thread = Thread(target=self.execute_results_thread, args=(batches, self.request.user.uuid), kwargs=kwargs)
thread.start()

View file

@ -39,6 +39,7 @@ from pyramid.response import FileResponse
from tailbone.db import Session
from tailbone.auth import logout_user
from tailbone.progress import SessionProgress
from tailbone.util import should_use_buefy
@ -100,6 +101,13 @@ class View(object):
def progress_loop(self, func, items, factory, *args, **kwargs):
return progress_loop(func, items, factory, *args, **kwargs)
def make_progress(self, key):
"""
Create and return a :class:`tailbone.progress.SessionProgress`
instance, with the given key.
"""
return SessionProgress(self.request, key)
# TODO: this signature seems wonky
def render_progress(self, progress, kwargs, template=None):
"""

View file

@ -58,7 +58,6 @@ from webhelpers2.html import HTML, tags
from tailbone import forms, grids, diffs
from tailbone.views import View
from tailbone.progress import SessionProgress
log = logging.getLogger(__name__)
@ -948,7 +947,7 @@ class MasterView(View):
# showing progress requires a separate thread; start that first
key = '{}.populate'.format(route_prefix)
progress = SessionProgress(self.request, key)
progress = self.make_progress(key)
thread = Thread(target=self.populate_thread, args=(obj.uuid, progress)) # TODO: uuid?
thread.start()
@ -1797,7 +1796,7 @@ class MasterView(View):
"""
objects = self.get_effective_data()
key = '{}.bulk_delete'.format(self.model_class.__tablename__)
progress = SessionProgress(self.request, key)
progress = self.make_progress(key)
thread = Thread(target=self.bulk_delete_thread, args=(objects, progress))
thread.start()
return self.render_progress(progress, {
@ -1957,7 +1956,7 @@ class MasterView(View):
def make_execute_progress(self, obj):
key = '{}.execute'.format(self.get_grid_key())
return SessionProgress(self.request, key)
return self.make_progress(key)
def execute_thread(self, uuid, user_uuid, progress=None, **kwargs):
"""

View file

@ -49,7 +49,6 @@ from webhelpers2.html import tags, HTML
from tailbone import forms, grids
from tailbone.db import Session
from tailbone.views import MasterView, AutocompleteView
from tailbone.progress import SessionProgress
from tailbone.util import raw_datetime
@ -1090,7 +1089,7 @@ class ProductsView(MasterView):
handler = supported[batch_key]
products = self.get_products_for_batch(batch_key)
progress = SessionProgress(self.request, 'products.batch')
progress = self.make_progress('products.batch')
thread = Thread(target=self.make_batch_thread,
args=(handler, self.request.user.uuid, products, params, progress))
thread.start()

View file

@ -49,7 +49,6 @@ from webhelpers2.html import tags, HTML
from tailbone import forms, grids
from tailbone.views.purchasing import PurchasingBatchView
from tailbone.progress import SessionProgress
log = logging.getLogger(__name__)
@ -1810,7 +1809,7 @@ class ReceivingBatchView(PurchasingBatchView):
"""
batch = self.get_instance()
key = '{}.receive_all'.format(self.get_grid_key())
progress = SessionProgress(self.request, key)
progress = self.make_progress(key)
kwargs = {'progress': progress}
thread = Thread(target=self.auto_receive_thread, args=(batch.uuid, self.request.user.uuid), kwargs=kwargs)
thread.start()

View file

@ -49,7 +49,6 @@ from tailbone import forms, grids
from tailbone.db import Session
from tailbone.views import View
from tailbone.views.exports import ExportMasterView
from tailbone.progress import SessionProgress
plu_upc_pattern = re.compile(r'^000000000(\d{5})$')
@ -372,7 +371,7 @@ class GenerateReport(View):
# if form validates, start generating new report output; show progress page
if form.validate(newstyle=True):
key = 'report_output.generate'
progress = SessionProgress(self.request, key)
progress = self.make_progress(key)
kwargs = {'progress': progress}
thread = Thread(target=self.generate_thread,
args=(report, form.validated, self.request.user.uuid),

View file

@ -52,7 +52,7 @@ from deform import widget as dfwidget
from webhelpers2.html import tags, HTML
from tailbone.views import MasterView
from tailbone.progress import SessionProgress, get_progress_session
from tailbone.progress import get_progress_session #, SessionProgress
log = logging.getLogger(__name__)