diff options
| author | Tim Graham <timograham@gmail.com> | 2017-09-07 08:16:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-07 08:16:21 -0400 |
| commit | 6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch) | |
| tree | 1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/contrib/contenttypes/views.py | |
| parent | 8b2515a450ef376b9205029090af0a79c8341bd7 (diff) | |
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda
because try/except performs better.
Diffstat (limited to 'django/contrib/contenttypes/views.py')
| -rw-r--r-- | django/contrib/contenttypes/views.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py index c527687250..d67f071569 100644 --- a/django/contrib/contenttypes/views.py +++ b/django/contrib/contenttypes/views.py @@ -1,5 +1,3 @@ -from contextlib import suppress - from django.apps import apps from django.contrib.contenttypes.models import ContentType from django.contrib.sites.requests import RequestSite @@ -55,10 +53,12 @@ def shortcut(request, content_type_id, object_id): # First, look for an many-to-many relationship to Site. for field in opts.many_to_many: if field.remote_field.model is Site: - with suppress(IndexError): + try: # Caveat: In the case of multiple related Sites, this just # selects the *first* one, which is arbitrary. object_domain = getattr(obj, field.name).all()[0].domain + except IndexError: + pass if object_domain is not None: break @@ -77,8 +77,10 @@ def shortcut(request, content_type_id, object_id): # Fall back to the current site (if possible). if object_domain is None: - with suppress(Site.DoesNotExist): + try: object_domain = Site.objects.get_current(request).domain + except Site.DoesNotExist: + pass else: # Fall back to the current request's site. |
