#NEWLINE# def shortcut( request , content_type_id , object_id ) : #NEWLINE# #INDENT# "\n    Redirect to an object's page based on a content-type ID and an object ID.\n    " #NEWLINE# try : #NEWLINE# #INDENT# content_type = ContentType . objects . get ( pk = content_type_id ) #NEWLINE# if ( not content_type . model_class ( ) ) : #NEWLINE# #INDENT# raise http . Http404 ( ( _ ( 'Content type %(ct_id)s object has no associated model' ) % { #NEWLINE# #INDENT# 'ct_id' : content_type_id , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# obj = content_type . get_object_for_this_type ( pk = object_id ) #NEWLINE# #UNINDENT# except ( ObjectDoesNotExist , ValueError ) : #NEWLINE# #INDENT# raise http . Http404 ( ( _ ( "Content type %(ct_id)s object %(obj_id)s doesn't exist" ) % { #NEWLINE# #INDENT# 'ct_id' : content_type_id , #NEWLINE# 'obj_id' : object_id , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# get_absolute_url = obj . get_absolute_url #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# raise http . Http404 ( ( _ ( "%(ct_name)s objects don't have a get_absolute_url() method" ) % { #NEWLINE# #INDENT# 'ct_name' : content_type . name , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# absurl = get_absolute_url ( ) #NEWLINE# if ( absurl . startswith ( 'http://' ) or absurl . startswith ( 'https://' ) ) : #NEWLINE# #INDENT# return http . HttpResponseRedirect ( absurl ) #NEWLINE# #UNINDENT# object_domain = None #NEWLINE# if Site . _meta . installed : #NEWLINE# #INDENT# opts = obj . _meta #NEWLINE# for field in opts . many_to_many : #NEWLINE# #INDENT# if ( field . rel . to is Site ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# object_domain = getattr ( obj , field . name ) . all ( ) [ 0 ] . domain #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( object_domain is not None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( object_domain is None ) : #NEWLINE# #INDENT# for field in obj . _meta . fields : #NEWLINE# #INDENT# if ( field . rel and ( field . rel . to is Site ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# object_domain = getattr ( obj , field . name ) . domain #NEWLINE# #UNINDENT# except Site . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( object_domain is not None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( object_domain is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# object_domain = get_current_site ( request ) . domain #NEWLINE# #UNINDENT# except Site . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( object_domain is not None ) : #NEWLINE# #INDENT# protocol = ( 'https' if request . is_secure ( ) else 'http' ) #NEWLINE# return http . HttpResponseRedirect ( ( '%s://%s%s' % ( protocol , object_domain , absurl ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return http . HttpResponseRedirect ( absurl )