Ticket #16042: 16042.3.diff
File 16042.3.diff, 3.0 KB (added by , 13 years ago) |
---|
-
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): 47 47 def lookup_content_type(token, tagname): 48 48 try: 49 49 app, model = token.split('.') 50 return ContentType.objects.get (app_label=app, model=model)50 return ContentType.objects.get_by_natural_key(app, model) 51 51 except ValueError: 52 52 raise template.TemplateSyntaxError("Third argument in %r must be in the format 'app.model'" % tagname) 53 53 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..307a66d 100644
a b 1 1 from django.contrib.comments.forms import CommentForm 2 2 from django.contrib.comments.models import Comment 3 3 from django.contrib.contenttypes.models import ContentType 4 from django.template import Template, Context 4 from django.template import Template, Context, RequestContext 5 5 from regressiontests.comment_tests.models import Article, Author 6 6 from regressiontests.comment_tests.tests import CommentTestCase 7 from django.db import connection 8 from django.conf import settings 9 from django.test import RequestFactory 7 10 8 11 class CommentTemplateTagTests(CommentTestCase): 9 12 … … class CommentTemplateTagTests(CommentTestCase): 100 103 def testRenderCommentListFromObject(self): 101 104 self.testRenderCommentList("{% render_comment_list for a %}") 102 105 106 class CommentTemplateTagNumQueries(CommentTemplateTagTests): 107 def setUp(self): 108 super(CommentTemplateTagNumQueries, self).setUp() 109 self.debug = settings.DEBUG 110 settings.DEBUG = True 111 112 def tearDown(self): 113 settings.DEBUG = self.debug 114 super(CommentTemplateTagNumQueries, self).tearDown() 115 116 def render(self, t, **c): 117 rf = RequestFactory() 118 request = rf.get("/") 119 ctx = RequestContext(request, c) 120 out = Template(t).render(ctx) 121 return ctx, out 122 123 def renderCommentList(self, tag=None): 124 connection.queries = [] 125 t = "{% load comments %}" + (tag or "{% render_comment_list for comment_tests.article a.id %}") 126 ctx, out = self.render(t, a=Article.objects.get(pk=1)) 127 return len(connection.queries) 128 129 def testNumberQueries(self): 130 self.createSomeComments() 131 132 num_queries = self.renderCommentList() 133 num_queries_2 = self.renderCommentList() 134 self.assertEquals(num_queries, 3) 135 self.assertEquals(num_queries, num_queries_2) 136 ContentType.objects.__class__._cache = {} 137 num_queries_3 = self.renderCommentList() 138 self.assertEquals(4, num_queries_3)