Ticket #2134: django-20060611-comment-link.diff

File django-20060611-comment-link.diff, 2.3 KB (added by md@…, 9 years ago)

comment patch

  • django/contrib/comments/views/comments.py

    This patch against django svn 20060611 adds the freshly posted comment
    to the 'posted' template thus allowing to show the comment or link
    via an anchor to the comment. E.g.
    <a href="{{ object.get_absolute_url }}#comment-{{ comment.id }}">View Comment</a>
      --Maximillian Dornseif
    
     
    252252        else:
    253253            manipulator.do_html2python(new_data)
    254254            comment = manipulator.save(new_data)
    255         return HttpResponseRedirect("../posted/?c=%s:%s" % (content_type_id, object_id))
     255        return HttpResponseRedirect("../posted/?c=%s:%s&ic=%s" % (content_type_id, object_id, comment.id))
    256256    else:
    257257        raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
    258258
     
    316316        else:
    317317            manipulator.do_html2python(new_data)
    318318            comment = manipulator.save(new_data)
    319         return HttpResponseRedirect("../posted/?c=%s:%s" % (content_type_id, object_id))
     319        return HttpResponseRedirect("../posted/?c=%s:%s&if=%s" % (content_type_id, object_id, comment.id))
    320320    else:
    321321        raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
    322322
     
    330330            The object the comment was posted on
    331331    """
    332332    obj = None
     333    comment = None
    333334    if request.GET.has_key('c'):
    334335        content_type_id, object_id = request.GET['c'].split(':')
    335336        try:
     
    337338            obj = content_type.get_object_for_this_type(pk=object_id)
    338339        except ObjectDoesNotExist:
    339340            pass
    340     return render_to_response('comments/posted.html', {'object': obj}, context_instance=RequestContext(request))
     341        try:
     342            comment_id = request.GET['if']
     343            comment = FreeComment.objects.get(pk=comment_id)
     344        except ObjectDoesNotExist:
     345            pass           
     346        try:
     347            comment_id = request.GET['ic']
     348            comment = Comment.objects.get(pk=comment_id)
     349        except ObjectDoesNotExist:
     350            pass           
     351    return render_to_response('comments/posted.html', {'object': obj, 'comment': comment}, context_instance=RequestContext(request))
Back to Top