From 2648f25c143fdce2d655e375784b7c8b1ca00dd5 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 5 Dec 2021 17:15:34 -0600 Subject: [PATCH] Add some methods/attrs to import handlers, for exposing in web app not complete but a good start --- rattail/app.py | 9 +++++++++ rattail/commands/importing.py | 8 ++++---- rattail/importing/handlers.py | 28 ++++++++++++++++++++++++++++ rattail/importing/rattail.py | 4 ++++ rattail/importing/versions.py | 4 +++- setup.py | 3 +++ 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/rattail/app.py b/rattail/app.py index 7588e334..c5250af5 100644 --- a/rattail/app.py +++ b/rattail/app.py @@ -62,6 +62,9 @@ class AppHandler(object): def __init__(self, config): self.config = config + def get_title(self, default=None): + return self.config.app_title(default=default) + def get_autocompleter(self, key, **kwargs): """ Returns a new :class:`~rattail.autocomplete.base.Autocompleter` @@ -154,6 +157,12 @@ class AppHandler(object): # TODO: is it helpful to expose this? or more confusing? get_mail_handler = get_email_handler + def all_import_handlers(self, **kwargs): + from rattail.util import load_entry_points + + handlers = load_entry_points('rattail.importing') + return list(handlers.values()) + def get_membership_handler(self, **kwargs): """ Returns a reference to the configured Membership Handler. diff --git a/rattail/commands/importing.py b/rattail/commands/importing.py index b45d1a23..0d184356 100644 --- a/rattail/commands/importing.py +++ b/rattail/commands/importing.py @@ -214,10 +214,10 @@ class ImportSubcommand(Subcommand): "Note that this flag is ignored if --make-batches is specified.") def run(self, args): - log.info("begin `%s %s` for data models: %s", - self.parent_name, - self.name, - ', '.join(args.models) if args.models else "(ALL)") + log.debug("begin `%s %s` for data models: %s", + self.parent_name, + self.name, + ', '.join(args.models) if args.models else "(ALL)") handler = self.get_handler(args=args) models = args.models or handler.get_default_keys() diff --git a/rattail/importing/handlers.py b/rattail/importing/handlers.py index 63512a4a..2f4dcfc8 100644 --- a/rattail/importing/handlers.py +++ b/rattail/importing/handlers.py @@ -99,6 +99,34 @@ class ImportHandler(object): for key, value in kwargs.items(): setattr(self, key, value) + @classmethod + def get_key(cls): + return 'to_{}.from_{}'.format(cls.local_key, cls.host_key) + + @classmethod + def get_spec(cls): + return '{}:{}'.format(cls.__module__, cls.__name__) + + @classmethod + def get_generic_host_title(cls): + if hasattr(cls, 'generic_host_title'): + return cls.generic_host_title + return "TODO: define `{}.generic_host_title`".format(cls.__name__) + + @classmethod + def get_generic_local_title(cls): + if hasattr(cls, 'generic_local_title'): + return cls.generic_local_title + return "TODO: define `{}.generic_local_title`".format(cls.__name__) + + @classmethod + def get_generic_title(cls): + if hasattr(cls, 'generic_title'): + return cls.generic_title + host_title = cls.get_generic_host_title() + local_title = cls.get_generic_local_title() + return "{} -> {}".format(host_title, local_title) + def get_importers(self): """ Returns a dict of all available importers, where the keys are model diff --git a/rattail/importing/rattail.py b/rattail/importing/rattail.py index c52af2da..e48331a0 100644 --- a/rattail/importing/rattail.py +++ b/rattail/importing/rattail.py @@ -44,6 +44,8 @@ class FromRattailHandler(FromSQLAlchemyHandler): """ Base class for import handlers which target a Rattail database on the local side. """ + host_key = 'rattail' + generic_host_title = "Rattail" @property def host_title(self): @@ -57,6 +59,8 @@ class ToRattailHandler(ToSQLAlchemyHandler): """ Base class for import handlers which target a Rattail database on the local side. """ + generic_local_title = "Rattail" + local_key = 'rattail' @property def local_title(self): diff --git a/rattail/importing/versions.py b/rattail/importing/versions.py index dd00c357..ad429096 100644 --- a/rattail/importing/versions.py +++ b/rattail/importing/versions.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2021 Lance Edgar # # This file is part of Rattail. # @@ -39,6 +39,8 @@ class FromRattailToRattailVersions(FromRattailHandler, ToRattailHandler): """ Handler for Rattail -> Rattail "versions" data import """ + local_key = 'rattail_versions' + generic_local_title = "Rattail (Versions)" @property def local_title(self): diff --git a/setup.py b/setup.py index b3be2bee..4d51b578 100644 --- a/setup.py +++ b/setup.py @@ -239,6 +239,9 @@ rattail.trainwreck = rattail.trainwreck.config:TrainwreckConfig new-report = rattail.features.newreport:NewReportFeature new-table = rattail.features.newtable:NewTableFeature +[rattail.importing] +to_rattail.from_versions = rattail.importing.versions:FromRattailToRattailVersions + [rattail.reports] customer_mailing = rattail.reporting.customer_mailing:CustomerMailing