Ticket #16042: 16042.2.diff

File 16042.2.diff, 3.0 KB (added by Thejaswi Puthraya, 13 years ago)

patch against the latest git checkout

  • django/contrib/comments/templatetags/comments.py

    diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py
    index 7962a40..52c731c 100644
    a b class BaseCommentNode(template.Node):  
    4747    def lookup_content_type(token, tagname):
    4848        try:
    4949            app, model = token.split('.')
    50             return ContentType.objects.get(app_label=app, model=model)
     50            return ContentType.objects.get_by_natural_key(app, model)
    5151        except ValueError:
    5252            raise template.TemplateSyntaxError("Third argument in %r must be in the format 'app.model'" % tagname)
    5353        except ContentType.DoesNotExist:
  • tests/regressiontests/comment_tests/tests/templatetag_tests.py

    diff --git a/tests/regressiontests/comment_tests/tests/templatetag_tests.py b/tests/regressiontests/comment_tests/tests/templatetag_tests.py
    index 0ead6c2..dd0f33a 100644
    a b  
    11from django.contrib.comments.forms import CommentForm
    22from django.contrib.comments.models import Comment
    33from django.contrib.contenttypes.models import ContentType
    4 from django.template import Template, Context
     4from django.template import Template, Context, RequestContext
    55from regressiontests.comment_tests.models import Article, Author
    66from regressiontests.comment_tests.tests import CommentTestCase
     7from django.db import connection
     8from django.conf import settings
     9from django.test import RequestFactory
    710
    811class CommentTemplateTagTests(CommentTestCase):
    912
    class CommentTemplateTagTests(CommentTestCase):  
    100103    def testRenderCommentListFromObject(self):
    101104        self.testRenderCommentList("{% render_comment_list for a %}")
    102105
     106class CommentTemplateTagNumQueries(CommentTemplateTagTests):
     107    def setUp(self):
     108        super(CommentTemplateTagNumQueries, self).setUp()
     109        settings.DEBUG = True
     110
     111    def tearDown(self):
     112        settings.DEBUG = False
     113        super(CommentTemplateTagNumQueries, self).tearDown()
     114
     115    def render(self, t, **c):
     116        rf = RequestFactory()
     117        request = rf.get("/")
     118        ctx = RequestContext(request, c)
     119        out = Template(t).render(ctx)
     120        return ctx, out
     121
     122    def renderCommentList(self, tag=None):
     123        connection.queries = []
     124        t = "{% load comments %}" + (tag or "{% render_comment_list for comment_tests.article a.id %}")
     125        ctx, out = self.render(t, a=Article.objects.get(pk=1))
     126        return len(connection.queries)
     127
     128    def testNumberQueries(self):
     129        self.createSomeComments()
     130
     131        num_queries = self.renderCommentList()
     132        num_queries_2 = self.renderCommentList()
     133        self.assertEquals(num_queries, 3)
     134        self.assertEquals(num_queries, num_queries_2)
     135        ContentType.objects.__class__._cache = {}
     136        num_queries_3 = self.renderCommentList()
     137        self.assertEquals(4, num_queries_3)
Back to Top