Example #1
0
def comment(request):
    form = PostCommentForm(request.POST, request)

    if not form.is_valid():
        data = {'placement': 'comments_container', 'content': form.errors}
        return HttpResponseBadRequest(json.dumps(data))
    else:
        new_comment = form.save()

    posted = add_to_session_list(request, 'posted_comments', new_comment.id)
    comments = form.cleaned_data['thread'].comments.all()

    site = Site.objects.get(domain=form.cleaned_data['domain'])

    request.session['all_comments'] = True

    resp = render(
        request, 'comments.html', {
            'comments': comments,
            'posted_comments': posted,
            'last_posted_comment_id': posted[-1] if posted else None,
            'rs_customer_id': site.rs_customer_id,
            'all_comments': request.session.get('all_comments', False),
        })
    data = {
        'placement': 'comments_container',
        'content': resp.content,
        'comment_id': new_comment.id
    }

    return HttpResponse(json.dumps(data))
Example #2
0
def comment(request):
    form = PostCommentForm(request.POST, request)

    if not form.is_valid():
        data = {"placement": "comments_container", "content": form.errors}
        return HttpResponseBadRequest(json.dumps(data))
    else:
        new_comment = form.save()

    posted = add_to_session_list(request, "posted_comments", new_comment.id)
    comments = form.cleaned_data["thread"].comments.all()

    site = Site.objects.get(domain=form.cleaned_data["domain"])

    request.session["all_comments"] = True

    resp = render(
        request,
        "comments.html",
        {
            "comments": comments,
            "posted_comments": posted,
            "last_posted_comment_id": posted[-1] if posted else None,
            "rs_customer_id": site.rs_customer_id,
            "all_comments": request.session.get("all_comments", False),
        },
    )
    data = {"placement": "comments_container", "content": resp.content, "comment_id": new_comment.id}

    return HttpResponse(json.dumps(data))
Example #3
0
def comment(request):
    form = PostCommentForm(request.POST, request)
    if not form.is_valid():
        data = {'placement': 'comments_container', 'content': form.errors}
        return HttpResponseBadRequest(json.dumps(data))
    else:
        site = Site.objects.get(domain=form.cleaned_data['domain'])
        if not request.user.is_anonymous():
            if request.user.hidden.filter(id=site.id):
                return HttpResponseBadRequest(
                    _("User doesn't have permissions to post to this site."))
        new_comment = form.save()

    posted = add_to_session_list(request, 'posted_comments', new_comment.id)
    comments = form.cleaned_data['thread'].comments.all()

    request.session['all_comments'] = True

    resp = render(
        request,
        'comments.html',
        {
            'comments': comments,
            'posted_comments': posted,
            'last_posted_comment_id': posted[-1] if posted else None,
            'rs_customer_id': site.rs_customer_id,
            'all_comments': request.session.get('all_comments', False),
        }
    )
    data = {
        'placement': 'comments_container',
        'content': resp.content,
        'comment_id': new_comment.id
    }

    return HttpResponse(json.dumps(data))
Example #4
0
def post_detail(request, slug, year, month, day, template_name="blog/post_detail.html"):
    """Blog post detail view."""
    try:
        tt = time.strptime('%s-%s-%s' % (year, month, day),
                           '%s-%s-%s' % ('%Y', '%b', '%d'))
        date = datetime.date(*tt[:3])
    except ValueError:
        raise Http404

    lookup_kwargs = {
        'publish': date,
        'slug__exact': slug,
    }

    now = timezone.now()
    if date >= now.date():
        lookup_kwargs['publish__lte'] = now

    try:
        post = Post.objects.published().get(**lookup_kwargs)
    except Post.DoesNotExist:
        raise Http404

    context = {
        'post': post,
    }

    if post.allow_comments:
        comment_form = PostCommentForm(request.POST or None)
        context.update({'comment_form': comment_form})
        if request.method == "POST":
            if comment_form.is_valid():
                comment_form.save(post=post)
                return redirect(post.get_absolute_url())

    return render(request, template_name, context)