예제 #1
0
파일: main.py 프로젝트: xkyh/szxkyhblog
def detail(postid):
    form = CommentsForm()
    if form.validate_on_submit():
        if not current_user.is_authenticated:
            flash('登录才能评论哦')
            return redirect(url_for('users.login'))
        else:
            user = current_user._get_current_object()
            post = Posts.query.get(postid)
            comment = Comments(content=form.content.data, user=user, post=post)
            db.session.add(comment)
            return redirect(url_for('main.detail', postid=postid))
    post = Posts.query.get(postid)
    # 阅读数+1
    post.views += 1
    db.session.add(post)
    # 最热 最新 博文
    Topposts = Posts.query.order_by(db.desc(Posts.views))[:5]
    Newposts = Posts.query.order_by(db.desc(Posts.timestamp))[:5]
    # 博文的评论
    comments = Comments.query.filter_by(post=post).order_by(
        db.desc(Comments.timestamp))
    return render_template('common/detail.html',
                           post=post,
                           Newposts=Newposts,
                           Topposts=Topposts,
                           form=form,
                           comments=comments)
예제 #2
0
def post(id):
    article = Articles.query.get_or_404(id)
    posts = Articles.query.order_by(Articles.date_posted.desc()).all()
    comments = article.userscomments
    form = CommentsForm()
    if form.validate_on_submit():
        comment = Comments(comment=form.comments.data,user_id=current_user.id,article_id=article.id)
        db.session.add(comment)
        db.session.commit()
        flash('Your have successfully added your comment!', 'success')
        return redirect(url_for('post',id = id))
    return render_template('post.html', title=article.title, article = article,form=form,posts=posts,comments=comments)
예제 #3
0
def film_info(film_name):
    post = Cinema.query.filter_by(name=film_name).first_or_404()
    form = CommentsForm()
    users = User
    user_comment = Comments.query.all()
    if form.validate_on_submit():
        add_comment = Comments(body=form.text.data, user_id=current_user.id)
        db.session.add(add_comment)
        db.session.commit()
    return render_template('film_info.html',
                           post=post,
                           form=form,
                           comments=user_comment,
                           user=users)
예제 #4
0
def submitComments():
    form = CommentsForm()
    print("Hello 1")
    if form.validate_on_submit():
        print("Hello 2")
        comment = Comment(
            name=form.name.data,
            comment=form.comment.data)  #commentID=form.commentID.data)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been posted!')
        print("Hello 3")
        return redirect(url_for('viewOtherComments'))
    print("Hello 4")
    return render_template('comments.html', title='Comments', form=form)
예제 #5
0
def updatecomment(commentid,articleid):
    article = Articles.query.get_or_404(str(articleid))
    comment = Comments.query.get_or_404(str(commentid))
    if comment.writer != current_user:
        abort(403)

    form = CommentsForm()
    if form.validate_on_submit():
        comment.comment = form.comments.data
        db.session.commit()
        flash('Your comment has been updated!', 'success')
        return redirect(url_for('post',id = article.id))
    elif request.method == 'GET':
        form.comments.data = comment.comment
    return render_template('post.html', title = 'Update comment', form = form,article=article)
def comments(p_id):
    form = CommentsForm()
    if form.validate_on_submit():
        preparedQuery = 'INSERT INTO Comments (p_id, u_id, comment, creation_time) VALUES(?, ?, ?, ?);'
        data = (p_id, current_user.id, form.comment.data, datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
        safe_query(preparedQuery, data)

    preparedQuery = 'SELECT * FROM Posts WHERE id=?;'
    post = safe_query(preparedQuery, (p_id,), one=True)

    preparedQuery = 'SELECT DISTINCT * FROM Comments AS c '\
    'JOIN Users AS u ON c.u_id=u.id '\
    'WHERE c.p_id=?'\
    'ORDER BY c.creation_time DESC;'
    all_comments = safe_query(preparedQuery, (p_id,))
    return render_template('comments.html', title='Comments', form=form, post=post, comments=all_comments)
예제 #7
0
def quadcopter(username):
    user = User.query.filter_by(username=username).first_or_404()
    form = CommentsForm()
    if form.validate_on_submit():
        post = Post(body=form.post.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your comment is now live')
        return redirect(url_for('quadcopter', username=user.username))
    page = request.args.get('page', 1, type=int)
    posts = Post.query.order_by(Post.timestamp.desc()).paginate(
        page, app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('quadcopter', username = user.username, page = posts.next_num) \
        if posts.has_next else None
    prev_url = url_for('quadcopter', username = user.username, page = posts.prev_num) \
        if posts.has_prev else None
    return render_template('quadcopter.html',
                           title='Quadcopter',
                           user=user,
                           form=form,
                           posts=posts.items,
                           next_url=next_url,
                           prev_url=prev_url)