fix bug when fetching metadata on pages that don't exist

This commit is contained in:
Matthew Scragg 2014-09-07 19:53:36 -05:00
parent bea662e2e7
commit f2f1e3f51e
2 changed files with 15 additions and 16 deletions

View file

@ -156,7 +156,18 @@ class Wiki():
sha = sha.encode('latin-1')
try:
return self.repo.get_commit_files(sha, paths=[name]).get(name)
data = self.repo.get_commit_files(sha, paths=[name]).get(name)
if not data:
return None
partials = {}
if data.get('data'):
meta = self.get_meta(data['data'])
if meta and 'import' in meta:
for partial_name in meta['import']:
partials[partial_name] = self.get_page(partial_name)
data['partials'] = partials
return data
except KeyError:
# HEAD doesn't exist yet
return None
@ -168,7 +179,6 @@ class Wiki():
if not meta_end:
return None
return yaml.safe_load(content[0:meta_end.start()])
#return [content[0:meta_end.start()], content[meta_end.end():]]
def compare(self, name, old_sha, new_sha):
old = self.get_page(name, sha=old_sha)

View file

@ -60,15 +60,10 @@ def edit(name):
username=current_user.username)
else:
if data:
partials = {}
meta = wiki.get_meta(data['data'])
if meta and 'import' in meta:
for partial_name in meta['import']:
partials[partial_name] = wiki.get_page(partial_name)
name = remove_ext(data['name'])
content = data['data']
content = data.get('data')
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html', name=name, content=content, partials=partials)
return render_template('wiki/edit.html', name=name, content=content, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
@ -107,14 +102,8 @@ def page(name):
return redirect(url_for('wiki.page', name=cname))
data = wiki.get_page(cname)
meta = wiki.get_meta(data['data'])
partials = {}
if meta and 'import' in meta:
for partial_name in meta['import']:
partials[partial_name] = wiki.get_page(partial_name)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=partials)
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))