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

View file

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

View file

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