From d01614495fed0674d9c3745dc1bb76c3f98aff34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 10 Nov 2018 23:30:27 +0100 Subject: [PATCH 1/3] settings: test reading PAGINATED_DIRECT_TEMPLATES from pelicanconf.py. At the moment aborts with the following: File "/usr/lib/python3.7/site-packages/pelican/settings.py", line 327, in handle_deprecated_settings if t not in settings['PAGINATED_TEMPLATES']: KeyError: 'PAGINATED_TEMPLATES' --- pelican/tests/test_settings.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pelican/tests/test_settings.py b/pelican/tests/test_settings.py index 5e794dc5..bb05e2ae 100644 --- a/pelican/tests/test_settings.py +++ b/pelican/tests/test_settings.py @@ -187,6 +187,20 @@ class TestSettingsConfiguration(unittest.TestCase): {'index': 10, 'category': None, 'archives': None}) self.assertNotIn('PAGINATED_DIRECT_TEMPLATES', settings) + def test_deprecated_paginated_direct_templates_from_file(self): + # This is equivalent to reading a settings file that has + # PAGINATED_DIRECT_TEMPLATES defined but no PAGINATED_TEMPLATES. + settings = read_settings(None, override={ + 'PAGINATED_DIRECT_TEMPLATES': ['index', 'archives'] + }) + self.assertEqual(settings['PAGINATED_TEMPLATES'], { + 'archives': None, + 'author': None, + 'index': None, + 'category': None, + 'tag': None}) + self.assertNotIn('PAGINATED_DIRECT_TEMPLATES', settings) + def test_theme_and_extra_templates_exception(self): settings = self.settings settings['EXTRA_TEMPLATES_PATHS'] = ['/ha'] From 4c3b6ac383115be4f6664d0e6389cdffd310b926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2018 00:17:00 +0100 Subject: [PATCH 2/3] settings: add another consistency test for SLUG_SUBSTITUTIONS. --- pelican/tests/test_settings.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pelican/tests/test_settings.py b/pelican/tests/test_settings.py index bb05e2ae..a92cf09c 100644 --- a/pelican/tests/test_settings.py +++ b/pelican/tests/test_settings.py @@ -285,3 +285,14 @@ class TestSettingsConfiguration(unittest.TestCase): self.assertEqual(settings['AUTHOR_REGEX_SUBSTITUTIONS'], [(r'Alexander\ Todorov', 'atodorov')] + default_slug_regex_subs) + + def test_deprecated_slug_substitutions_from_file(self): + # This is equivalent to reading a settings file that has + # SLUG_SUBSTITUTIONS defined but no SLUG_REGEX_SUBSTITUTIONS. + settings = read_settings(None, override={ + 'SLUG_SUBSTITUTIONS': [('C++', 'cpp')] + }) + self.assertEqual(settings['SLUG_REGEX_SUBSTITUTIONS'], + [(r'C\+\+', 'cpp')] + + self.settings['SLUG_REGEX_SUBSTITUTIONS']) + self.assertNotIn('SLUG_SUBSTITUTIONS', settings) From 74a2481bf3182f6e1b814eb02d52046d22905282 Mon Sep 17 00:00:00 2001 From: Deniz Turgut Date: Sun, 11 Nov 2018 13:57:13 +0100 Subject: [PATCH 3/3] settings: set backward-compatible PAGINATED_TEMPLATES if not present. --- pelican/settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pelican/settings.py b/pelican/settings.py index 6907051c..b94859a6 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -323,6 +323,11 @@ def handle_deprecated_settings(settings): 'PAGINATED_DIRECT_TEMPLATES', 'PAGINATED_TEMPLATES') logger.warning(message) + # set PAGINATED_TEMPLATES + if 'PAGINATED_TEMPLATES' not in settings: + settings['PAGINATED_TEMPLATES'] = { + 'tag': None, 'category': None, 'author': None} + for t in settings['PAGINATED_DIRECT_TEMPLATES']: if t not in settings['PAGINATED_TEMPLATES']: settings['PAGINATED_TEMPLATES'][t] = None