def edit(page_path=None): '''Edit a wiki page.''' # It should be possible to create a new page from the edit link. if page_path is None: return redirect(url_for('create')) try: validate_page_path(page_path) page = WikiPage(page_path) # Proceed if the wiki exists. if page.exists: return render_wiki_editor(page) else: # Get the user going with this new page. return redirect(url_for('create', page_path=page_path)) except ValidationError as verror: # The user tried to create a page straight from the URL, but the path # isn't correct. Give them the page path again in case they fat # fingered something. flash(verror.message) return redirect(url_for('create', page_path=page_path))
def make_wiki(): '''Make the wiki page.''' page_path = request.form['page_path'] content = request.form['wiki_content'] try: validate_page_path(page_path) page = WikiPage(page_path) # Proceed if the wiki does not exist. if not page.exists: if not page.store(content): # Storing would fail if something unrecoverable happened. abort(500) app.search_engine.add_wiki(page_path, content) return redirect(url_for('wiki', page_path=page_path)) else: flash('That wiki name already exists. Please choose another.') return create(page_path, request.form['wiki_content']) except ValidationError as verror: flash(verror.message) return create(page_path, request.form['wiki_content'])
def delete(page_path): '''Delete the wiki page.''' if page_path == 'Home': flash('You sneaky devil. You can\'t delete the main page. ' 'But feel free to edit it.') return redirect(url_for('index')) try: validate_page_path(page_path) page = WikiPage(page_path) if page.exists: if not page.delete(): # Unsuccessful delete. abort(500) app.search_engine.delete_wiki(page_path) else: flash('That wiki doesn\'t exist.') except ValidationError as verror: # The user tried to delete a bogus page straight from the URL. flash(verror.message) return redirect(url_for('index'))