예제 #1
0
파일: views.py 프로젝트: zhaiwei/project
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)
예제 #2
0
파일: views.py 프로젝트: zhaiwei/project
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)
예제 #3
0
파일: views.py 프로젝트: zhaiwei/project
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)))
예제 #4
0
파일: views.py 프로젝트: zhaiwei/project
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)))
예제 #5
0
파일: views.py 프로젝트: zhaiwei/project
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)
예제 #6
0
파일: views.py 프로젝트: zhaiwei/project
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)
예제 #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)
예제 #8
0
파일: views.py 프로젝트: zhaiwei/project
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)))
예제 #9
0
파일: views.py 프로젝트: zhaiwei/project
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))
예제 #10
0
파일: views.py 프로젝트: zhaiwei/project
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))
예제 #11
0
파일: views.py 프로젝트: zhaiwei/project
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))
예제 #12
0
파일: views.py 프로젝트: zhaiwei/project
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)