Refactor batch views / templates per rattail framework overhaul
This commit is contained in:
parent
a5184e416a
commit
203f0242fb
12 changed files with 225 additions and 182 deletions
|
@ -38,6 +38,7 @@ from rattail.gpc import GPC
|
|||
from rattail.threads import Thread
|
||||
from rattail.exceptions import LabelPrintingError
|
||||
from rattail.util import load_object
|
||||
from rattail.batch import get_batch_handler
|
||||
|
||||
import formalchemy as fa
|
||||
from pyramid import httpexceptions
|
||||
|
@ -349,15 +350,14 @@ class ProductsView(MasterView):
|
|||
# okay then, new-style it is
|
||||
# TODO: make this more configurable surely..?
|
||||
supported = {
|
||||
'labels': 'rattail.db.batch.labels.handler:LabelBatchHandler',
|
||||
'labels': 'rattail.batch.labels:LabelBatchHandler',
|
||||
}
|
||||
|
||||
if self.request.method == 'POST':
|
||||
batch_key = self.request.POST.get('batch_type')
|
||||
if batch_key and batch_key in supported:
|
||||
handler_spec = self.rattail_config.get('rattail.batch', '{}.handler'.format(batch_key),
|
||||
default=supported[batch_key])
|
||||
handler = load_object(handler_spec)(self.rattail_config)
|
||||
handler = get_batch_handler(self.rattail_config, batch_key,
|
||||
default=supported[batch_key])
|
||||
|
||||
progress = SessionProgress(self.request, 'products.batch')
|
||||
thread = Thread(target=self.make_batch_thread,
|
||||
|
@ -372,7 +372,7 @@ class ProductsView(MasterView):
|
|||
batch_types = []
|
||||
for key, spec in supported.iteritems():
|
||||
handler = load_object(spec)(self.rattail_config)
|
||||
batch_types.append((key, handler.model_title))
|
||||
batch_types.append((key, handler.get_model_title()))
|
||||
|
||||
return {'supported_batches': batch_types}
|
||||
|
||||
|
@ -384,11 +384,9 @@ class ProductsView(MasterView):
|
|||
user = session.query(model.User).get(user_uuid)
|
||||
assert user
|
||||
products = self.get_effective_query(session)
|
||||
batch = handler.make_batch(session, created_by=user, products=products, progress=progress)
|
||||
if not batch:
|
||||
session.rollback()
|
||||
session.close()
|
||||
return
|
||||
batch = handler.make_batch(session, created_by=user)
|
||||
batch.products = products.all()
|
||||
handler.make_initial_rows(batch, progress=progress)
|
||||
|
||||
session.commit()
|
||||
session.refresh(batch)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue