mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Allow definition of pagination rules by page index.
This commit is contained in:
parent
71e83635ea
commit
95890a2a61
2 changed files with 31 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals, print_function
|
|||
import six
|
||||
|
||||
# From django.core.paginator
|
||||
from collections import namedtuple
|
||||
import functools
|
||||
import logging
|
||||
import os
|
||||
|
|
@ -11,6 +12,13 @@ from math import ceil
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
PaginationRule = namedtuple(
|
||||
'PaginationRule',
|
||||
'min_page URL SAVE_AS',
|
||||
)
|
||||
|
||||
|
||||
class Paginator(object):
|
||||
def __init__(self, name, object_list, settings):
|
||||
self.name = name
|
||||
|
|
@ -109,8 +117,16 @@ class Page(object):
|
|||
"""Returns URL information as defined in settings. Similar to
|
||||
URLWrapper._from_settings, but specialized to deal with pagination
|
||||
logic."""
|
||||
setting = "%s_%s" % ('PAGINATION', key)
|
||||
value = self.settings[setting]
|
||||
|
||||
rule = None
|
||||
|
||||
# find the last matching pagination rule
|
||||
for p in self.settings['PAGINATION_PATTERNS']:
|
||||
if p.min_page <= self.number:
|
||||
rule = p
|
||||
|
||||
value = getattr(rule, key)
|
||||
|
||||
if not isinstance(value, six.string_types):
|
||||
logger.warning('%s is set to %s' % (setting, value))
|
||||
return value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue