示例#1
0
def post_action(post_id, action):
    """ Post actions.

    :param post_id: ID of the post to take action upon
    :param action: Action to take on post
    """
    referrer = request.referrer
    post = Post.query.filter_by(id=post_id).first_or_404()
    # Delete post.
    if action == 'delete':
        if current_user == post.author or current_user.id == post.recipient_id:
            referrer = url_for('users.profile', username=current_user.username)
            post.delete()
            NotificationHelper(post=post).delete_post()
            post.commit()
            flash('Post was deleted.')
    # Like post.
    if action == 'like':
        current_user.like_post(post)
        NotificationHelper(notified=post.author,
                           notifier=current_user,
                           post=post).post_like()
        current_user.commit()
    # Unlike post.
    if action == 'unlike':
        current_user.unlike_post(post)
        NotificationHelper(notifier=current_user, post=post).delete_post_like()
        current_user.commit()
    return redirect(referrer)
示例#2
0
def unlike(post_id):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if post is None:
        return redirect(url_for('main.index'))
    current_user.unlike_post(post)
    db.session.commit()
    return redirect(url_for('main.post', post_id=post.id))
示例#3
0
def like_action_comment(post_id, comment_id, action):
    ''' Adds or removes a like/dislike to or from a comment '''

    post = Posts.query.get_or_404(post_id)
    comment = Comment.query.get_or_404(comment_id)

    if action == 'like':
        if current_user.has_disliked_comment:
            current_user.undislike_post(post=None, comment=comment)
        current_user.like_post(post=None, comment=comment)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post=None, comment=comment)
        db.session.commit()

    if action == 'dislike':
        if current_user.has_liked_comment:
            current_user.unlike_post(post=None, comment=comment)
        current_user.dislike_post(post=None, comment=comment)
        db.session.commit()
    if action == 'undislike':
        current_user.undislike_post(post=None, comment=comment)
        db.session.commit()

    return redirect(
        url_for('boards.selected_comment',
                topic_address=post.topic,
                post_id=post_id,
                comment_id=comment_id))
示例#4
0
def unlike_post(id):
    post = Post.query.filter_by(id=id).first()
    if post is None:
        flash('This post is invalid or has been deleted by the user')
        return redirect(url_for('.home'))
    current_user.unlike_post(post)
    flash("You have unliked this post")
    return redirect(url_for('.post', id=id))
示例#5
0
def like_action(post_id, action):
    if action == 'like':
        current_user.like_post(post_id)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post_id)
        db.session.commit()
    return redirect(url_for('main.home'))
示例#6
0
def unlike_post(post_id):
    post = Post.filter(id=post_id).first()
    if not post:
        flash(_("Post %(post_id)s not found", post=post), "danger")
        return redirect(url_for("main.index"))
    current_user.unlike_post(post)
    db.session.commit()
    return redirect(request.referrer)
示例#7
0
def unlike_post(id):
    post = Post.query.get_or_404(id)
    if not current_user.is_liking_post(post):
        flash("You are not liking this post.")
        return redirect(url_for('.post', id=post.id, page=1))
    current_user.unlike_post(post)
    flash("You now unlike %s" % post.title)
    return redirect(url_for('.post', id=post.id))
示例#8
0
def like_action(post_id, action):
    post = Posts.query.filter_by(sno=post_id).first()
    if action == 'like':
        current_user.like_post(post)
    else:
        current_user.unlike_post(post)
        db.session.commit()
    return redirect(url_for('index'))
示例#9
0
def unlike():
    if request.method == "POST":
        post_id = request.form['post_id']
        post = Post.query.filter_by(id=post_id).first_or_404()
        current_user.unlike_post(post)
        unlikes = post.unlikes.count()
        likes = post.likes.count()
        db.session.commit()
    return jsonify({'unlikes': unlikes, 'likes': likes})
示例#10
0
def like_action(post_id, action):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if action == 'like':
        current_user.like_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return render_template('leaderboard.html')
示例#11
0
def post_vote(post_id, action_vote):
    post = get_post(post_id)
    if action_vote == 'like':
        current_user.like_post(post)
        db.session.commit()
    if action_vote == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return redirect(url_for('profile'))
示例#12
0
def like_action(post_id, action):
    print(post_id)
    if action == 'like':
        current_user.like_post(post_id)

    if action == 'unlike':
        current_user.unlike_post(post_id)

    return redirect(request.referrer)
示例#13
0
def like_action(post_id, action):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if action == 'like':
        current_user.like_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return redirect(request.referrer)
示例#14
0
def like_action(post_id, action):
	post = Post.query.get_or_404(post_id)
	if action == 'like':
		current_user.like_post(post)
		db.session.commit()
	elif action == 'unlike':
		current_user.unlike_post(post)
		db.session.commit()
	return redirect(url_for('posts.post', post_id=post_id))
示例#15
0
def like_action(post_id, action):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if request.method == 'POST':
        if action == 'like':
            if current_user.has_disliked_post(post):
                current_user.undislike_post(post)
                db.session.commit()

            if current_user.has_liked_post(post):
                current_user.unlike_post(post)
                db.session.commit()

            else:
                print('like')
                current_user.like_post(post)
                db.session.commit()

            return succesful_response({'message': 'Great Success!'})

        if action == 'dislike':
            if current_user.has_liked_post(post):
                current_user.unlike_post(post)
                db.session.commit()

            if current_user.has_disliked_post(post):
                current_user.undislike_post(post)
                db.session.commit()

            else:
                current_user.dislike_post(post)
                db.session.commit()

            return succesful_response({'message': 'Great Success!'})

    if request.method == 'GET':
        if current_user.has_liked_post(post):
            liked = True
            disliked = False
        elif current_user.has_disliked_post(post):
            liked = False
            disliked = True
        else:
            liked = False
            disliked = False

        data = {
            'likes': post.likes.count(),
            'dislikes': post.dislikes.count(),
            'liked': liked,
            'disliked': disliked
        }
        return data


# @app.route('/profile/<', methods=['GET', 'POST'])
# @login_required
# def like_action(post_id, action):
示例#16
0
def like(post_id, action):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if action == 'like':
        current_user.like_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return redirect('like',pitch = my_pitch, comment_form = comment_form, comments = all_comments, title = title, like = like)
示例#17
0
def like_action(post_id, action):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if action == 'apply':
        current_user.like_post(post)
        db.session.commit()
    if action == 'cancel':
        current_user.unlike_post(post)
        db.session.commit()
    return render_template('post_v2.html', title=post.title, post=post)
示例#18
0
def promolike_action(promotion_id, action):
    promolikes = Promotion.query.filter_by(id=promotion_id).first_or_404()
    if action == 'like':
        current_user.like_post(promolikes)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(promolikes)
        db.session.commit()
    return redirect(request.referrer)
示例#19
0
def interviewlike_action(interview_id, action):
    interviewlikes = Interview.query.filter_by(id=interview_id).first_or_404()
    if action == 'like':
        current_user.like_post(interviewlikes)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(interviewlikes)
        db.session.commit()
    return redirect(request.referrer)
示例#20
0
def pickuplike_action(pickuplines_id, action):
    pickupikes = PickupLines.query.filter_by(id=pickuplines_id).first_or_404()
    if action == 'like':
        current_user.like_post(pickupikes)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(pickupikes)
        db.session.commit()
    return redirect(request.referrer)
示例#21
0
def like(id, action):
    post = get_post(id)
    if action == 'like':
        current_user.like_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return redirect(request.referrer)
示例#22
0
def postlike_action(post_id, action):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if action == 'like':
        current_user.like_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return redirect(url_for('posts.postn', post_id=post.id, page=-1))
示例#23
0
def dislike_action(post_id, action):
    post = Post.query.get_or_404(post_id)
    if action == 'dislike':
        current_user.dislike_post(post)
        current_user.unlike_post(post)
        db.session.commit()
    if action == 'undislike':
        current_user.undislike_post(post)
        db.session.commit()
    return redirect(request.referrer)
示例#24
0
def handle_my_custom_event( json ):
    post = Post.query.filter_by(id=json.get('post_id')).first_or_404()
    if json.get('action') == 'like':
        current_user.like_post(post)
        db.session.commit()
    if json.get('action') == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    print( 'recived my event:' + str( json.get('post_id')) )
    socketio.emit( 'my response', json, callback=messageRecived )
示例#25
0
def like_action(post_id, action):
    post = Post.query.get_or_404(post_id)
    if action == 'like':
        current_user.like_post(post)
        post.likes += 1
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        post.likes -= 1
        db.session.commit()
    return redirect(request.referrer)
def like_action(post_id, action):
    post = Post.query.filter_by(id=post_id).first_or_404()
    if action == 'like':
        current_user.like_post(post)
        db.session.commit()
        flash('You liked the post!', 'alert alert-primary')
    elif action == 'dislike':
        current_user.unlike_post(post)
        db.session.commit()
        flash('You disliked the post!', 'alert alert-warning')
    return redirect(url_for("posts.post", post_id=post_id))
示例#27
0
def handle_vote(ballot, action):
    post = Post.query.filter_by(id=ballot).first_or_404()
    if action == 'like':
        current_user.like_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    p = Post.query.filter_by(id=ballot).first()
    result1 = p.likes.count()
    emit("vote_results", {'results1': result1}, broadcast=True)
示例#28
0
def like_post():
    id = request.args.get('id')
    post = Post.query.filter_by(id=id).first()
    result = {'like': True}
    if current_user.has_liked_post(post):
        current_user.unlike_post(post)
        result = {'like': False}
        return jsonify(result)
    else:
        current_user.like_post(post)
        return jsonify(result)
示例#29
0
def unlike_post(post_id):
    form = EmptyForm()
    if form.validate_on_submit():
        post = Post.query.filter_by(id=post_id).first()
        if post is None:
            flash('Post {} not found.'.format(post))
            return redirect(url_for('main.index'))
        current_user.unlike_post(post)
        db.session.commit()
        flash('Post removed from liked posts')
    return redirect(url_for('main.post_info', post_id=post_id))
示例#30
0
def like_unlike(post_id=None, action=None):
    post = database.models.Post.query.filter_by(id=post_id).first()
    if action == 'like':
        postlike = database.models.Post.query.filter_by(
            user_id=current_user.id).all()
        print(current_user.has_liked_post(post))
        current_user.like_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return redirect(request.referrer)