Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits:
8e7a6613 by Mark Sapiro at 2018-09-11T15:19:48Z
Enable setting additional templates in the var/templates hierarchy.
- - - - -
bb9222a5 by Mark Sapiro at 2018-09-11T15:34:19Z
Merge branch 'template' into 'master'
Enable setting additional templates in the var/templates hierarchy.
Closes #486
See merge request mailman/mailman!398
- - - - -
6 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/interfaces/template.py
- src/mailman/model/template.py
- + src/mailman/templates/en/list:member:digest:header.txt
- + src/mailman/templates/en/list:member:regular:header.txt
- + src/mailman/templates/en/list:user:notice:goodbye.txt
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -110,6 +110,8 @@ Bugs
has been fixed to generate proper mappings in this case. (Closes #485)
* Fix a bug where duplicate address records can be created when a user adds an
existing address with a different case. (Closes #476)
+* Several additional templates can now be set in the ``var/templates``
+ hierarchy. (Closes #486)
Command line
------------
=====================================
src/mailman/interfaces/template.py
=====================================
@@ -159,7 +159,9 @@ class ITemplateManager(Interface):
# Mapping of template names to their in-source file names. A None value means
-# that there is no file in the tree for that template.
+# that there is no file in the tree for that template, but we have possibly
+# empty files for all templates so they can be defined in the var/templates
+# hierarchy.
ALL_TEMPLATES = {
key: '{}.txt'.format(key)
@@ -171,9 +173,14 @@ ALL_TEMPLATES = {
'list:admin:notice:subscribe',
'list:admin:notice:unrecognized',
'list:admin:notice:unsubscribe',
+ 'list:member:digest:footer',
+ 'list:member:digest:header',
'list:member:digest:masthead',
+ 'list:member:regular:footer',
+ 'list:member:regular:header',
'list:user:action:subscribe',
'list:user:action:unsubscribe',
+ 'list:user:notice:goodbye',
'list:user:notice:hold',
'list:user:notice:no-more-today',
'list:user:notice:post',
@@ -184,18 +191,11 @@ ALL_TEMPLATES = {
}
}
-# These have other names.
-ALL_TEMPLATES.update({
+# These have alternate names.
+ALT_TEMPLATE_NAMES = {
'list:member:digest:footer': 'list:member:generic:footer.txt',
'list:member:regular:footer': 'list:member:generic:footer.txt',
- })
-
-# These are some extra supported templates which don't have a mapping to a
-# file in the source tree.
-ALL_TEMPLATES.update({
- 'list:member:digest:header': None,
- 'list:member:regular:header': None,
- 'list:user:notice:goodbye': None,
- })
+ }
public(ALL_TEMPLATES=ALL_TEMPLATES)
+public(ALT_TEMPLATE_NAMES=ALT_TEMPLATE_NAMES)
=====================================
src/mailman/model/template.py
=====================================
@@ -27,9 +27,9 @@ from mailman.interfaces.cache import ICacheManager
from mailman.interfaces.domain import IDomain
from mailman.interfaces.mailinglist import IMailingList
from mailman.interfaces.template import (
- ALL_TEMPLATES, ITemplateLoader, ITemplateManager)
+ ALL_TEMPLATES, ALT_TEMPLATE_NAMES, ITemplateLoader, ITemplateManager)
from mailman.utilities import protocols
-from mailman.utilities.i18n import find
+from mailman.utilities.i18n import TemplateNotFoundError, find
from mailman.utilities.string import expand
from public import public
from requests import HTTPError
@@ -197,10 +197,19 @@ class TemplateLoader:
missing = object()
default_uri = ALL_TEMPLATES.get(name, missing)
if default_uri is None:
- return ''
+ # Currently default_uri is never None, but leave this in case
+ # of a future change.
+ return '' # pragma: nocover
elif default_uri is missing:
raise URLError('No such file')
- path, fp = find(default_uri, mlist, code)
+ try:
+ path, fp = find(default_uri, mlist, code)
+ except TemplateNotFoundError:
+ default_uri = ALT_TEMPLATE_NAMES.get(name, missing)
+ if default_uri is missing:
+ # Here again, default_uri is never missing, but leave it.
+ raise # pragma: nocover
+ path, fp = find(default_uri, mlist, code)
try:
return fp.read()
finally:
=====================================
src/mailman/templates/en/list:member:digest:header.txt
=====================================
=====================================
src/mailman/templates/en/list:member:regular:header.txt
=====================================
=====================================
src/mailman/templates/en/list:user:notice:goodbye.txt
=====================================
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/0fbb37f0ca1d93338751c6ed3ec3f5f7bbb46daa...bb9222a568718a629d3eb2c4e0db4ee143266f56
--
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/0fbb37f0ca1d93338751c6ed3ec3f5f7bbb46daa...bb9222a568718a629d3eb2c4e0db4ee143266f56
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org