#NEWLINE# @ staff_member_required #NEWLINE# def static_proxy( request ) : #NEWLINE# #INDENT# '\n    Serves TinyMCE plugins inside the inline popups and the uploadify\n    SWF, as these are normally static files, and will break with\n    cross-domain JavaScript errors if ``STATIC_URL`` is an external\n    host. URL for the file is passed in via querystring in the inline\n    popup plugin template, and we then attempt to pull out the relative\n    path to the file, so that we can serve it locally via Django.\n    ' #NEWLINE# normalize = ( lambda u : ( ( '//' + u . split ( '://' ) [ ( - 1 ) ] ) if ( '://' in u ) else u ) ) #NEWLINE# url = normalize ( request . GET [ 'u' ] ) #NEWLINE# host = ( '//' + request . get_host ( ) ) #NEWLINE# static_url = normalize ( settings . STATIC_URL ) #NEWLINE# for prefix in ( host , static_url , '/' ) : #NEWLINE# #INDENT# if url . startswith ( prefix ) : #NEWLINE# #INDENT# url = url . replace ( prefix , '' , 1 ) #NEWLINE# #UNINDENT# #UNINDENT# response = '' #NEWLINE# ( content_type , encoding ) = mimetypes . guess_type ( url ) #NEWLINE# if ( content_type is None ) : #NEWLINE# #INDENT# content_type = 'application/octet-stream' #NEWLINE# #UNINDENT# path = finders . find ( url ) #NEWLINE# if path : #NEWLINE# #INDENT# if isinstance ( path , ( list , tuple ) ) : #NEWLINE# #INDENT# path = path [ 0 ] #NEWLINE# #UNINDENT# if url . endswith ( '.htm' ) : #NEWLINE# #INDENT# static_url = ( ( settings . STATIC_URL + os . path . split ( url ) [ 0 ] ) + '/' ) #NEWLINE# if ( not urlparse ( static_url ) . scheme ) : #NEWLINE# #INDENT# static_url = urljoin ( host , static_url ) #NEWLINE# #UNINDENT# base_tag = ( "<base href='%s'>" % static_url ) #NEWLINE# with open ( static_url , 'r' ) as f : #NEWLINE# #INDENT# response = f . read ( ) . replace ( '<head>' , ( '<head>' + base_tag ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# with open ( path , 'rb' ) as f : #NEWLINE# #INDENT# response = f . read ( ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError : #NEWLINE# #INDENT# return HttpResponseNotFound ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return HttpResponse ( response , content_type = content_type )