예제 #1
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))
예제 #2
0
def like(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.like_post(post)
    db.session.commit()
    return redirect(url_for('main.post', post_id=post.id))
예제 #3
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)
예제 #4
0
def like_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.like_post(post)
    flash("You have liked this post")
    return redirect(url_for('.post', id=id))
예제 #5
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'))
예제 #6
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'))
예제 #7
0
def like_post(id):
    post = Post.query.get_or_404(id)
    if current_user.is_liking_post(post):
        flash('You already like this post')
        return redirect(url_for('.post', id=post.id, page=1))
    current_user.like_post(post)
    flash("You now like %s" % post.title)
    return redirect(url_for('.post', id=post.id))
예제 #8
0
def like_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.like_post(post)
    db.session.commit()
    return redirect(request.referrer)
예제 #9
0
def like():
    if request.method == "POST":
        post_id = request.form['post_id']
        post = Post.query.filter_by(id=post_id).first_or_404()
        current_user.like_post(post)
        likes = post.likes.count()
        unlikes = post.unlikes.count()
        db.session.commit()
    return jsonify({'likes': likes, 'unlikes': unlikes})
예제 #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):
    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)
예제 #13
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)
예제 #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_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)
예제 #17
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)
예제 #18
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)
예제 #19
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)
예제 #20
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)
예제 #21
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))
예제 #22
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)
예제 #23
0
def like_action(post_id, action):
    post = Post.query.get_or_404(post_id)
    if action == 'like':
        current_user.like_post(post)
        current_user.undislike_post(post)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_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_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)
예제 #26
0
def like_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.like_post(post)
        db.session.commit()
        flash('Post added to liked posts')
    return redirect(url_for('main.post_info', post_id=post_id))
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))
예제 #28
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)
예제 #29
0
파일: app.py 프로젝트: MadRealm/projet_web
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)
예제 #30
0
def like_action(id, action):
    post = Post.query.filter_by(id=id).first_or_404()
    if action == 'like':
        current_user.like_post(post)
        current_user.add_notification(
            current_user.username + ' just liked your post',
            current_user.has_liked_post(post))
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_post(post)
        db.session.commit()
    return redirect(request.referrer)