Skip to content

Commit

Permalink
Fix getpelican#1223: PAGINATION_PATTERNS with tags/cats/…
Browse files Browse the repository at this point in the history
+Added unit test to avoid future reproduction.

The Paginator Page was keeping only the directory path for {base_name}, which
means that different items (tags, categories…) were collapsing into the same
file.  Instead, it is now keeping everything but the extension, so that a tag
(or category…) is not collapsing with an other one.

Bug is likely introduced by e07b39d.
Bug discovered thanks to the “no overwrite” feature.
  • Loading branch information
Rogdham committed Jun 6, 2014
1 parent b8db970 commit cad9209
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pelican/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
32 changes: 23 additions & 9 deletions pelican/tests/test_paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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'),
))

0 comments on commit cad9209

Please sign in to comment.