mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +00:00
magic-removal: fixed #1425 -- django.views.defaults.shortcut now works correctly (thanks, Christopher Lenz)
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2615 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3825cb0a7d
commit
537f01c162
@ -26,27 +26,44 @@ def shortcut(request, content_type_id, object_id):
|
|||||||
|
|
||||||
object_domain = None
|
object_domain = None
|
||||||
|
|
||||||
# Next, look for an many-to-many relationship to sites
|
# Otherwise, we need to introspect the object's relationships for a
|
||||||
if hasattr(obj, 'get_site_list'):
|
# relation to the Site object
|
||||||
site_list = obj.get_site_list()
|
opts = obj._meta
|
||||||
if site_list:
|
|
||||||
object_domain = site_list[0].domain
|
|
||||||
|
|
||||||
# Next, look for a many-to-one relationship to sites
|
# First, look for an many-to-many relationship to sites
|
||||||
elif hasattr(obj, 'get_site'):
|
for field in opts.many_to_many:
|
||||||
try:
|
if field.rel.to is Site:
|
||||||
object_domain = obj.get_site().domain
|
try:
|
||||||
except Site.DoesNotExist:
|
object_domain = getattr(obj, field.name).all()[0].domain
|
||||||
pass
|
except Site.DoesNotExist:
|
||||||
|
pass
|
||||||
|
if object_domain is not None:
|
||||||
|
break
|
||||||
|
|
||||||
# Then, fall back to the current site (if possible)
|
# Next look for a many-to-one relationship to site
|
||||||
else:
|
if object_domain is None:
|
||||||
|
for field in obj._meta.fields:
|
||||||
|
if field.rel and field.rel.to is Site:
|
||||||
|
try:
|
||||||
|
object_domain = getattr(obj, field.name).domain
|
||||||
|
except Site.DoesNotExist:
|
||||||
|
pass
|
||||||
|
if object_domain is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Fall back to the current site (if possible)
|
||||||
|
if object_domain is None:
|
||||||
try:
|
try:
|
||||||
object_domain = Site.objects.get_current().domain
|
object_domain = Site.objects.get_current().domain
|
||||||
except Site.DoesNotExist:
|
except Site.DoesNotExist:
|
||||||
# Finally, give up and use a URL without the domain name
|
pass
|
||||||
return http.HttpResponseRedirect(obj.get_absolute_url())
|
|
||||||
return http.HttpResponseRedirect('http://%s%s' % (object_domain, obj.get_absolute_url()))
|
# If all that malarky found an object domain, use it; otherwise fall back
|
||||||
|
# to whatever get_absolute_url() returned.
|
||||||
|
if object_domain is not None:
|
||||||
|
return http.HttpResponseRedirect('http://%s%s' % (object_domain, absurl))
|
||||||
|
else:
|
||||||
|
return http.HttpResponseRedirect(absurl)
|
||||||
|
|
||||||
def page_not_found(request, template_name='404'):
|
def page_not_found(request, template_name='404'):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user