@require_POST
@csrf_exempt
@cross_domain_post_response
def dislike_thread(request, thread_id):
    try:
        thread = Thread.objects.get(id=thread_id)
    except Thread.DoesNotExist as e:
        data = {
            'placement': 'comments_header',
            'content': str(e)
        }
        return HttpResponseNotFound(json.dumps(data))

    if not request.user.is_anonymous():
        if request.user.hidden.filter(id=thread.site.id):
            return HttpResponseBadRequest(
                _('user is disabled on site with id %s') % thread.site.id
            )
    liked_threads = request.session.get('liked_threads', [])
    disliked_threads = request.session.get('disliked_threads', [])

    # if user disliked thread already, remove his dislike and add like
    if thread.id in liked_threads:
        thread.undo_like(request.user)
        remove_from_session_list(request, 'liked_threads', thread.id)
        thread.dislike(request.user)
        add_to_session_list(request, 'disliked_threads', thread.id)

    elif thread.id not in disliked_threads:
        # if user haven't had interaction with thread, like the thread
        thread.dislike(request.user)
        # save liked information to the session
        add_to_session_list(request, 'disliked_threads', thread.id)

    resp = render(request, 'header.html', {'thread': thread})
    data = {'placement': 'comments_header', 'content': resp.content}

    return HttpResponse(json.dumps(data))
dataset/ETHPy150Open c4all/c4all/comments/views.py/dislike_thread/original