Beispiel #1
0
def delete():
    # TODO token与用户验证
    topic_id = int(request.args.get('id'))
    tp = Topic.find(topic_id)
    print('删除 的 topic 是', tp)
    t = Theme.find(tp.theme_id)
    t.topic_num -= 1
    t.save()
    delete_file(local_image_director, tp.banner_img)
    tp.delete()
    return redirect(url_for('theme.detail'))
Beispiel #2
0
def delete():
    id = int(request.args.get('id'))
    token = request.args.get('token')
    u = current_user()
    t = get_token(u.id)
    if t.content == token:
        flash_token(t)
        b = Theme.find(id)
        log('删除 theme 用户是', u, b)
        delete_file(local_image_director, b.banner_img)
        Theme.delete(id)
        return redirect(url_for('board.edit'))
    else:
        abort(403)
Beispiel #3
0
def detail(id_page):
    topic_num = 5
    (id, page) = check_idpage(id_page)
    (startn, endn) = ((page - 1) * topic_num, page * topic_num)
    m = Theme.find(id)
    pages = math.ceil(m.topic_num / topic_num)
    if m.topic_num < startn or startn < 0:
        abort(404)
    elif startn < m.topic_num < endn:
        tps = Topic.find_all(theme_id=m.id)[startn:]
        # tps = Topic.cache_all()
    else:
        tps = Topic.find_all(theme_id=m.id)[startn:endn]
    return render_template("theme/detail.html", theme=m, tps=tps, pgs=pages)
Beispiel #4
0
def update():
    token = request.args.get('token')
    form = request.form
    id = int(form.get('id', -1))
    name = form.get('name', '')
    u = current_user()
    t = get_token(u.id)
    if t.content == token and '' != name:
        flash_token(t)
        b = Theme.find(id)
        log('update board 用户是', u.id, u.username, b)
        b.name = name
        b.save()
        return redirect(url_for('board.edit'))
    else:
        abort(403)
Beispiel #5
0
def add():
    u = current_user()
    user_info = {
        'user_id': u.id,
        'user_name': u.username,
    }

    if file_exists():
        print('file=', request.files)
        return redirect(url_for('topic.new', tip='no name/theme img'))

    filename = allow_save(local_image_director)
    if filename is not None:
        form = request.form
        m = Topic.new(form, **user_info)
        m.banner_img = filename
        m.content = form.get('content', '')
        m.save()
        t = Theme.find(m.theme_id)
        t.topic_num += 1
        t.save()
    return redirect(url_for('theme.index'))