Exemplo n.º 1
0
def article_detail(id):
    article = Article.query.options(joinedload('replies')).get(id)
    if request.method == 'POST':
        if 'id' not in session:
            return redirect(url_for('.login'))
        reply = Reply()
        reply.user_id = session.get('id')
        reply.article = article
        reply.content = request.form['content']
        db_session.commit()
    return render_template('detail.html', article=article)
Exemplo n.º 2
0
def article_detail(id):
    article = Article.query.options(joinedload('replies')).get(id)
    if request.method == 'POST' and session.get('id'):
        content = request.form.get('content')
        reply = Reply()
        reply.user_id = session.get('id')
        reply.article = article
        reply.content = content
        db_session.commit()
        return redirect(url_for('.article_detail', id=id))
    return render_template('article_detail.html', article=article)
Exemplo n.º 3
0
def reply_again(id):
    if 'id' not in session:
        return json.dumps(dict(error='请先登陆'))
    reply = Reply()
    reply.user_id = session.get('id')
    reply.reply_again_id = id
    reply.content = request.form.get('content')
    db_session.add(reply)
    db_session.commit()

    macro = get_template_attribute('repeat_reply.html', 'repeat_reply')
    return json.dumps(dict(id=reply.id, content=macro(reply)))
Exemplo n.º 4
0
def reply_again(id):
    if not session.get("id"):
        return json.dumps(dict(error="请先登陆"))

    reply = Reply()
    reply.user_id = session.get("id")
    reply.reply_id = id
    reply.content = request.form.get("content")

    db_session.add(reply)
    db_session.commit()

    macro = get_template_attribute("reply_again.html", "repeat_reply")

    return json.dumps(dict(id=reply.id, content=macro(reply)))
Exemplo n.º 5
0
def detail(id):
    article = Article.query.options(joinedload("replies")).get(id)
    if request.method == "POST":
        if not session.get("id"):
            flash("请先登陆")
        elif not request.form.get("content"):
            flash("请输入评论信息")
        else:
            reply = Reply()
            reply.article = article
            reply.user_id = session.get("id")
            reply.content = request.form.get("content")
            db_session.commit()
            return redirect(url_for(".detail", id=id))
    return render_template("article_detail.html", article=article)
Exemplo n.º 6
0
def article_detail(id):
    article = Article.query.options(joinedload(Article.replies).joinedload(Reply.user)).get(id)
    if request.method == 'POST':
        if not session.get('id'):
            return redirect(url_for('.login'))
        content = request.form.get('content')
        if not content:
            flash('请填写内容')
        else:
            reply = Reply()
            reply.content = content
            reply.article = article
            reply.user_id = session.get('id')

            db_session.commit()
            return redirect(url_for('.article_detail', id=id))
    return render_template('article_detail.html', article=article)
Exemplo n.º 7
0
def add_reply(topicid,u):
    try:
        content = request.get_json()['content']
    except:
        make_response("no reply content", 400)
    try:
        topic = TopicModel.objects(id=topicid)[0]
    except:
        return make_response("no such topic", 400)

    #解析content
    pattern = re.compile(r'@\w+')
    usernames = [] + re.findall(pattern, content)
    print usernames
    receivers = set([topic.author])
    for name in usernames:
        try:
            receivers.add(UserModel.objects(username=name[1:])[0])
        except:
            pass  #@了一个没有的人
    reply = Reply()
    reply.sender = u
    reply.topic = topic
    reply.receivers = list(receivers)
    reply.content = content
    reply.save()
    topic.updateLastEditedTime()
    topic.save()
    for receiver in receivers:
        receiver.unreadReplies_count += 1
        receiver.save()

    return make_response("update complete", 200)
Exemplo n.º 8
0
def reply_again(id):
    user_id = session.get('id')
    content = request.form.get('content')
    if not user_id:
        return json.dumps(dict(error='请先登陆!'))
    if not content:
        return json.dumps(dict(error='请输入评论信息!'))
    reply = Reply()
    reply.user_id = user_id
    reply.content = content
    reply.reply_id = id

    db_session.add(reply)
    db_session.commit()
    
    macro_func = get_template_attribute('reply_recursion.html', 'reply_again')

    return json.dumps(dict(id=reply.id, content=macro_func(reply)))
Exemplo n.º 9
0
def reply_again():
    if not session.get('id'):
        return jsonify(error='请先登陆!')

    content = request.form.get('content')
    if not content:
        return jsonify(error='请填写内容')

    reply = Reply()
    reply.content = content
    reply.user_id = session.get('id')
    reply.reply_parent_id = request.form.get('id')

    db_session.add(reply)
    db_session.commit()

    macro = get_template_attribute('recurse.html', 'recurse_reply')

    return jsonify(content=macro(reply))
Exemplo n.º 10
0
def reply_again(id):
    if not session.get('id'):
        return jsonify(error='请先登陆!')

    content = request.form.get('content')
    if not content:
        return jsonify(error='请输入完整信息!')

    reply = Reply()
    reply.user_id = session.get('id')
    reply.reply_id = id
    reply.content = content

    db_session.add(reply)
    db_session.commit()

    macro = get_template_attribute('replyAgain.html', 'replyAgain')

    return jsonify(id=reply.id, html=macro(reply))
Exemplo n.º 11
0
def reply_again():
    if not session.get('id'):
        return jsonify(error='请先登陆')

    form = request.form

    if not form['content']:
        return jsonify(error='请填写信息')

    reply = Reply()
    reply.user_id = session.get('id')
    reply.content = form['content']
    reply.reply_id = form['id']

    db_session.add(reply)
    db_session.commit()

    macro = get_template_attribute('recurse.html', 'recurse')

    return jsonify(content=macro(reply))
Exemplo n.º 12
0
def detail(id):
    article = Article.query.options(joinedload('replies')).get(id)

    if request.method == 'POST':
        if not session.get('id'):
            flash('请先登陆!')
        else:
            content = request.form.get('content')
            if not content:
                flash('请输入完整信息!')
            else:
                reply = Reply()
                reply.user_id = session.get('id')
                reply.article = article
                reply.content = content

                db_session.commit()

                return redirect(url_for('.detail', id=id))
    return render_template('article_detail.html', article=article)