From f2f1e3f51e81d23d76b1edcc45e67af6ff98c081 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Sun, 7 Sep 2014 19:53:36 -0500 Subject: [PATCH] fix bug when fetching metadata on pages that don't exist --- realms/modules/wiki/models.py | 14 ++++++++++++-- realms/modules/wiki/views.py | 17 +++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index 273999f..d2389c8 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -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) diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index 3a5ed57..a665171 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -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)) \ No newline at end of file