@require_GET
@csrf_exempt
@json_response
def get_comments(request):
    form = GetRequestValidationForm(request.GET)
    if not form.is_valid():
        return HttpResponseBadRequest(
            _('could not get comments, errors: %s') % form.errors
        )

    domain_name = form.cleaned_data['domain']
    thread_id = form.cleaned_data['thread']

    try:
        site = Site.objects.get(domain=domain_name)
        if not request.user.is_anonymous():
            if request.user.hidden.filter(id=site.id):
                return HttpResponseBadRequest(
                    _('user is disabled on site with id %s') % site.id
                )
    except Site.DoesNotExist:
        return HttpResponseBadRequest(
            'domain with name %s does not exist' % domain_name
        )

    if not thread_id:
        return HttpResponseBadRequest(
            _('thread url not provided')
        )

    thread, created = site.threads.get_or_create(id=thread_id)

    posted_comments = request.session.get('posted_comments', [])
    all_comments = request.GET.get('all', False)
    if all_comments:
        request.session['all_comments'] = True

    if request.user.is_anonymous():
        site_admin = False
    else:
        site_admin = request.user.is_site_admin(domain_name)

    comments = thread.comments.exclude(user__hidden__in=[site]).distinct()
    resp = render(
        request,
        "comments.html",
        {
            'comments': comments,
            'posted_comments': posted_comments,
            'last_posted_comment_id': posted_comments[-1] if posted_comments else None,
            'rs_customer_id': site.rs_customer_id,
            'all_comments': all_comments,
            'site_admin': site_admin
        }
    )

    return {"html": resp.content, "html_container_name": "comments_container"}
dataset/ETHPy150Open c4all/c4all/comments/views.py/get_comments/original