Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (30 sloc) 1.28 KB
from django.views.decorators.http import require_POST
from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.contenttypes.models import ContentType
from dialogos.forms import UnauthenticatedCommentForm, AuthenticatedCommentForm
from dialogos.models import Comment
def post_comment(request, content_type_id, object_id):
content_type = get_object_or_404(ContentType, pk=content_type_id)
obj = get_object_or_404(content_type.model_class(), pk=object_id)
if request.user.is_authenticated():
form_class = AuthenticatedCommentForm
form_class = UnauthenticatedCommentForm
form = form_class(request.POST, request=request, obj=obj)
if form.is_valid():
redirect_to = request.POST.get("next")
# light security check -- make sure redirect_to isn't garbage.
if not redirect_to or " " in redirect_to or redirect_to.startswith("http"):
redirect_to = obj
return redirect(redirect_to)
def delete_comment(request, comment_id):
comment = get_object_or_404(Comment, pk=comment_id)
obj = comment.content_object
if == request.user:
return redirect(obj)
Jump to Line
Something went wrong with that request. Please try again.