Add some methods/attrs to import handlers, for exposing in web app

not complete but a good start
This commit is contained in:
Lance Edgar 2021-12-05 17:15:34 -06:00
parent fb75927662
commit 2648f25c14
6 changed files with 51 additions and 5 deletions

View file

@ -62,6 +62,9 @@ class AppHandler(object):
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
def get_title(self, default=None):
return self.config.app_title(default=default)
def get_autocompleter(self, key, **kwargs): def get_autocompleter(self, key, **kwargs):
""" """
Returns a new :class:`~rattail.autocomplete.base.Autocompleter` 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? # TODO: is it helpful to expose this? or more confusing?
get_mail_handler = get_email_handler 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): def get_membership_handler(self, **kwargs):
""" """
Returns a reference to the configured Membership Handler. Returns a reference to the configured Membership Handler.

View file

@ -214,7 +214,7 @@ class ImportSubcommand(Subcommand):
"Note that this flag is ignored if --make-batches is specified.") "Note that this flag is ignored if --make-batches is specified.")
def run(self, args): def run(self, args):
log.info("begin `%s %s` for data models: %s", log.debug("begin `%s %s` for data models: %s",
self.parent_name, self.parent_name,
self.name, self.name,
', '.join(args.models) if args.models else "(ALL)") ', '.join(args.models) if args.models else "(ALL)")

View file

@ -99,6 +99,34 @@ class ImportHandler(object):
for key, value in kwargs.items(): for key, value in kwargs.items():
setattr(self, key, value) 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): def get_importers(self):
""" """
Returns a dict of all available importers, where the keys are model Returns a dict of all available importers, where the keys are model

View file

@ -44,6 +44,8 @@ class FromRattailHandler(FromSQLAlchemyHandler):
""" """
Base class for import handlers which target a Rattail database on the local side. Base class for import handlers which target a Rattail database on the local side.
""" """
host_key = 'rattail'
generic_host_title = "Rattail"
@property @property
def host_title(self): 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. Base class for import handlers which target a Rattail database on the local side.
""" """
generic_local_title = "Rattail"
local_key = 'rattail'
@property @property
def local_title(self): def local_title(self):

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar # Copyright © 2010-2021 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -39,6 +39,8 @@ class FromRattailToRattailVersions(FromRattailHandler, ToRattailHandler):
""" """
Handler for Rattail -> Rattail "versions" data import Handler for Rattail -> Rattail "versions" data import
""" """
local_key = 'rattail_versions'
generic_local_title = "Rattail (Versions)"
@property @property
def local_title(self): def local_title(self):

View file

@ -239,6 +239,9 @@ rattail.trainwreck = rattail.trainwreck.config:TrainwreckConfig
new-report = rattail.features.newreport:NewReportFeature new-report = rattail.features.newreport:NewReportFeature
new-table = rattail.features.newtable:NewTableFeature new-table = rattail.features.newtable:NewTableFeature
[rattail.importing]
to_rattail.from_versions = rattail.importing.versions:FromRattailToRattailVersions
[rattail.reports] [rattail.reports]
customer_mailing = rattail.reporting.customer_mailing:CustomerMailing customer_mailing = rattail.reporting.customer_mailing:CustomerMailing