comparison foodtruck/views/dashboard.py @ 770:a7726e4862c4

admin: Fix API changes, don't crash the dashboard on non-binary WIP files. Treat new/edited files that have no `auto_format` supported extension as "miscellaneous" files, which are shown separately on the dashboard.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 02 Jul 2016 01:30:51 -0700
parents 4d8e82641597
children 3885421c29a3
comparison
equal deleted inserted replaced
769:d841716d8e0d 770:a7726e4862c4
37 if fe: 37 if fe:
38 fs_endpoints[fe] = source 38 fs_endpoints[fe] = source
39 39
40 data['new_pages'] = [] 40 data['new_pages'] = []
41 data['edited_pages'] = [] 41 data['edited_pages'] = []
42 data['misc_files'] = []
42 if site.scm: 43 if site.scm:
43 st = site.scm.getStatus() 44 st = site.scm.getStatus()
44 for p in st.new_files: 45 for p in st.new_files:
45 pd = _getWipData(p, site, fs_endpoints) 46 pd = _getWipData(p, site, fs_endpoints)
46 if pd: 47 if pd:
47 data['new_pages'].append(pd) 48 data['new_pages'].append(pd)
49 else:
50 data['misc_files'].append(p)
48 for p in st.edited_files: 51 for p in st.edited_files:
49 pd = _getWipData(p, site, fs_endpoints) 52 pd = _getWipData(p, site, fs_endpoints)
50 if pd: 53 if pd:
51 data['edited_pages'].append(pd) 54 data['edited_pages'].append(pd)
55 else:
56 data['misc_files'].append(p)
52 57
53 data['site_name'] = site.name 58 data['site_name'] = site.name
54 data['site_title'] = site.piecrust_app.config.get('site/title', site.name) 59 data['site_title'] = site.piecrust_app.config.get('site/title', site.name)
55 data['url_publish'] = url_for('publish') 60 data['url_publish'] = url_for('publish')
56 data['url_preview'] = url_for('preview_site_root', sitename=site.name) 61 data['url_preview'] = url_for('preview_site_root', sitename=site.name)
68 with_menu_context(data) 73 with_menu_context(data)
69 return render_template('dashboard.html', **data) 74 return render_template('dashboard.html', **data)
70 75
71 76
72 def _getWipData(path, site, fs_endpoints): 77 def _getWipData(path, site, fs_endpoints):
78 auto_formats = site.piecrust_app.config.get('site/auto_formats', ['html'])
79 pathname, pathext = os.path.splitext(path)
80 if pathext not in auto_formats:
81 return None
82
73 source = None 83 source = None
74 for endpoint, s in fs_endpoints.items(): 84 for endpoint, s in fs_endpoints.items():
75 if path.startswith(endpoint): 85 if path.startswith(endpoint):
76 source = s 86 source = s
77 break 87 break
78 if source is None: 88 if source is None:
79 return None 89 return None
80 90
81 fac = source.buildPageFactory(os.path.join(site.root_dir, path)) 91 fac = source.buildPageFactory(os.path.join(site.root_dir, path))
82 route = site.piecrust_app.getRoute( 92 route = site.piecrust_app.getSourceRoute(source.name, fac.metadata)
83 source.name, fac.metadata, skip_taxonomies=True)
84 if not route: 93 if not route:
85 return None 94 return None
86 95
87 qp = QualifiedPage(fac.buildPage(), route, fac.metadata) 96 qp = QualifiedPage(fac.buildPage(), route, fac.metadata)
88 uri = qp.getUri() 97 uri = qp.getUri()