Mercurial > piecrust2
comparison piecrust/sources/mixins.py @ 280:8c0c53a315ae
data: Correctly build pagination filters when we know items are pages.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Sun, 01 Mar 2015 21:39:26 -0800 |
| parents | 07b4b8484c0a |
| children | 4b1019bb2533 |
comparison
equal
deleted
inserted
replaced
| 279:980bbbd0705e | 280:8c0c53a315ae |
|---|---|
| 1 import os | 1 import os |
| 2 import os.path | 2 import os.path |
| 3 import logging | 3 import logging |
| 4 from piecrust.data.base import PaginationData | 4 from piecrust.data.base import PaginationData |
| 5 from piecrust.data.filters import PaginationFilter | 5 from piecrust.data.filters import PaginationFilter, page_value_accessor |
| 6 from piecrust.sources.base import PageFactory | 6 from piecrust.sources.base import PageFactory |
| 7 from piecrust.sources.interfaces import IPaginationSource, IListableSource | 7 from piecrust.sources.interfaces import IPaginationSource, IListableSource |
| 8 | 8 |
| 9 | 9 |
| 10 logger = logging.getLogger(__name__) | 10 logger = logging.getLogger(__name__) |
| 42 yield None | 42 yield None |
| 43 else: | 43 else: |
| 44 yield PaginationData(page) | 44 yield PaginationData(page) |
| 45 | 45 |
| 46 | 46 |
| 47 def page_setting_accessor(item, name): | |
| 48 return item.config.get(name) | |
| 49 | |
| 50 | |
| 51 class SimplePaginationSourceMixin(IPaginationSource): | 47 class SimplePaginationSourceMixin(IPaginationSource): |
| 52 """ Implements the `IPaginationSource` interface in a standard way that | 48 """ Implements the `IPaginationSource` interface in a standard way that |
| 53 should fit most page sources. | 49 should fit most page sources. |
| 54 """ | 50 """ |
| 55 def getItemsPerPage(self): | 51 def getItemsPerPage(self): |
| 68 conf = (page.config.get('items_filters') or | 64 conf = (page.config.get('items_filters') or |
| 69 self.config.get('items_filters')) | 65 self.config.get('items_filters')) |
| 70 if conf == 'none' or conf == 'nil' or conf == '': | 66 if conf == 'none' or conf == 'nil' or conf == '': |
| 71 conf = None | 67 conf = None |
| 72 if conf is not None: | 68 if conf is not None: |
| 73 f = PaginationFilter() | 69 f = PaginationFilter(value_accessor=page_value_accessor) |
| 74 f.addClausesFromConfig(conf) | 70 f.addClausesFromConfig(conf) |
| 75 return f | 71 return f |
| 76 return None | 72 return None |
| 77 | 73 |
| 78 def getSettingAccessor(self): | 74 def getSettingAccessor(self): |
| 79 return page_setting_accessor | 75 return page_value_accessor |
| 80 | 76 |
| 81 | 77 |
| 82 class SimpleListableSourceMixin(IListableSource): | 78 class SimpleListableSourceMixin(IListableSource): |
| 83 """ Implements the `IListableSource` interface for sources that map to | 79 """ Implements the `IListableSource` interface for sources that map to |
| 84 simple file-system structures. | 80 simple file-system structures. |
