示例#1
0
def list_threads():
    threads = get_user_threads(session['login'])
    if threads is None:
        return render_template('list.html', threads=None)
    else:
        with db_session:
            threads = Thread.select(lambda c: c.id in threads)[:]
            return render_template('list.html', threads=threads)
示例#2
0
def thread_page(t_id):
    if t_id not in get_user_threads(session['login']):
        return "This tread is blocked for you", 403

    with db_session:
        threads = Thread.select(lambda t: t.id == t_id)[:]
        if not threads:
            return "Thread not found", 404
        thread = threads[0]
        if request.method == 'POST':
            text = request.form.get('text')
            if not text:
                return "All fields are required"
            author = list(User.select(lambda u: u.id == session['id']))[0]
            app.logger.info("New message from %s: %s" % (author.login, text))
            Message(text=text, thread=thread, author=author)
        u_id = session['id']
        hash = calc_hash(t_id, u_id)
        return render_template('thread_page.html',
                               thread=thread,
                               u_id=u_id,
                               t_id=t_id,
                               hash=hash)