Ticket #8960: 8960_View_on_site_does_not_work_if_contrib_sites_is_not_installed.diff
File 8960_View_on_site_does_not_work_if_contrib_sites_is_not_installed.diff, 3.0 KB (added by , 16 years ago) |
---|
-
django/views/defaults.py
25 25 return http.HttpResponseRedirect(absurl) 26 26 27 27 object_domain = None 28 29 # Look for object domain only if contrib.sites is installed 30 if Site._meta.installed: 31 # Otherwise, we need to introspect the object's relationships for a 32 # relation to the Site object 33 opts = obj._meta 28 34 29 # Otherwise, we need to introspect the object's relationships for a 30 # relation to the Site object 31 opts = obj._meta 32 33 # First, look for an many-to-many relationship to sites 34 for field in opts.many_to_many: 35 if field.rel.to is Site: 36 try: 37 object_domain = getattr(obj, field.name).all()[0].domain 38 except IndexError: 39 pass 40 if object_domain is not None: 41 break 42 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: 35 # First, look for an many-to-many relationship to sites 36 for field in opts.many_to_many: 37 if field.rel.to is Site: 47 38 try: 48 object_domain = getattr(obj, field.name). domain49 except Site.DoesNotExist:39 object_domain = getattr(obj, field.name).all()[0].domain 40 except IndexError: 50 41 pass 51 42 if object_domain is not None: 52 43 break 53 44 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 45 # Next look for a many-to-one relationship to site 46 if object_domain is None: 47 for field in obj._meta.fields: 48 if field.rel and field.rel.to is Site: 49 try: 50 object_domain = getattr(obj, field.name).domain 51 except Site.DoesNotExist: 52 pass 53 if object_domain is not None: 54 break 60 55 56 # Fall back to the current site (if possible) 57 if object_domain is None: 58 try: 59 object_domain = Site.objects.get_current().domain 60 except (Site.DoesNotExist): 61 pass 62 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: 64 66 protocol = request.is_secure() and 'https' or 'http' 65 67 return http.HttpResponseRedirect('%s://%s%s' % (protocol, object_domain, absurl)) 66 68 else: 69 print absurl 67 70 return http.HttpResponseRedirect(absurl) 68 71 69 72 def page_not_found(request, template_name='404.html'):