コード例 #1
0
def close_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)

    post.status = statusEnum.CLOSED
    db.session.commit()
    flash('Your post is closed!', 'success')

    # create notification for all users who have commented on this post
    notification_message = "A post you commented on has now been closed."
    notify_commenters(post_id, current_user.id, notification_message,
                      notificationTypeEnum.STATUS_CLOSED)
    db.session.commit()

    return redirect(url_for('post', post_id=post.id))
コード例 #2
0
def open_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)

    post.status = statusEnum.OPEN
    db.session.commit()
    flash('Your post is now open!', 'success')

    # create notification for all users who have commented (not volunteered, because that case is not possible)
    notification_message = "A post you commented on has now been re-opened."
    notify_commenters(post_id, current_user.id, notification_message,
                      notificationTypeEnum.STATUS_OPEN)
    db.session.commit()

    return redirect(url_for('post', post_id=post.id))
コード例 #3
0
def unvolunteer(post_id):
    post = Post.query.get_or_404(post_id)
    # This check is precautionary, we are already checking user in post.html.
    if post.volunteer != current_user.id:
        flash('You never volunteered for this post!', 'danger')
    else:
        post.volunteer = 0
        post.status = statusEnum.OPEN
        db.session.commit()
        flash('You are no longer volunteering for the post!', 'success')

        # create notification for post owner, and all users who have commented on this post
        notification_message = "{} has un-volunteered for your post.".format(
            current_user.username)
        notify_post_owner(post_id, current_user.id, notification_message,
                          notificationTypeEnum.UN_VOLUNTEER)

        notification_message = "A post you commented on has lost its volunteer."
        notify_commenters(post_id, current_user.id, notification_message,
                          notificationTypeEnum.UN_VOLUNTEER)

    db.session.commit()
    return redirect(url_for('post', post_id=post.id))
コード例 #4
0
def create_new_comment(post_id):
    post = Post.query.get_or_404(post_id)
    comments = db.session.query(PostComment).filter_by(post_id=post_id)
    form = PostCommentForm()

    if request.method == 'POST':
        if form.validate_on_submit():
            created_comment = PostComment(comment_desc=form.comment_desc.data,
                                          cmt_author=current_user,
                                          post_id=post_id)
            db.session.add(created_comment)
            db.session.commit()
            flash('Comment added!', 'success')

            # create notification for post owner + all users who have commented or volunteered for this post
            notification_message = "{} commented on your post.".format(
                current_user.username)
            notify_post_owner(post_id, current_user.id, notification_message,
                              notificationTypeEnum.COMMENT)

            notification_message = "{} commented on a post that you volunteered for.".format(
                current_user.username)
            notify_volunteer(post_id, current_user.id, notification_message,
                             notificationTypeEnum.COM_VOLUNTEER)

            notification_message = "{} commented on a post that you also commented on.".format(
                current_user.username)
            notify_commenters(post_id, current_user.id, notification_message,
                              notificationTypeEnum.COMMENT)

            return redirect(url_for('post', post_id=post.id))

    return render_template('post.html',
                           post=post,
                           comments=comments,
                           form=form)
コード例 #5
0
def volunteer(post_id):
    post = Post.query.get_or_404(post_id)
    # This check is precautionary, we are already checking user in post.html.
    if post.author == current_user:
        flash("You can't volunteer for your own post!", 'warning')
    elif post.status != statusEnum.OPEN:
        flash('Post status must be OPEN to volunteer!', 'warning')
    else:
        post.volunteer = current_user.id
        post.status = statusEnum.TAKEN
        db.session.commit()
        flash('You are now volunteering for the post!', 'success')

        # create notification for post owner, and all users who have commented on this post
        notification_message = "{} volunteered for your post.".format(
            current_user.username)
        notify_post_owner(post_id, current_user.id, notification_message,
                          notificationTypeEnum.VOLUNTEER)

        notification_message = "A post you commented on is now taken by another volunteer."
        notify_commenters(post_id, current_user.id, notification_message,
                          notificationTypeEnum.VOLUNTEER)

    return redirect(url_for('post', post_id=post.id))