From d7730434299581d3e9c6ebc37382f530c91f0264 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 26 Nov 2018 18:58:55 -0600 Subject: [PATCH] Allow override of products query when making batch from it also, invoke handler properly when populating the batch (i.e. to include setup/teardown) --- tailbone/views/products.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index c5f85b9a..10561582 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -1008,7 +1008,7 @@ class ProductsView(MasterView): params[name] = None handler = supported[batch_key] - products = self.get_effective_data() + products = self.get_products_for_batch(batch_key) progress = SessionProgress(self.request, 'products.batch') thread = Thread(target=self.make_batch_thread, args=(handler, self.request.user.uuid, products, params, progress)) @@ -1024,6 +1024,14 @@ class ProductsView(MasterView): 'params_forms': params_forms, }) + def get_products_for_batch(self, batch_key): + """ + Returns the products query to be used when making a batch (of type + ``batch_key``) with the user's current filters in effect. You can + override this to add eager joins for certain batch types, etc. + """ + return self.get_effective_data() + def make_batch_params_schema_pricing(self): """ Return params schema for making a pricing batch. @@ -1049,7 +1057,7 @@ class ProductsView(MasterView): params['created_by'] = user batch = handler.make_batch(session, **params) batch.products = products.with_session(session).all() - handler.populate(batch, progress=progress) + handler.do_populate(batch, user, progress=progress) session.commit() session.refresh(batch)