wiki get page

This commit is contained in:
Matthew Scragg 2013-09-28 16:33:00 -05:00
parent 26137047cd
commit 32e152a2a7
3 changed files with 17 additions and 13 deletions

View file

@ -35,7 +35,7 @@ from models import Site
site = Site.get_by_name(".")
wiki = Wiki(site.get('repo'))
w = Wiki(site.get('repo'))
def redirect_url():
@ -65,10 +65,13 @@ def rename(page):
@app.route("/edit/<page>", methods=['GET', 'POST'])
def edit(page):
pass
data = w.get_page(page)
if data:
return render_template('page/edit.html', page=data)
else:
return redirect('/create/'+page)
@app.route("/delete/<page>")
@app.route("/delete/<page>", methods=['POST'])
def delete(page):
pass
@ -80,12 +83,9 @@ def create(page):
@app.route("/<page>")
def render(page):
file_path = site.get('repo') + "/" + page.lower() + ".md"
if path.isfile(file_path):
f = open(file_path)
content = f.read()
f.close()
return render_template('page/page.html', content=content)
data = w.get_page(page)
if data:
return render_template('page/page.html', page=data)
else:
return redirect('/create/'+page)

View file

@ -1,6 +1,6 @@
{% extends 'layout.html' %}
{% block body %}
{{ content }}
{{ page.data }}
{% endblock %}

View file

@ -1,6 +1,7 @@
from gittle import Gittle
import os
class Wiki():
path = None
base_path = '/'
@ -8,9 +9,11 @@ class Wiki():
default_committer_name = 'Anon'
default_committer_email = 'anon@anon.anon'
index_page = 'Home'
repo = None
def __init__(self, path, **kwargs):
self.path = path
self.repo = Gittle(path)
def write_page(self, name):
name = name.replace(" ", "-")
@ -18,5 +21,6 @@ class Wiki():
def rename_page(self, page, rename, commit={}):
pass
def page_exists(self, name):
return None
def get_page(self, name):
name = name.lower() + ".md"
return self.repo.get_commit_files('HEAD', paths=[name]).get(name)