Beispiel #1
0
def post_comment(request, content_type=None, object_id=None, parent_id=None):
    """Generic function to add comments to objects of any ContentType"""
    if not (content_type and object_id):
        raise Http404(
            "Invalid POST data. Please, use corresponding comment form."
        )  # Must specify both content_type and object_id to post comments
    if request.method != "POST":
        raise Http404("Only POST access is allowed")
    form = VVCommentForm(request.POST)
    if form.is_valid():
        new_comment = form.save(commit=False)
        new_comment.content_type = get_object_or_404(ContentType, id=int(content_type))
        new_comment.object_id = int(object_id)
        new_comment.user = request.user
        if parent_id:
            new_comment.parent = get_object_or_404(VVComment, id=int(parent_id))
            # raise Error
        new_comment.save()
        next = request.POST.get("next", "/")
        return RedirectView.as_view(
            url=next
            + "?nc="
            + VVComment.objects.filter(content_type=new_comment.content_type, object_id=new_comment.object_id)
            .count()
            .__str__()
        )  # + "#comment_header_" + new_comment.id.__str__())
    else:
        form = VVCommentForm()
        return RedirectView.as_view(url="/")  # redirect_to(request, '/')
Beispiel #2
0
def post_comment(request, content_type = None, object_id = None, parent_id = None):
	"""Generic function to add comments to objects of any ContentType"""
	if not (content_type and object_id):
		raise Http404("Invalid POST data. Please, use corresponding comment form.")	# Must specify both content_type and object_id to post comments
	if request.method != 'POST':
		raise Http404('Only POST access is allowed')
	form = VVCommentForm(request.POST)
	if form.is_valid():
		new_comment = form.save(commit = False)
		new_comment.content_type = get_object_or_404(ContentType, id = int(content_type))
		new_comment.object_id = int(object_id)
		new_comment.user = request.user
		if parent_id:
			new_comment.parent = get_object_or_404(VVComment, id = int(parent_id))
		#raise Error
		new_comment.save()
		next = request.POST.get('next', '/')
		return redirect_to(request, next)
	else:
		form = VVCommentForm()
		return redirect_to(request, '/stories/')