Use common logic for fetching batch handler

This commit is contained in:
Lance Edgar 2022-03-25 13:49:39 -05:00
parent ae1e9dba0f
commit f0b6b62791

View file

@ -45,7 +45,7 @@ from sqlalchemy import orm
from rattail.db import model, Session as RattailSession
from rattail.db.util import short_session
from rattail.threads import Thread
from rattail.util import load_object, prettify, simple_error
from rattail.util import prettify, simple_error
from rattail.progress import SocketProgress
import colander
@ -142,12 +142,13 @@ class BatchMasterView(MasterView):
``batch_key`` attribute of the main batch model class.
"""
# first try to figure out if config defines a factory class
app = rattail_config.get_app()
model_class = cls.get_model_class()
batch_key = model_class.batch_key
spec = rattail_config.get('rattail.batch', '{}.handler'.format(batch_key),
handler = app.get_batch_handler(batch_key,
default=cls.default_handler_spec)
if spec: # yep, so use that
return load_object(spec)
if handler:
return handler.__class__
# fall back to whatever class was defined statically
return cls.batch_handler_class