def append_links(): page_path = 'Links' page = WikiPage(page_path) if not page.append(request.args.get('link')): # Storing would fail if something unrecoverable happened. abort(500) app.search_engine.update_wiki(page_path, request.args.get('link')) return redirect(url_for('wiki', page_path=page_path))
def append_wiki(): '''Update a wiki page.''' # If the path changed, then this is now a new page. if request.form['original_page_path'] != request.form['page_path']: return make_wiki() else: # Because the path is the same as the original, then it must be valid # because it is a pre-existing page. page_path = request.form['page_path'] page = WikiPage(page_path) if not page.append(request.form['wiki_content']): # Storing would fail if something unrecoverable happened. abort(500) app.search_engine.update_wiki(page_path, request.form['wiki_content']) return redirect(url_for('wiki', page_path=page_path))
def revert(page_path, commit): '''Revert the wiki page as it was back in history.''' page = WikiPage(page_path) if page.exists: app.gitint.revert_file(page.rel_path, commit) return redirect(url_for('wiki', page_path=page_path)) else: flash('Sorry. That version doesn\'t exist.') return redirect(url_for('index'))
def history(page_path): '''Display history of a specific wiki page.''' page = WikiPage(page_path) if page.exists: changes = app.gitint.get_changes(page.rel_path) return render_template('history.html', page=page_path, changes=changes) else: flash('Sorry. That wiki doesn\'t exist.') return redirect(url_for('index'))
def update_wiki(): '''Update a wiki page.''' # If the path changed, then this is now a new page. if request.form['original_page_path'] != request.form['page_path']: return make_wiki() else: # Because the path is the same as the original, then it must be valid # because it is a pre-existing page. page_path = request.form['page_path'] page = WikiPage(page_path) if not page.store(request.form['wiki_content']): # Storing would fail if something unrecoverable happened. abort(500) app.search_engine.update_wiki(page_path, request.form['wiki_content']) return redirect(url_for('wiki', page_path=page_path))
def wiki(page_path='Home'): '''Render the wiki page or make a new one if the wiki doesn't exist.''' page = WikiPage(page_path) if page.exists: g.sections = page.sections return render_template('wiki.html', page_path=page_path, title=page.title, wiki=page.html, git=app.gitint) else: return create(page_path)
def view_history(page_path, commit): '''Render the wiki page as it was back in history.''' page = WikiPage(page_path) if page.exists: title = '%s - %s' % (page.title, commit) content = app.gitint.view_history(page.rel_path, commit) return render_template('view_history.html', content=content, title=title, page=page_path, commit=commit) else: flash('Sorry. That version doesn\'t exist.') return redirect(url_for('index'))
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'))
def test_gets_sections(self): '''Test getting sections out of paths.''' page_path = '/One/Two/Three' page = WikiPage(page_path) sections = page.sections self.assertEqual(len(sections), 2) self.assertEqual(sections[0].name, 'One') self.assertEqual(sections[0].path, 'One') self.assertEqual(sections[1].name, 'Two') self.assertEqual(sections[1].path, 'One/Two') section_path = '/Foo/Bar' section = WikiSection(section_path) sections = section.sections self.assertEqual(len(sections), 2) self.assertEqual(sections[0].name, 'Foo') self.assertEqual(sections[0].path, 'Foo') self.assertEqual(sections[1].name, 'Bar') self.assertEqual(sections[1].path, 'Foo/Bar')
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 cat(section_path=''): '''List the contents of a directory section.''' h = '' rpages = [] if is_valid_section(section_path): section = WikiSection(section_path) g.sections = section.sections for p in section.pages: #flash(p.path) #page = WikiPage(p.path) rpages.append(WikiPage(p.path)) #h+= "<div class=col-md-3>"+page.html+"</div>" return render_template('cat.html', section_path=section_path, sections=section.subsections, pages=section.pages, rpages=rpages) else: # This should only happen if a wiki link is created with a bad section # or if someone directly tries to attempt a bad URL. flash('Sorry. That wiki section doesn\'t exist.') return redirect(url_for('index'))