diff options
| author | Barry Warsaw | 2016-02-27 14:40:06 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2016-02-27 14:40:06 -0500 |
| commit | cd61fcc88245af25bda231710cbbe1eb75a5e0e4 (patch) | |
| tree | d45dd282508400183c352ac239d984358af12ac8 /src/mailman/utilities | |
| parent | a763e9634ce5dacc4a5079271d14e8fb4b71235c (diff) | |
| download | mailman-cd61fcc88245af25bda231710cbbe1eb75a5e0e4.tar.gz mailman-cd61fcc88245af25bda231710cbbe1eb75a5e0e4.tar.zst mailman-cd61fcc88245af25bda231710cbbe1eb75a5e0e4.zip | |
Allow List-ID in decoration template URIs.
Closes #196
In mailman: URIs (e.g. IMailingList.header_uri and .footer_uri), you
used to be able to only use fqdn-listnames. But since List-IDs are more
stable, let's allow those too. Silently deprecate using the fqdn-listname.
Diffstat (limited to 'src/mailman/utilities')
| -rw-r--r-- | src/mailman/utilities/i18n.py | 32 | ||||
| -rw-r--r-- | src/mailman/utilities/tests/test_templates.py | 7 |
2 files changed, 25 insertions, 14 deletions
diff --git a/src/mailman/utilities/i18n.py b/src/mailman/utilities/i18n.py index bce1026f6..069bd8f52 100644 --- a/src/mailman/utilities/i18n.py +++ b/src/mailman/utilities/i18n.py @@ -27,7 +27,6 @@ __all__ = [ import os import sys -import errno from itertools import product from mailman.config import config @@ -61,7 +60,8 @@ def search(template_file, mlist=None, language=None): The <language> path component is variable, and described below. * The list-specific language directory - $template_dir/lists/<mlist.fqdn_listname>/<language> + $template_dir/lists/<mlist.list_id>/<language> + $template_dir/lists/<mlist.fqdn_listname>/<language> (deprecated) * The domain-specific language directory $template_dir/domains/<mlist.mail_host>/<language> @@ -78,23 +78,27 @@ def search(template_file, mlist=None, language=None): Languages are iterated after each of the four locations are searched. So for example, when searching for the 'foo.txt' template, where the server's - default language is 'fr', the mailing list's (test@example.com) language + default language is 'fr', the mailing list's (test.example.com) language is 'de' and the `language` parameter is 'it', these locations are searched in order: - * $template_dir/lists/test@example.com/it/foo.txt + * $template_dir/lists/test.example.com/it/foo.txt + * $template_dir/lists/test@example.com/it/foo.txt (deprecated) * $template_dir/domains/example.com/it/foo.txt * $template_dir/site/it/foo.txt - * $template_dir/lists/test@example.com/de/foo.txt + * $template_dir/lists/test.example.com/de/foo.txt + * $template_dir/lists/test@example.com/de/foo.txt (deprecated) * $template_dir/domains/example.com/de/foo.txt * $template_dir/site/de/foo.txt - * $template_dir/lists/test@example.com/fr/foo.txt + * $template_dir/lists/test.example.com/fr/foo.txt + * $template_dir/lists/test@example.com/fr/foo.txt (deprecated) * $template_dir/domains/example.com/fr/foo.txt * $template_dir/site/fr/foo.txt - * $template_dir/lists/test@example.com/en/foo.txt + * $template_dir/lists/test.example.com/en/foo.txt + * $template_dir/lists/test@example.com/en/foo.txt (deprecated) * $template_dir/domains/example.com/en/foo.txt * $template_dir/site/en/foo.txt @@ -113,10 +117,13 @@ def search(template_file, mlist=None, language=None): # The non-language qualified $template_dir paths in search order. paths = [os.path.join(config.TEMPLATE_DIR, 'site')] if mlist is not None: + # Don't forget these are in REVERSE search order! paths.append(os.path.join( config.TEMPLATE_DIR, 'domains', mlist.mail_host)) paths.append(os.path.join( config.TEMPLATE_DIR, 'lists', mlist.fqdn_listname)) + paths.append(os.path.join( + config.TEMPLATE_DIR, 'lists', mlist.list_id)) paths.reverse() for language, path in product(languages, paths): yield os.path.join(path, language, template_file) @@ -151,15 +158,12 @@ def find(template_file, mlist=None, language=None, _trace=False): if _trace: print('@@@', path, end='', file=sys.stderr) fp = open(path, 'r', encoding='utf-8') - except IOError as error: - if error.errno == errno.ENOENT: - if _trace: - print('MISSING', file=sys.stderr) - else: - raise + except FileNotFoundError: + if _trace: + print(' MISSING', file=sys.stderr) else: if _trace: - print('FOUND:', path, file=sys.stderr) + print(' FOUND:', path, file=sys.stderr) return path, fp raise TemplateNotFoundError(template_file) diff --git a/src/mailman/utilities/tests/test_templates.py b/src/mailman/utilities/tests/test_templates.py index 8697699ab..f4b581b90 100644 --- a/src/mailman/utilities/tests/test_templates.py +++ b/src/mailman/utilities/tests/test_templates.py @@ -88,18 +88,22 @@ class TestSearchOrder(unittest.TestCase): def nexteq(path): self.assertEqual(next(search_order), path) # 1: Use the given language argument + nexteq('/v/templates/lists/l.example.com/it/foo.txt') nexteq('/v/templates/lists/l@example.com/it/foo.txt') nexteq('/v/templates/domains/example.com/it/foo.txt') nexteq('/v/templates/site/it/foo.txt') # 2: Use mlist.preferred_language + nexteq('/v/templates/lists/l.example.com/de/foo.txt') nexteq('/v/templates/lists/l@example.com/de/foo.txt') nexteq('/v/templates/domains/example.com/de/foo.txt') nexteq('/v/templates/site/de/foo.txt') # 3: Use the site's default language + nexteq('/v/templates/lists/l.example.com/fr/foo.txt') nexteq('/v/templates/lists/l@example.com/fr/foo.txt') nexteq('/v/templates/domains/example.com/fr/foo.txt') nexteq('/v/templates/site/fr/foo.txt') # 4: English + nexteq('/v/templates/lists/l.example.com/en/foo.txt') nexteq('/v/templates/lists/l@example.com/en/foo.txt') nexteq('/v/templates/domains/example.com/en/foo.txt') nexteq('/v/templates/site/en/foo.txt') @@ -114,14 +118,17 @@ class TestSearchOrder(unittest.TestCase): def nexteq(path): self.assertEqual(next(search_order), path) # 1: Use mlist.preferred_language + nexteq('/v/templates/lists/l.example.com/de/foo.txt') nexteq('/v/templates/lists/l@example.com/de/foo.txt') nexteq('/v/templates/domains/example.com/de/foo.txt') nexteq('/v/templates/site/de/foo.txt') # 2: Use the site's default language + nexteq('/v/templates/lists/l.example.com/fr/foo.txt') nexteq('/v/templates/lists/l@example.com/fr/foo.txt') nexteq('/v/templates/domains/example.com/fr/foo.txt') nexteq('/v/templates/site/fr/foo.txt') # 3: English + nexteq('/v/templates/lists/l.example.com/en/foo.txt') nexteq('/v/templates/lists/l@example.com/en/foo.txt') nexteq('/v/templates/domains/example.com/en/foo.txt') nexteq('/v/templates/site/en/foo.txt') |
