Mercurial > piecrust2
comparison piecrust/page.py @ 147:ab6e7e0e9d44
Pass date information to routing when building URLs.
This is so that URLs with dates in them can be built even when the date
information is not coming from the source metadata, but from the page's
config.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 29 Nov 2014 21:00:44 -0800 |
parents | 0bdd938d6b9f |
children | aa6b7ff6a193 |
comparison
equal
deleted
inserted
replaced
146:0609739169bd | 147:ab6e7e0e9d44 |
---|---|
9 import dateutil.parser | 9 import dateutil.parser |
10 import collections | 10 import collections |
11 from werkzeug.utils import cached_property | 11 from werkzeug.utils import cached_property |
12 from piecrust.configuration import (Configuration, ConfigurationError, | 12 from piecrust.configuration import (Configuration, ConfigurationError, |
13 parse_config_header) | 13 parse_config_header) |
14 from piecrust.routing import IRouteMetadataProvider | |
14 | 15 |
15 | 16 |
16 logger = logging.getLogger(__name__) | 17 logger = logging.getLogger(__name__) |
17 | 18 |
18 | 19 |
34 | 35 |
35 FLAG_NONE = 0 | 36 FLAG_NONE = 0 |
36 FLAG_RAW_CACHE_VALID = 2**0 | 37 FLAG_RAW_CACHE_VALID = 2**0 |
37 | 38 |
38 | 39 |
39 class Page(object): | 40 class Page(IRouteMetadataProvider): |
40 def __init__(self, source, source_metadata, rel_path): | 41 def __init__(self, source, source_metadata, rel_path): |
41 self.source = source | 42 self.source = source |
42 self.source_metadata = source_metadata | 43 self.source_metadata = source_metadata |
43 self.rel_path = rel_path | 44 self.rel_path = rel_path |
44 self._config = None | 45 self._config = None |
135 self._config = config | 136 self._config = config |
136 self._raw_content = content | 137 self._raw_content = content |
137 if was_cache_valid: | 138 if was_cache_valid: |
138 self._flags |= FLAG_RAW_CACHE_VALID | 139 self._flags |= FLAG_RAW_CACHE_VALID |
139 | 140 |
141 def getRouteMetadata(self): | |
142 page_dt = self.datetime | |
143 return { | |
144 'year': page_dt.year, | |
145 'month': page_dt.month, | |
146 'day': page_dt.day} | |
147 | |
140 | 148 |
141 def _parse_config_date(page_date): | 149 def _parse_config_date(page_date): |
142 if page_date is None: | 150 if page_date is None: |
143 return None | 151 return None |
144 | 152 |