From a891e77d406f17eb8eac19c1dbdf62564f7fc8e3 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Thu, 16 Jan 2014 17:37:55 -0600 Subject: [PATCH] updated wiki routes --- realms/__init__.py | 51 ++++++++++++++++-------------------- realms/modules/wiki/views.py | 15 +++++------ 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/realms/__init__.py b/realms/__init__.py index 0176098..87a2b06 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -213,35 +213,30 @@ for status_code in httplib.responses: assets = Environment() assets.init_app(app) -if config.ENV is 'PROD': - if 'js_common' not in assets._named_bundles: - assets.register('js_common', Bundle('packed-common.js')) - if 'js_editor' not in assets._named_bundles: - assets.register('js_editor', Bundle('packed-editor.js')) -else: - if 'js_common' not in assets._named_bundles: - js = Bundle( - Bundle('vendor/jquery/jquery.js', - 'vendor/components-underscore/underscore.js', - 'vendor/components-bootstrap/js/bootstrap.js', - 'vendor/handlebars/handlebars.js', - 'vendor/showdown/src/showdown.js', - 'vendor/showdown/src/extensions/table.js', - 'js/wmd.js', - filters='closure_js'), - 'js/html-sanitizer-minified.js', - 'vendor/highlightjs/highlight.pack.js', - Bundle('js/main.js', filters='closure_js'), - output='packed-common.js') - assets.register('js_common', js) - if 'js_editor' not in assets._named_bundles: - js = Bundle('js/ace/ace.js', - 'js/ace/mode-markdown.js', - 'vendor/keymaster/keymaster.js', - 'js/dillinger.js', - filters='closure_js', output='packed-editor.js') - assets.register('js_editor', js) + +js = Bundle( + Bundle('vendor/jquery/jquery.js', + 'vendor/components-underscore/underscore.js', + 'vendor/components-bootstrap/js/bootstrap.js', + 'vendor/handlebars/handlebars.js', + 'vendor/showdown/src/showdown.js', + 'vendor/showdown/src/extensions/table.js', + 'js/wmd.js', + filters='closure_js'), + 'js/html-sanitizer-minified.js', + 'vendor/highlightjs/highlight.pack.js', + Bundle('js/main.js', filters='closure_js'), + output='packed-common.js') +assets.register('js_common', js) + +js = Bundle('js/ace/ace.js', + 'js/ace/mode-markdown.js', + 'vendor/keymaster/keymaster.js', + 'js/dillinger.js', + filters='closure_js', output='packed-editor.js') + +assets.register('js_editor', js) @app.before_request diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index 4b0344c..0384931 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -47,11 +47,11 @@ def edit(name): edit_cname = to_canonical(request.form['name']) if edit_cname.lower() != cname.lower(): g.current_wiki.rename_page(cname, edit_cname) + g.current_wiki.write_page(edit_cname, request.form['content'], message=request.form['message'], username=g.current_user.get('username')) - return redirect(url_for('wiki.page', name=edit_cname)) else: if data: name = remove_ext(data['name']) @@ -70,12 +70,7 @@ def delete(name): @blueprint.route("/wiki/_create/", defaults={'name': None}, methods=['GET', 'POST']) @blueprint.route("/wiki/_create/", methods=['GET', 'POST']) def create(name): - cname = "" - if name: - cname = to_canonical(name) - if g.current_wiki.get_page(cname): - # Page exists, edit instead - return redirect(url_for('wiki.edit', name=cname)) + if request.method == 'POST': g.current_wiki.write_page(request.form['name'], @@ -83,8 +78,12 @@ def create(name): message=request.form['message'], create=True, username=g.current_user.get('username')) - return redirect(url_for('wiki.page', name=cname)) else: + cname = to_canonical(name) if name else "" + if cname and g.current_wiki.get_page(cname): + # Page exists, edit instead + return redirect(url_for('wiki.edit', name=cname)) + return render_template('wiki/edit.html', name=cname, content="")