Mercurial > piecrust2
comparison piecrust/app.py @ 83:f9f67086415c
Allow adding to the default content model instead of replacing it.
Allow dot and slash notation for data endpoints.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 01 Sep 2014 22:49:56 -0700 |
parents | fdb08d986384 |
children | 2fb6501ed668 |
comparison
equal
deleted
inserted
replaced
82:ae90caf26224 | 83:f9f67086415c |
---|---|
120 'pagination_suffix': '/%num%', | 120 'pagination_suffix': '/%num%', |
121 'plugins_sources': [DEFAULT_PLUGIN_SOURCE], | 121 'plugins_sources': [DEFAULT_PLUGIN_SOURCE], |
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 } | 127 } |
127 sitec = values.get('site') | 128 sitec = values.get('site') |
128 if sitec is None: | 129 if sitec is None: |
129 sitec = {} | 130 sitec = {} |
130 for key, val in default_sitec.items(): | 131 for key, val in default_sitec.items(): |
166 if pf is not None: | 167 if pf is not None: |
167 sitec.setdefault('items_filters', pf) | 168 sitec.setdefault('items_filters', pf) |
168 | 169 |
169 # Figure out if we need to validate sources/routes, or auto-generate | 170 # Figure out if we need to validate sources/routes, or auto-generate |
170 # them from simple blog settings. | 171 # them from simple blog settings. |
171 if 'sources' not in sitec: | 172 orig_sources = sitec.get('sources') |
173 orig_routes = sitec.get('routes') | |
174 orig_taxonomies = sitec.get('taxonomies') | |
175 use_default_content = sitec.get('use_default_content') | |
176 if (orig_sources is None or orig_routes is None or | |
177 orig_taxonomies is None or use_default_content): | |
178 | |
179 # Setup defaults for various settings. | |
172 posts_fs = sitec.setdefault('posts_fs', DEFAULT_POSTS_FS) | 180 posts_fs = sitec.setdefault('posts_fs', DEFAULT_POSTS_FS) |
173 blogsc = sitec.setdefault('blogs', ['posts']) | 181 blogsc = sitec.setdefault('blogs', ['posts']) |
174 | 182 |
175 g_post_url = sitec.get('post_url', '%year%/%month%/%day%/%slug%') | 183 g_post_url = sitec.get('post_url', '%year%/%month%/%day%/%slug%') |
176 g_tag_url = sitec.get('tag_url', 'tag/%tag%') | 184 g_tag_url = sitec.get('tag_url', 'tag/%tag%') |
177 g_category_url = sitec.get('category_url', '%category%') | 185 g_category_url = sitec.get('category_url', '%category%') |
178 g_posts_per_page = sitec.get('items_per_page', 5) | 186 g_posts_per_page = sitec.get('items_per_page', 5) |
179 g_posts_filters = sitec.get('items_filters') | 187 g_posts_filters = sitec.get('items_filters') |
180 g_date_format = sitec.get('date_format', DEFAULT_DATE_FORMAT) | 188 g_date_format = sitec.get('date_format', DEFAULT_DATE_FORMAT) |
181 | 189 |
190 # The normal pages and tags/categories. | |
182 sourcesc = {} | 191 sourcesc = {} |
183 sourcesc['pages'] = { | 192 sourcesc['pages'] = { |
184 'type': 'default', | 193 'type': 'default', |
185 'data_endpoint': 'site/pages', | 194 'data_endpoint': 'site.pages', |
186 'item_name': 'page'} | 195 'item_name': 'page'} |
187 sitec['sources'] = sourcesc | 196 sitec['sources'] = sourcesc |
188 | 197 |
189 routesc = [] | 198 routesc = [] |
190 routesc.append({ | 199 routesc.append({ |
199 'term': 'tag'} | 208 'term': 'tag'} |
200 taxonomiesc['categories'] = { | 209 taxonomiesc['categories'] = { |
201 'term': 'category'} | 210 'term': 'category'} |
202 sitec['taxonomies'] = taxonomiesc | 211 sitec['taxonomies'] = taxonomiesc |
203 | 212 |
213 # Setup sources/routes/taxonomies for each blog. | |
204 for blog_name in blogsc: | 214 for blog_name in blogsc: |
205 blogc = values.get(blog_name, {}) | 215 blogc = values.get(blog_name, {}) |
206 url_prefix = blog_name + '/' | 216 url_prefix = blog_name + '/' |
207 endpoint = 'posts/%s' % blog_name | 217 endpoint = 'posts/%s' % blog_name |
208 item_name = '%s-post' % blog_name | 218 item_name = '%s-post' % blog_name |
246 'func': 'pctagurl(tag)'}) | 256 'func': 'pctagurl(tag)'}) |
247 routesc.append({'url': category_url, 'source': blog_name, | 257 routesc.append({'url': category_url, 'source': blog_name, |
248 'taxonomy': 'categories', | 258 'taxonomy': 'categories', |
249 'func': 'pccaturl(category)'}) | 259 'func': 'pccaturl(category)'}) |
250 | 260 |
261 # If the user defined some additional sources/routes/taxonomies, | |
262 # append them to the default ones. | |
263 if orig_sources: | |
264 sourcesc += orig_sources | |
265 if orig_routes: | |
266 routesc + orig_routes | |
267 if orig_taxonomies: | |
268 taxonomiesc += orig_taxonomies | |
269 | |
251 # Validate sources/routes. | 270 # Validate sources/routes. |
252 sourcesc = sitec.get('sources') | 271 sourcesc = sitec.get('sources') |
253 routesc = sitec.get('routes') | 272 routesc = sitec.get('routes') |
254 if not sourcesc: | 273 if not sourcesc: |
255 raise ConfigurationError("There are no sources defined.") | 274 raise ConfigurationError("There are no sources defined.") |