Add some methods/attrs to import handlers, for exposing in web app
not complete but a good start
This commit is contained in:
parent
fb75927662
commit
2648f25c14
|
@ -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.
|
||||
|
|
|
@ -214,7 +214,7 @@ 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",
|
||||
log.debug("begin `%s %s` for data models: %s",
|
||||
self.parent_name,
|
||||
self.name,
|
||||
', '.join(args.models) if args.models else "(ALL)")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
3
setup.py
3
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue