comparison piecrust/data/linker.py @ 381:4c9eab0e283b

data: Fix problems with using non-existing metadata on a linked page. The page data wrapper now has supports for loader to raise a custom exception to declare that they can't return a value after all (this is especially useful for the wildcard loader). The returned value, if any, is also now cached properly.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 10 May 2015 00:37:28 -0700
parents 2408eb6f4da8
children 8e1e55ad35fb
comparison
equal deleted inserted replaced
380:f33712c4cfab 381:4c9eab0e283b
1 import logging 1 import logging
2 import collections 2 import collections
3 from piecrust.data.base import PaginationData 3 from piecrust.data.base import PaginationData, LazyPageConfigLoaderHasNoValue
4 from piecrust.data.iterators import PageIterator 4 from piecrust.data.iterators import PageIterator
5 from piecrust.sources.base import build_pages
6 from piecrust.sources.interfaces import IPaginationSource, IListableSource 5 from piecrust.sources.interfaces import IPaginationSource, IListableSource
7 6
8 7
9 logger = logging.getLogger(__name__) 8 logger = logging.getLogger(__name__)
10 9
51 self.is_dir = (self.children is not None) 50 self.is_dir = (self.children is not None)
52 self.is_page = True 51 self.is_page = True
53 52
54 self.mapLoader('*', self._linkerChildLoader) 53 self.mapLoader('*', self._linkerChildLoader)
55 54
56 def _linkerChildLoader(self, name): 55 def _linkerChildLoader(self, data, name):
57 return getattr(self.children, name) 56 if self.children and hasattr(self.children, name):
57 return getattr(self.children, name)
58 raise LazyPageConfigLoaderHasNoValue
58 59
59 60
60 class LinkedPageDataBuilderIterator(object): 61 class LinkedPageDataBuilderIterator(object):
61 """ Iterator that builds `LinkedPageData` out of pages. 62 """ Iterator that builds `LinkedPageData` out of pages.
62 """ 63 """