From 9108f8214926e140b8db4f5eeb859bc8bba85139 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Tue, 8 Dec 2015 21:38:09 -0500 Subject: [PATCH] Preliminary subdirectory support. refs #50 --- realms/lib/util.py | 4 ++-- realms/modules/wiki/models.py | 5 +++++ realms/modules/wiki/views.py | 14 +++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/realms/lib/util.py b/realms/lib/util.py index fdb7777..74dcf26 100644 --- a/realms/lib/util.py +++ b/realms/lib/util.py @@ -85,10 +85,10 @@ def to_canonical(s): """ Double space -> single dash Double dash -> single dash - Remove all non alphanumeric and dash + Remove all non alphanumeric and dash except path separatos (/) Limit to first 128 chars """ - reserved_chars = "&$+,/:;=?@#" + reserved_chars = "&$+,:;=?@#" unsafe_chars = "?<>[]{}|\^~%" s = s.encode('utf8') diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index 4a2a8e7..70e912e 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -1,4 +1,5 @@ import os +import posixpath import re import ghdiff import gittle.utils @@ -82,6 +83,10 @@ class Wiki(HookMixin): cname = to_canonical(name) filename = cname_to_filename(cname) + dirname = posixpath.join(self.path, posixpath.dirname(filename)) + + if not os.path.exists(dirname): + os.makedirs(dirname) with open(self.path + "/" + filename, 'w') as f: f.write(content) diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index bbd13bc..58c40d2 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -6,7 +6,7 @@ from .models import PageNotFound blueprint = Blueprint('wiki', __name__) -@blueprint.route("/_commit//") +@blueprint.route("/_commit//") def commit(name, sha): if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): return current_app.login_manager.unauthorized() @@ -21,7 +21,7 @@ def commit(name, sha): return render_template('wiki/page.html', name=name, page=data, commit=sha) -@blueprint.route("/_compare//") +@blueprint.route(r"/_compare//") def compare(name, fsha, dots, lsha): if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): return current_app.login_manager.unauthorized() @@ -59,7 +59,7 @@ def revert(): return dict(sha=sha) -@blueprint.route("/_history/") +@blueprint.route("/_history/") def history(name): if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): return current_app.login_manager.unauthorized() @@ -67,7 +67,7 @@ def history(name): return render_template('wiki/history.html', name=name, history=g.current_wiki.get_history(name)) -@blueprint.route("/_edit/") +@blueprint.route("/_edit/") @login_required def edit(name): cname = to_canonical(name) @@ -88,7 +88,7 @@ def edit(name): @blueprint.route("/_create/", defaults={'name': None}) -@blueprint.route("/_create/") +@blueprint.route("/_create/") @login_required def create(name): cname = to_canonical(name) if name else "" @@ -111,7 +111,7 @@ def index(): return render_template('wiki/index.html', index=g.current_wiki.get_index()) -@blueprint.route("/", methods=['POST', 'PUT', 'DELETE']) +@blueprint.route("/", methods=['POST', 'PUT', 'DELETE']) @login_required def page_write(name): cname = to_canonical(name) @@ -164,7 +164,7 @@ def page_write(name): @blueprint.route("/", defaults={'name': 'home'}) -@blueprint.route("/") +@blueprint.route("/") def page(name): if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous(): return current_app.login_manager.unauthorized()