Make app.get_all_import_handlers() a bit smarter

should fetch all "designated" handlers in addition to those which are
officially registered
This commit is contained in:
Lance Edgar 2021-12-17 20:26:41 -06:00
parent 768cccd9ab
commit d04c2958c0

View file

@ -222,15 +222,31 @@ class AppHandler(object):
:returns: List of all registered Import/Export Handler classes. :returns: List of all registered Import/Export Handler classes.
""" """
handlers = self.load_entry_points('rattail.importing', # first load all "registered" Handler classes
Handlers = self.load_entry_points('rattail.importing',
ignore_errors=ignore_errors) ignore_errors=ignore_errors)
handlers = list(handlers.values())
# organize registered classes by spec
specs = {}
for Handler in six.itervalues(Handlers):
spec = '{}:{}'.format(Handler.__module__, Handler.__name__)
specs[spec] = Handler
# many handlers may not be registered per se, but may be
# designated via config. so try to include those too
for Handler in six.itervalues(Handlers):
spec = self.get_designated_import_handler_spec(Handler.get_key())
if spec and spec not in specs:
specs[spec] = load_object(spec)
# flatten back to simple list
Handlers = list(specs.values())
if sort: if sort:
handlers.sort(key=lambda h: (h.get_generic_host_title(), Handlers.sort(key=lambda h: (h.get_generic_host_title(),
h.get_generic_local_title())) h.get_generic_local_title()))
return handlers return Handlers
def get_designated_import_handlers(self, with_alternates=False, **kwargs): def get_designated_import_handlers(self, with_alternates=False, **kwargs):
""" """