Mercurial > piecrust2
comparison piecrust/app.py @ 93:28ea3e69d67e
Use the `OrderedDict` correctly when fresh-loading the app config.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 05 Sep 2014 00:42:52 -0700 |
parents | 2fb6501ed668 |
children | 10fc9c8bf682 |
comparison
equal
deleted
inserted
replaced
92:0dd43c5f5484 | 93:28ea3e69d67e |
---|---|
99 self.cache.write('config.json', config_text) | 99 self.cache.write('config.json', config_text) |
100 self._values['__cache_valid'] = False | 100 self._values['__cache_valid'] = False |
101 | 101 |
102 def _validateAll(self, values): | 102 def _validateAll(self, values): |
103 # Put all the defaults in the `site` section. | 103 # Put all the defaults in the `site` section. |
104 default_sitec = { | 104 default_sitec = collections.OrderedDict({ |
105 'title': "Untitled PieCrust website", | 105 'title': "Untitled PieCrust website", |
106 'root': '/', | 106 'root': '/', |
107 'default_format': DEFAULT_FORMAT, | 107 'default_format': DEFAULT_FORMAT, |
108 'default_template_engine': DEFAULT_TEMPLATE_ENGINE, | 108 'default_template_engine': DEFAULT_TEMPLATE_ENGINE, |
109 'enable_gzip': True, | 109 'enable_gzip': True, |
122 'themes_sources': [DEFAULT_THEME_SOURCE], | 122 'themes_sources': [DEFAULT_THEME_SOURCE], |
123 'cache_time': 28800, | 123 'cache_time': 28800, |
124 'display_errors': True, | 124 'display_errors': True, |
125 'enable_debug_info': True, | 125 'enable_debug_info': True, |
126 'use_default_content': True | 126 'use_default_content': True |
127 } | 127 }) |
128 sitec = values.get('site') | 128 sitec = values.get('site') |
129 if sitec is None: | 129 if sitec is None: |
130 sitec = {} | 130 sitec = collections.OrderedDict() |
131 for key, val in default_sitec.items(): | 131 for key, val in default_sitec.items(): |
132 sitec.setdefault(key, val) | 132 sitec.setdefault(key, val) |
133 values['site'] = sitec | 133 values['site'] = sitec |
134 | 134 |
135 # Add a section for our cached information. | 135 # Add a section for our cached information. |
136 cachec = {} | 136 cachec = collections.OrderedDict() |
137 values['__cache'] = cachec | 137 values['__cache'] = cachec |
138 | 138 |
139 # Cache auto-format regexes. | 139 # Cache auto-format regexes. |
140 if not isinstance(sitec['auto_formats'], dict): | 140 if not isinstance(sitec['auto_formats'], dict): |
141 raise ConfigurationError("The 'site/auto_formats' setting must be a dictionary.") | 141 raise ConfigurationError("The 'site/auto_formats' setting must be a dictionary.") |
186 g_posts_per_page = sitec.get('items_per_page', 5) | 186 g_posts_per_page = sitec.get('items_per_page', 5) |
187 g_posts_filters = sitec.get('items_filters') | 187 g_posts_filters = sitec.get('items_filters') |
188 g_date_format = sitec.get('date_format', DEFAULT_DATE_FORMAT) | 188 g_date_format = sitec.get('date_format', DEFAULT_DATE_FORMAT) |
189 | 189 |
190 # The normal pages and tags/categories. | 190 # The normal pages and tags/categories. |
191 sourcesc = {} | 191 sourcesc = collections.OrderedDict() |
192 sourcesc['pages'] = { | 192 sourcesc['pages'] = { |
193 'type': 'default', | 193 'type': 'default', |
194 'ignore_missing_dir': True, | 194 'ignore_missing_dir': True, |
195 'data_endpoint': 'site.pages', | 195 'data_endpoint': 'site.pages', |
196 'item_name': 'page'} | 196 'item_name': 'page'} |
201 'url': '/%path:path%', | 201 'url': '/%path:path%', |
202 'source': 'pages', | 202 'source': 'pages', |
203 'func': 'pcurl(path)'}) | 203 'func': 'pcurl(path)'}) |
204 sitec['routes'] = routesc | 204 sitec['routes'] = routesc |
205 | 205 |
206 taxonomiesc = {} | 206 taxonomiesc = collections.OrderedDict() |
207 taxonomiesc['tags'] = { | 207 taxonomiesc['tags'] = { |
208 'multiple': True, | 208 'multiple': True, |
209 'term': 'tag'} | 209 'term': 'tag'} |
210 taxonomiesc['categories'] = { | 210 taxonomiesc['categories'] = { |
211 'term': 'category'} | 211 'term': 'category'} |
261 'func': 'pccaturl(category)'}) | 261 'func': 'pccaturl(category)'}) |
262 | 262 |
263 # If the user defined some additional sources/routes/taxonomies, | 263 # If the user defined some additional sources/routes/taxonomies, |
264 # append them to the default ones. | 264 # append them to the default ones. |
265 if orig_sources: | 265 if orig_sources: |
266 sourcesc += orig_sources | 266 sourcesc.update(orig_sources) |
267 if orig_routes: | 267 if orig_routes: |
268 routesc + orig_routes | 268 routesc + orig_routes |
269 if orig_taxonomies: | 269 if orig_taxonomies: |
270 taxonomiesc += orig_taxonomies | 270 taxonomiesc.update(orig_taxonomies) |
271 | 271 |
272 # Validate sources/routes. | 272 # Validate sources/routes. |
273 sourcesc = sitec.get('sources') | 273 sourcesc = sitec.get('sources') |
274 routesc = sitec.get('routes') | 274 routesc = sitec.get('routes') |
275 if not sourcesc: | 275 if not sourcesc: |