From 6164c1b917297594aad253cd404240bfde9cef81 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 22 Jun 2011 10:12:25 -0400 Subject: [PATCH] Eliminated unnecessary ContentType queries that used applabel/model-based lookups. --- philo/contrib/julian/models.py | 2 +- philo/templatetags/collections.py | 2 +- philo/templatetags/containers.py | 2 +- philo/templatetags/embed.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/philo/contrib/julian/models.py b/philo/contrib/julian/models.py index e4e78ba..fd0a7c5 100644 --- a/philo/contrib/julian/models.py +++ b/philo/contrib/julian/models.py @@ -334,7 +334,7 @@ class CalendarView(FeedView): def get_events_by_location(self, request, app_label, model, pk, extra_context=None): try: - ct = ContentType.objects.get(app_label=app_label, model=model) + ct = ContentType.objects.get_by_natural_key(app_label, model) location = ct.model_class()._default_manager.get(pk=pk) except ObjectDoesNotExist: raise Http404 diff --git a/philo/templatetags/collections.py b/philo/templatetags/collections.py index 414a742..e9db2bd 100644 --- a/philo/templatetags/collections.py +++ b/philo/templatetags/collections.py @@ -47,7 +47,7 @@ def membersof(parser, token): try: app_label, model = params[3].strip('"').split('.') - ct = ContentType.objects.get(app_label=app_label, model=model) + ct = ContentType.objects.get_by_natural_key(app_label, model) except ValueError: raise template.TemplateSyntaxError('"%s" template tag option "with" requires an argument of the form app_label.model (see django.contrib.contenttypes)' % tag) except ContentType.DoesNotExist: diff --git a/philo/templatetags/containers.py b/philo/templatetags/containers.py index e280e60..bc04b9f 100644 --- a/philo/templatetags/containers.py +++ b/philo/templatetags/containers.py @@ -87,7 +87,7 @@ def container(parser, token): if option_token == 'references': try: app_label, model = remaining_tokens.pop(0).strip('"').split('.') - references = ContentType.objects.get(app_label=app_label, model=model) + references = ContentType.objects.get_by_natural_key(app_label, model) except IndexError: raise template.TemplateSyntaxError('"%s" template tag option "references" requires an argument specifying a content type' % tag) except ValueError: diff --git a/philo/templatetags/embed.py b/philo/templatetags/embed.py index 9599240..16f8092 100644 --- a/philo/templatetags/embed.py +++ b/philo/templatetags/embed.py @@ -285,7 +285,7 @@ def parse_content_type(bit, tagname): except ValueError: raise template.TemplateSyntaxError('"%s" template tag expects the first argument to be of the form app_label.model' % tagname) try: - ct = ContentType.objects.get(app_label=app_label, model=model) + ct = ContentType.objects.get_by_natural_key(app_label, model) except ContentType.DoesNotExist: raise template.TemplateSyntaxError('"%s" template tag requires an argument of the form app_label.model which refers to an installed content type (see django.contrib.contenttypes)' % tagname) return ct -- 2.20.1