Honor the configured email collection module(s), even w/ entry points
entry points make for an obvious default collection, but if config declares a particular list of modules, that should win
This commit is contained in:
parent
890ec80b73
commit
54c3d0eae3
|
@ -89,13 +89,43 @@ class EmailHandler(object):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.enum = self.config.get_enum()
|
self.enum = self.config.get_enum()
|
||||||
|
|
||||||
|
def use_entry_points(self):
|
||||||
|
"""
|
||||||
|
Returns a boolean indicating if the app should get its list of
|
||||||
|
available emails from the setuptools entry points, instead of
|
||||||
|
the (legacy) ``[rattail.mail] emails`` config setting.
|
||||||
|
"""
|
||||||
|
return self.config.getbool('rattail.mail', 'emails.use_entry_points',
|
||||||
|
default=False)
|
||||||
|
|
||||||
def get_all_emails(self, **kwargs):
|
def get_all_emails(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Retrieve the complete set of all Email profiles exposed by the
|
Retrieve the complete set of all Email profiles exposed by the
|
||||||
app and installed packages.
|
app and installed packages.
|
||||||
"""
|
"""
|
||||||
|
# TODO: maybe deprecate this at some point?
|
||||||
|
if not self.use_entry_points():
|
||||||
|
# nb. this is the legacy behavior
|
||||||
|
return dict([(email.key or email.__name__, email)
|
||||||
|
for email in self.iter_emails(warn=False)])
|
||||||
|
|
||||||
|
# this is the future..
|
||||||
emails = {}
|
emails = {}
|
||||||
modules = load_entry_points('rattail.emails').values()
|
|
||||||
|
# first get *all* email modules, per entry points
|
||||||
|
all_modules = load_entry_points('rattail.emails').values()
|
||||||
|
|
||||||
|
# but maybe the app config says only to use certain modules
|
||||||
|
app_modules = self.config.getlist('rattail.mail', 'emails')
|
||||||
|
|
||||||
|
# figure out which modules we should actually use
|
||||||
|
if app_modules:
|
||||||
|
modules = [import_module_path(m)
|
||||||
|
for m in app_modules]
|
||||||
|
else:
|
||||||
|
modules = all_modules
|
||||||
|
|
||||||
|
# and collect all email profiles from those modules
|
||||||
for module in modules:
|
for module in modules:
|
||||||
mod_emails = self.get_emails_from_module(module)
|
mod_emails = self.get_emails_from_module(module)
|
||||||
emails.update(dict([(email.key or email.__name__, email)
|
emails.update(dict([(email.key or email.__name__, email)
|
||||||
|
@ -114,15 +144,6 @@ class EmailHandler(object):
|
||||||
emails.append(obj)
|
emails.append(obj)
|
||||||
return emails
|
return emails
|
||||||
|
|
||||||
def use_entry_points(self):
|
|
||||||
"""
|
|
||||||
Returns a boolean indicating if the app should get its list of
|
|
||||||
available emails from the setuptools entry points, instead of
|
|
||||||
the (legacy) ``[rattail.mail] emails`` config setting.
|
|
||||||
"""
|
|
||||||
return self.config.getbool('rattail.mail', 'emails.use_entry_points',
|
|
||||||
default=False)
|
|
||||||
|
|
||||||
def get_available_emails(self, **kwargs):
|
def get_available_emails(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Retrieve the set of "available" Email profiles, i.e. those
|
Retrieve the set of "available" Email profiles, i.e. those
|
||||||
|
|
Loading…
Reference in a new issue