Ticket #8960: 8960_View_on_site_does_not_work_if_contrib_sites_is_not_installed.2.diff
File 8960_View_on_site_does_not_work_if_contrib_sites_is_not_installed.2.diff, 3.1 KB (added by , 15 years ago) |
---|
-
django/contrib/contenttypes/views.py
23 23 if absurl.startswith('http://') or absurl.startswith('https://'): 24 24 return http.HttpResponseRedirect(absurl) 25 25 26 # Otherwise, we need to introspect the object's relationships for a27 # relation to the Site object28 26 object_domain = None 29 opts = obj._meta30 27 31 # First, look for an many-to-many relationship to Site. 32 for field in opts.many_to_many: 33 if field.rel.to is Site: 34 try: 35 # Caveat: In the case of multiple related Sites, this just 36 # selects the *first* one, which is arbitrary. 37 object_domain = getattr(obj, field.name).all()[0].domain 38 except IndexError: 39 pass 40 if object_domain is not None: 41 break 28 # Look for object domain only if contrib.sites is installed 29 if Site._meta.installed: 30 # Otherwise, we need to introspect the object's relationships for a 31 # relation to the Site object 32 opts = obj._meta 42 33 43 # Next, look for a many-to-one relationship to Site. 44 if object_domain is None: 45 for field in obj._meta.fields: 46 if field.rel and field.rel.to is Site: 34 # First, look for an many-to-many relationship to Site. 35 for field in opts.many_to_many: 36 if field.rel.to is Site: 47 37 try: 48 object_domain = getattr(obj, field.name).domain 49 except Site.DoesNotExist: 38 # Caveat: In the case of multiple related Sites, this just 39 # selects the *first* one, which is arbitrary. 40 object_domain = getattr(obj, field.name).all()[0].domain 41 except IndexError: 50 42 pass 51 43 if object_domain is not None: 52 44 break 53 45 54 # Fall back to the current site (if possible). 55 if object_domain is None: 56 try: 57 object_domain = Site.objects.get_current().domain 58 except Site.DoesNotExist: 59 pass 46 # Next, look for a many-to-one relationship to Site. 47 if object_domain is None: 48 for field in obj._meta.fields: 49 if field.rel and field.rel.to is Site: 50 try: 51 object_domain = getattr(obj, field.name).domain 52 except Site.DoesNotExist: 53 pass 54 if object_domain is not None: 55 break 60 56 57 # Fall back to the current site (if possible). 58 if object_domain is None: 59 try: 60 object_domain = Site.objects.get_current().domain 61 except Site.DoesNotExist: 62 pass 61 63 # If all that malarkey found an object domain, use it. Otherwise, fall back 62 64 # to whatever get_absolute_url() returned. 63 65 if object_domain is not None: