Ejemplo n.º 1
0
def upvote_post(request, post_slug):
    if request.method != "POST":
        raise Http404()

    post = get_object_or_404(Post, slug=post_slug)

    post_vote, is_vote_created = PostVote.upvote(
        user=request.me,
        post=post,
        request=request,
    )

    return {
        "post": {
            "upvotes": post.upvotes + (1 if is_vote_created else 0),
        },
        "upvoted_timestamp": int(post_vote.created_at.timestamp() * 1000)
    }
Ejemplo n.º 2
0
def retract_post_vote(request, post_slug):
    if request.method != "POST":
        raise Http404()

    post = get_object_or_404(Post, slug=post_slug)

    is_retracted = PostVote.retract_vote(
        request=request,
        user=request.me,
        post=post,
    )

    return {
        "success": is_retracted,
        "post": {
            "upvotes": post.upvotes - (1 if is_retracted else 0)
        }
    }
Ejemplo n.º 3
0
def upvote_post(update: Update, context: CallbackContext) -> None:
    user = get_club_user(update)
    if not user:
        return None

    post = get_club_post(update)
    if not post:
        return None

    _, is_created = PostVote.upvote(
        user=user,
        post=post,
    )

    if is_created:
        update.message.reply_text(f"Заплюсовано 👍")
    else:
        update.message.reply_text(f"Ты уже плюсовал, поц")