示例#1
0
文件: wikiton.py 项目: lzedl/wikiton
def main(init_db=False, insert_defaults=False, debug=False):
    if init_db:
        db.connect()
        db.create_tables([Page, PageHistory, Option])
    if insert_defaults:
        Option.set_value('default_lang', 'ru')
        Option.set_value('main_page', 'main')
        Page.create(lang='ru', title='default_main', path='main',
                    content='Welcome to Wikitone')

    app.run(debug=debug)
示例#2
0
文件: wikiton.py 项目: lzedl/wikiton
def move_page(lang, path):
    try:
        page = Page.get(lang=lang, path=path)

        if request.method == 'GET':
            return render_template('move.html', page=page)
        else:  # POST
            page.path = request.form['path']
            page.save()
            return redirect(url_for('show_page', lang=lang, path=page.path))
    except DoesNotExist:
        abort(404)
示例#3
0
文件: wikiton.py 项目: lzedl/wikiton
def show_page(lang, path=''):
    if len(lang) != 2 and lang not in ('ru', 'en'):
        path = lang + '/' + path
        lang = Option.get('default_lang', 'en')
        return redirect(url_for('show_path', lang=lang, path=path))

    try:
        page = Page.get(Page.path == path, Page.lang == lang)

        return render_template('page.html', page=page, title=page.title,
                               content=page.content_html)
    except DoesNotExist as e:
        app.logger.debug('Page "%s" does not exist. %s', path, e.message)
        return redirect(url_for('edit_page', lang=lang, path=path))
示例#4
0
文件: wikiton.py 项目: lzedl/wikiton
def edit_page(lang, path):
    try:
        page = Page.get(path=path, lang=lang)
    except DoesNotExist:
        page = None

    if request.method == 'GET':
        if not page:
            page = Page(title=basename(path), path=path, lang=lang, content='')
        return render_template('edit.html',
                               title='Edit page "%s"' % page.title,
                               page=page)
    elif request.method == 'POST':
        page, _ = Page.get_or_create(lang=lang, path=path)
        page.content = request.form['content']
        page.title = request.form['title']
        page.save()
        PageHistory.create_from_page(page)
        return redirect(url_for('show_page', lang=lang, path=path))
示例#5
0
文件: wikiton.py 项目: lzedl/wikiton
def delete_page(lang, path):
    Page.delete().where(lang=lang, path=path).execute()
    return redirect(url_for('home'))