diff --git a/pelican/paginator.py b/pelican/paginator.py index 757c912072..d1a72e0fad 100644 --- a/pelican/paginator.py +++ b/pelican/paginator.py @@ -141,7 +141,7 @@ def _from_settings(self, key): 'number': self.number, 'paginator': self.paginator, 'settings': self.settings, - 'base_name': os.path.dirname(self.name), + 'base_name': self.name, 'number_sep': '/', 'extension': self.extension, } diff --git a/pelican/tests/test_paginator.py b/pelican/tests/test_paginator.py index 108dc79188..1526fb27cc 100644 --- a/pelican/tests/test_paginator.py +++ b/pelican/tests/test_paginator.py @@ -35,16 +35,16 @@ def setUp(self): def tearDown(self): locale.setlocale(locale.LC_ALL, self.old_locale) - def test_save_as_preservation(self): - settings = get_settings() + def _test_save_as_setting(self, save_as_page_1, save_as_page_2, + pagination_patterns=None): + if pagination_patterns is None: + settings = get_settings() + else: + settings = get_settings(PAGINATION_PATTERNS=pagination_patterns) # fix up pagination rules from pelican.paginator import PaginationRule - pagination_rules = [ - PaginationRule(*r) for r in settings.get( - 'PAGINATION_PATTERNS', - DEFAULT_CONFIG['PAGINATION_PATTERNS'], - ) - ] + pagination_rules = [PaginationRule(*r) + for r in settings['PAGINATION_PATTERNS']] settings['PAGINATION_PATTERNS'] = sorted( pagination_rules, key=lambda r: r[0], @@ -53,4 +53,18 @@ def test_save_as_preservation(self): object_list = [Article(**self.page_kwargs), Article(**self.page_kwargs)] paginator = Paginator('foobar.foo', object_list, settings) page = paginator.page(1) - self.assertEqual(page.save_as, 'foobar.foo') + self.assertEqual(page.save_as, save_as_page_1) + page = paginator.page(2) + self.assertEqual(page.save_as, save_as_page_2) + + def test_save_as_preservation(self): + self._test_save_as_setting('foobar.foo', 'foobar2.foo') + + def test_save_as_base_name(self): + self._test_save_as_setting( + 'foobar/index.foo', + 'foobar/page/2.foo', + ( + (1, '{base_name}/', '{base_name}/index.foo'), + (2, '{base_name}/page/{number}', '{base_name}/page/{number}.foo'), + ))