|
@@ -1,8 +1,8 @@
|
|
|
-from django import http
|
|
|
from django.apps import apps
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
from django.contrib.sites.requests import RequestSite
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
|
+from django.http import Http404, HttpResponseRedirect
|
|
|
from django.utils.translation import gettext as _
|
|
|
|
|
|
|
|
@@ -14,18 +14,24 @@ def shortcut(request, content_type_id, object_id):
|
|
|
try:
|
|
|
content_type = ContentType.objects.get(pk=content_type_id)
|
|
|
if not content_type.model_class():
|
|
|
- raise http.Http404(_("Content type %(ct_id)s object has no associated model") %
|
|
|
- {'ct_id': content_type_id})
|
|
|
+ raise Http404(
|
|
|
+ _("Content type %(ct_id)s object has no associated model") %
|
|
|
+ {'ct_id': content_type_id}
|
|
|
+ )
|
|
|
obj = content_type.get_object_for_this_type(pk=object_id)
|
|
|
except (ObjectDoesNotExist, ValueError):
|
|
|
- raise http.Http404(_("Content type %(ct_id)s object %(obj_id)s doesn't exist") %
|
|
|
- {'ct_id': content_type_id, 'obj_id': object_id})
|
|
|
+ raise Http404(
|
|
|
+ _("Content type %(ct_id)s object %(obj_id)s doesn't exist") %
|
|
|
+ {'ct_id': content_type_id, 'obj_id': object_id}
|
|
|
+ )
|
|
|
|
|
|
try:
|
|
|
get_absolute_url = obj.get_absolute_url
|
|
|
except AttributeError:
|
|
|
- raise http.Http404(_("%(ct_name)s objects don't have a get_absolute_url() method") %
|
|
|
- {'ct_name': content_type.name})
|
|
|
+ raise Http404(
|
|
|
+ _("%(ct_name)s objects don't have a get_absolute_url() method") %
|
|
|
+ {'ct_name': content_type.name}
|
|
|
+ )
|
|
|
absurl = get_absolute_url()
|
|
|
|
|
|
# Try to figure out the object's domain, so we can do a cross-site redirect
|
|
@@ -33,7 +39,7 @@ def shortcut(request, content_type_id, object_id):
|
|
|
|
|
|
# If the object actually defines a domain, we're done.
|
|
|
if absurl.startswith(('http://', 'https://', '//')):
|
|
|
- return http.HttpResponseRedirect(absurl)
|
|
|
+ return HttpResponseRedirect(absurl)
|
|
|
|
|
|
# Otherwise, we need to introspect the object's relationships for a
|
|
|
# relation to the Site object
|
|
@@ -84,7 +90,6 @@ def shortcut(request, content_type_id, object_id):
|
|
|
# to whatever get_absolute_url() returned.
|
|
|
if object_domain is not None:
|
|
|
protocol = request.scheme
|
|
|
- return http.HttpResponseRedirect('%s://%s%s'
|
|
|
- % (protocol, object_domain, absurl))
|
|
|
+ return HttpResponseRedirect('%s://%s%s' % (protocol, object_domain, absurl))
|
|
|
else:
|
|
|
- return http.HttpResponseRedirect(absurl)
|
|
|
+ return HttpResponseRedirect(absurl)
|