Example #1
0
def topic(postid):
    allUsers = User.query.all()
    myPost = Post.query.get(postid)

    if myPost is None:
        return render_template('404.html'), 404

    rForm = ReplyForm()
    #    bcForm = BlessCurseForm()

    if rForm.rSubmit.data and rForm.validate():
        reply = Reply(post_id=postid,
                      text=rForm.text.data,
                      stance=('True' == rForm.stance.data),
                      user_id=current_user.id)
        db.session.add(reply)
        db.session.commit()
        myReply = Post.query.get(postid).p_replies.all()
        return render_template('topicpage.html',
                               title='Topic',
                               post=myPost,
                               replies=myReply,
                               form=rForm,
                               user=allUsers)


#    if bcForm.bcSubmit.data and bcForm.validate():
#        blessed = ('bless' == bcForm.choice.data)
#        thePost = myPost
#        post_bc_query = thePost.user_votes.filter_by(user_id=current_user.id).first()
#        if  post_bc_query == None:
#            post_bc = Post_BC(post_id=thePost.id, user_id=current_user.id, stance=blessed)
#            if blessed == True:
#                thePost.blesses = thePost.blesses + 1
#            else:
#                thePost.curses = thePost.curses + 1
#            db.session.add(post_bc)
#            db.session.commit()
#        elif post_bc_query.stance != blessed:
#            if blessed == True:
#                thePost.blesses +=  1
#                thePost.curses -=  1
#            else:
#                thePost.curses +=  1
#                thePost.blesses -=  1
#            post_bc_query.stance = blessed
#            db.session.commit()
#
#        myReply = myPost.p_replies.all()
#        return render_template('topicpage.html', title='Topic', post=myPost,
#                               replies=myReply, form=rForm, bcForm=bcForm, user=allUsers)

    myReply = myPost.p_replies.all()
    return render_template('topicpage.html',
                           title='Topic',
                           post=myPost,
                           replies=myReply,
                           form=rForm,
                           user=allUsers)
Example #2
0
File: topic.py Project: yira97/dipu
def detail(index):
    u = current_user()
    t = Topic.objects(id=ObjectId(index)).first()
    ts = Topic.objects(belong=t.id)
    form = ReplyForm()
    if form.validate_on_submit():
        Topic.make_reply(t, content=form.content.data, username=u.username)
        return redirect(url_for('topic.detail', index=index))
    return render_template('detail.html',
                           topic=t,
                           user=u,
                           form=form,
                           r_topics=ts)
Example #3
0
def post_page(pid):
    form = ReplyForm()
    if form.validate_on_submit():
        body = form.reply.data
        reply = Reply(body=body, pid=pid, user_id=current_user.id)
        db.session.add(reply)
        db.session.commit()
        redirect(url_for('post_page', pid=pid))
    post = Post.query.filter_by(id=pid).first_or_404()
    replys = Reply.query.filter_by(pid=pid)
    return render_template("post.html",
                           title=post.title,
                           post=post,
                           replys=replys,
                           form=form)
Example #4
0
def replyblog():
    form = ReplyForm()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            # 获取当前登录用户对象
            user = current_user._get_current_object()
            # 创建对象
            p = Posts(content=form.content.data, user=user)
            # 保存到数据库
            db.session.add(p)
            flash('发表成功')
            return redirect(url_for('main.index'))
        else:
            flash('请登录后再发表')
            return redirect(url_for('user.login'))
        flash('回复成功')
    return render_template('main/replyblog.html', form=form)
Example #5
0
def reply(book_title, title):
    post = Post.query.filter_by(title=title).first()
    book = Forum.query.filter_by(book_title=book_title).first()
    form = ReplyForm()
    if form.validate_on_submit():
        reply = Reply(userID=current_user.id, postID=post.id, content=form.content.data)
        db.session.add(reply)
        db.session.commit()

        #p2r = PostToReply(postID=post.id, replyID=reply.id)
        #db.session.add(p2r)
        #db.session.commit()

        flash('Reply posted')
        final_form = ReplyForm()
        render_template('reply.html', title='Reply', book=book, post=post, form=final_form)
        #session['book'] = Forum.query.filter_by(book_title=book_title).first()
        return redirect(url_for('forum', book_title=book_title))
    return render_template('reply.html',title='Reply', book=book, post=post, form=form)
Example #6
0
def detail(id):
    form = ReplyForm()
    page = request.args.get('page', 1, type=int)
    post = Post.query.get(id)
    allpost = Post.query.filter_by(rid=id).order_by(Post.timestamp.desc())
    pagination = allpost.paginate(page, per_page=3, error_out=False)
    posts = pagination.items
    if current_user.is_authenticated:
        if form.validate_on_submit():
            user = current_user._get_current_object()
            p = Post(content=form.content.data, rid=id, user=user)
            db.session.add(p)
            flash('帖子回复成功')
            return redirect(url_for('post.detail', id=id))
        return render_template('post/detail.html',
                               pagination=pagination,
                               post=post,
                               id=id,
                               form=form,
                               posts=posts)
    else:
        flash('登陆后才能回复帖子')
        return redirect(url_for('user.login'))
Example #7
0
def post(id):

    post = Post.query.filter_by(id=id).first()
    post.increment_views()
    db.session.commit()
    likeForm = LikeForm()
    commentForm = CommentForm()
    replyForm = ReplyForm()
    if commentForm.validate_on_submit():
        comment = Comment(body=commentForm.comment.data,
                          post=post,
                          author=current_user)
        post.decrement_views()
        db.session.add(comment)
        post.increment_comments_counter()
        db.session.commit()
        flash('Your comment is now live!')
        commentForm.comment.data = ''
        return render_template("post.html",
                               title='Post',
                               post=post,
                               likeForm=likeForm,
                               commentForm=commentForm,
                               replyForm=replyForm,
                               scrollToAnchor=comment.id)
    elif replyForm.validate_on_submit():
        comment = Comment.query.filter_by(id=replyForm.commentId.data).first()
        reply = Reply(body=replyForm.reply.data,
                      comment=comment,
                      author=current_user,
                      post=post)
        post.decrement_views()
        db.session.add(reply)
        post.increment_comments_counter()
        db.session.commit()
        flash('Your reply is now live!')
        replyForm.reply.data = ''
        return render_template("post.html",
                               title='Post',
                               post=post,
                               likeForm=likeForm,
                               commentForm=commentForm,
                               replyForm=replyForm,
                               scrollToAnchor=reply.id)
    elif likeForm.validate_on_submit():
        liked = post.liked_by.filter_by(user_id=current_user.id).first()
        if not liked:
            like = Like(author=current_user, post=post)
            post.increment_likes()
            post.decrement_views()
            db.session.commit()
            likeForm.like.data = ''
            flash('Your like is now live!')
        else:
            post.liked_by.remove(liked)
            post.decrement_likes()
            post.decrement_views()
            db.session.commit()
            likeForm.like.data = ''
            flash('Your unlike is now live!')
            print(post.liked_by.filter_by(user_id=current_user.id).first())
        return render_template("post.html",
                               title='Post',
                               post=post,
                               likeForm=likeForm,
                               commentForm=commentForm,
                               replyForm=replyForm,
                               scrollToAnchor='likePost')
    return render_template("post.html",
                           title='Post',
                           post=post,
                           likeForm=likeForm,
                           commentForm=commentForm,
                           replyForm=replyForm)