comparison piecrust/data/pagedata.py @ 854:08e02c2a2a1a

core: Keep refactoring, this time to prepare for generator sources. - Make a few APIs simpler. - Content pipelines create their own jobs, so that generator sources can keep aborting in `getContents`, but rely on their pipeline to generate pages for baking.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 04 Jun 2017 23:34:28 -0700
parents 4850f8c21b6e
children f4608e2e80ce
comparison
equal deleted inserted replaced
853:f070a4fc033c 854:08e02c2a2a1a
74 raise 74 raise
75 except Exception as ex: 75 except Exception as ex:
76 logger.exception(ex) 76 logger.exception(ex)
77 raise Exception( 77 raise Exception(
78 "Error while loading attribute '%s' for: %s" % 78 "Error while loading attribute '%s' for: %s" %
79 (name, self._page.rel_path)) from ex 79 (name, self._page.content_spec)) from ex
80 80
81 # Forget this loader now that it served its purpose. 81 # Forget this loader now that it served its purpose.
82 try: 82 try:
83 del self._loaders[name] 83 del self._loaders[name]
84 except KeyError: 84 except KeyError:
94 raise 94 raise
95 except Exception as ex: 95 except Exception as ex:
96 logger.exception(ex) 96 logger.exception(ex)
97 raise Exception( 97 raise Exception(
98 "Error while loading attribute '%s' for: %s" % 98 "Error while loading attribute '%s' for: %s" %
99 (name, self._page.rel_path)) from ex 99 (name, self._page.content_spec)) from ex
100 # We always keep the wildcard loader in the loaders list. 100 # We always keep the wildcard loader in the loaders list.
101 return self._values[name] 101 try:
102 return self._values[name]
103 except KeyError:
104 pass
102 105
103 raise LazyPageConfigLoaderHasNoValue("No such value: %s" % name) 106 raise LazyPageConfigLoaderHasNoValue()
104 107
105 def _setValue(self, name, value): 108 def _setValue(self, name, value):
106 self._values[name] = value 109 self._values[name] = value
107 110
108 def _unmapLoader(self, attr_name): 111 def _unmapLoader(self, attr_name):
134 self._load() 137 self._load()
135 except Exception as ex: 138 except Exception as ex:
136 logger.exception(ex) 139 logger.exception(ex)
137 raise Exception( 140 raise Exception(
138 "Error while loading data for: %s" % 141 "Error while loading data for: %s" %
139 self._page.rel_path) from ex 142 self._page.content_spec) from ex
140 143
141 def _load(self): 144 def _load(self):
142 pass 145 pass
143 146
144 def _debugRenderKeys(self): 147 def _debugRenderKeys(self):
160 def _load(self): 163 def _load(self):
161 page = self._page 164 page = self._page
162 dt = page.datetime 165 dt = page.datetime
163 for k, v in page.source_metadata.items(): 166 for k, v in page.source_metadata.items():
164 self._setValue(k, v) 167 self._setValue(k, v)
165 self._setValue('url', self._ctx.uri) 168 self._setValue('url', self._page.getUri(self._ctx.sub_num))
166 self._setValue('timestamp', time.mktime(dt.timetuple())) 169 self._setValue('timestamp', time.mktime(dt.timetuple()))
167 self._setValue('datetime', { 170 self._setValue('datetime', {
168 'year': dt.year, 'month': dt.month, 'day': dt.day, 171 'year': dt.year, 'month': dt.month, 'day': dt.day,
169 'hour': dt.hour, 'minute': dt.minute, 'second': dt.second}) 172 'hour': dt.hour, 'minute': dt.minute, 'second': dt.second})
170 date_format = page.app.config.get('site/date_format') 173 date_format = page.app.config.get('site/date_format')