Beispiel #1
0
def dislike_reaction(request):
    '''Dislike a reaction'''
    
    try:
        reaction_pk = request.GET['message']
    except KeyError:
        raise Http404

    reaction = get_object_or_404(Reaction, pk=reaction_pk)
    user = request.user

    if reaction.author.pk != request.user.pk:
        # Making sure the user is allowed to do that
        if CommentDislike.objects.filter(user__pk=user.pk, comments__pk=reaction_pk).count()==0:
            dislike=CommentDislike()
            dislike.user=user
            dislike.comments=reaction
            reaction.dislike=reaction.dislike+1
            reaction.save()
            dislike.save()
            if CommentLike.objects.filter(user__pk=user.pk, comments__pk=reaction_pk).count()>0:
                CommentLike.objects.filter(user__pk=user.pk, comments__pk=reaction_pk).all().delete()
                reaction.like=reaction.like-1
                reaction.save()
        else :
            CommentDislike.objects.filter(user__pk=user.pk, comments__pk=reaction_pk).all().delete()
            reaction.dislike=reaction.dislike-1
            reaction.save()

    return redirect(reaction.get_absolute_url())
Beispiel #2
0
def dislike_reaction(request):
    """Dislike a reaction."""

    try:
        reaction_pk = request.GET['message']
    except KeyError:
        raise Http404
    resp = {}
    reaction = get_object_or_404(Reaction, pk=reaction_pk)
    user = request.user

    if reaction.author.pk != request.user.pk:
        # Making sure the user is allowed to do that
        if CommentDislike.objects.filter(user__pk=user.pk,
                                         comments__pk=reaction_pk) \
                .count() == 0:
            dislike = CommentDislike()
            dislike.user = user
            dislike.comments = reaction
            reaction.dislike = reaction.dislike + 1
            reaction.save()
            dislike.save()
            if CommentLike.objects.filter(user__pk=user.pk,
                                          comments__pk=reaction_pk) \
                    .count() > 0:
                CommentLike.objects.filter(
                    user__pk=user.pk,
                    comments__pk=reaction_pk).all().delete()
                reaction.like = reaction.like - 1
                reaction.save()
        else:
            CommentDislike.objects.filter(
                user__pk=user.pk,
                comments__pk=reaction_pk).all().delete()
            reaction.dislike = reaction.dislike - 1
            reaction.save()

    resp['upvotes'] = reaction.like
    resp['downvotes'] = reaction.dislike

    if request.is_ajax():
        return HttpResponse(json_writer.dumps(resp))
    else:
        return redirect(reaction.get_absolute_url())
Beispiel #3
0
def dislike_post(request):
    """Dislike a post."""

    try:
        post_pk = request.GET["message"]
    except:
        # problem in variable format
        raise Http404
    resp = {}
    post = get_object_or_404(Post, pk=post_pk)
    user = request.user
    if not post.topic.forum.can_read(request.user):
        raise PermissionDenied
    if post.author.pk != request.user.pk:

        # Making sure the user is allowed to do that

        if CommentDislike.objects.filter(user__pk=user.pk,
                                         comments__pk=post_pk).count() == 0:
            dislike = CommentDislike()
            dislike.user = user
            dislike.comments = post
            post.dislike = post.dislike + 1
            post.save()
            dislike.save()
            if CommentLike.objects.filter(user__pk=user.pk,
                                          comments__pk=post_pk).count() > 0:
                CommentLike.objects.filter(user__pk=user.pk,
                                           comments__pk=post_pk).all().delete()
                post.like = post.like - 1
                post.save()
        else:
            CommentDislike.objects.filter(user__pk=user.pk,
                                          comments__pk=post_pk).all().delete()
            post.dislike = post.dislike - 1
            post.save()
    resp["upvotes"] = post.like
    resp["downvotes"] = post.dislike
    if request.is_ajax():
        return HttpResponse(json.dumps(resp))
    else:
        return redirect(post.get_absolute_url())
Beispiel #4
0
 def perform_dislike_post(post, user):
     """
     If the post isn't disliked by the user before, the post is disliked by the user and a like is removed if exists.
     Otherwise, the dislike is removed.
     """
     if post.author.pk != user.pk:
         if CommentDislike.objects.filter(
                 user__pk=user.pk, comments__pk=post.pk).count() == 0:
             dislike = CommentDislike()
             dislike.user = user
             dislike.comments = post
             post.dislike = post.dislike + 1
             post.save()
             dislike.save()
             if CommentLike.objects.filter(
                     user__pk=user.pk, comments__pk=post.pk).count() > 0:
                 CommentLike.objects.filter(
                     user__pk=user.pk, comments__pk=post.pk).all().delete()
                 post.like = post.like - 1
                 post.save()
         else:
             CommentDislike.objects.filter(
                 user__pk=user.pk, comments__pk=post.pk).all().delete()
             post.dislike = post.dislike - 1
             post.save()
Beispiel #5
0
def dislike_post(request):
    '''Dislike a post'''
    try:
        post_pk = request.GET['message']
    except KeyError:
        raise Http404

    post = get_object_or_404(Post, pk=post_pk)
    user = request.user

    if post.author.pk != request.user.pk:
        # Making sure the user is allowed to do that
        if CommentDislike.objects.filter(user__pk=user.pk,
                                         comments__pk=post_pk).count() == 0:
            dislike = CommentDislike()
            dislike.user = user
            dislike.comments = post
            post.dislike = post.dislike + 1
            post.save()
            dislike.save()
            if CommentLike.objects.filter(user__pk=user.pk,
                                          comments__pk=post_pk).count() > 0:
                CommentLike.objects.filter(
                    user__pk=user.pk, comments__pk=post_pk).all().delete()
                post.like = post.like - 1
                post.save()
        else:
            CommentDislike.objects.filter(user__pk=user.pk,
                                          comments__pk=post_pk).all().delete()
            post.dislike = post.dislike - 1
            post.save()

    return redirect(post.get_absolute_url())
Beispiel #6
0
def dislike_reaction(request):
    '''Dislike a reaction'''

    try:
        reaction_pk = request.GET['message']
    except KeyError:
        raise Http404

    reaction = get_object_or_404(Reaction, pk=reaction_pk)
    user = request.user

    if reaction.author.pk != request.user.pk:
        # Making sure the user is allowed to do that
        if CommentDislike.objects.filter(
                user__pk=user.pk, comments__pk=reaction_pk).count() == 0:
            dislike = CommentDislike()
            dislike.user = user
            dislike.comments = reaction
            reaction.dislike = reaction.dislike + 1
            reaction.save()
            dislike.save()
            if CommentLike.objects.filter(
                    user__pk=user.pk, comments__pk=reaction_pk).count() > 0:
                CommentLike.objects.filter(
                    user__pk=user.pk, comments__pk=reaction_pk).all().delete()
                reaction.like = reaction.like - 1
                reaction.save()
        else:
            CommentDislike.objects.filter(
                user__pk=user.pk, comments__pk=reaction_pk).all().delete()
            reaction.dislike = reaction.dislike - 1
            reaction.save()

    return redirect(reaction.get_absolute_url())
Beispiel #7
0
def dislike_reaction(request):
    """Dislike a reaction."""

    try:
        reaction_pk = request.GET['message']
    except KeyError:
        raise Http404
    resp = {}
    reaction = get_object_or_404(Reaction, pk=reaction_pk)
    user = request.user

    if reaction.author.pk != request.user.pk:
        # Making sure the user is allowed to do that
        if CommentDislike.objects.filter(user__pk=user.pk,
                                         comments__pk=reaction_pk) \
                .count() == 0:
            dislike = CommentDislike()
            dislike.user = user
            dislike.comments = reaction
            reaction.dislike = reaction.dislike + 1
            reaction.save()
            dislike.save()
            if CommentLike.objects.filter(user__pk=user.pk,
                                          comments__pk=reaction_pk) \
                    .count() > 0:
                CommentLike.objects.filter(
                    user__pk=user.pk,
                    comments__pk=reaction_pk).all().delete()
                reaction.like = reaction.like - 1
                reaction.save()
        else:
            CommentDislike.objects.filter(
                user__pk=user.pk,
                comments__pk=reaction_pk).all().delete()
            reaction.dislike = reaction.dislike - 1
            reaction.save()

    resp['upvotes'] = reaction.like
    resp['downvotes'] = reaction.dislike

    if request.is_ajax():
        return HttpResponse(json_writer.dumps(resp))
    else:
        return redirect(reaction.get_absolute_url())
Beispiel #8
0
def dislike_post(request):
    """Dislike a post."""

    try:
        post_pk = request.GET["message"]
    except:
        # problem in variable format
        raise Http404
    resp = {}
    post = get_object_or_404(Post, pk=post_pk)
    user = request.user
    if not post.topic.forum.can_read(request.user):
        raise PermissionDenied
    if post.author.pk != request.user.pk:

        # Making sure the user is allowed to do that

        if CommentDislike.objects.filter(user__pk=user.pk,
                                         comments__pk=post_pk).count() == 0:
            dislike = CommentDislike()
            dislike.user = user
            dislike.comments = post
            post.dislike = post.dislike + 1
            post.save()
            dislike.save()
            if CommentLike.objects.filter(user__pk=user.pk,
                                          comments__pk=post_pk).count() > 0:
                CommentLike.objects.filter(user__pk=user.pk,
                                           comments__pk=post_pk).all().delete()
                post.like = post.like - 1
                post.save()
        else:
            CommentDislike.objects.filter(user__pk=user.pk,
                                          comments__pk=post_pk).all().delete()
            post.dislike = post.dislike - 1
            post.save()
    resp["upvotes"] = post.like
    resp["downvotes"] = post.dislike
    if request.is_ajax():
        return HttpResponse(json.dumps(resp))
    else:
        return redirect(post.get_absolute_url())