#NEWLINE# def send_file( request , download_key ) : #NEWLINE# #INDENT# '\n    After the appropriate session variable has been set, we commence the download.\n    The key is maintained in the url but the session variable is used to control the\n    download in order to maintain security.\n    ' #NEWLINE# if ( not request . session . get ( 'download_key' , False ) ) : #NEWLINE# #INDENT# url = urlresolvers . reverse ( 'satchmo_download_process' , kwargs = { #NEWLINE# #INDENT# 'download_key' : download_key , #NEWLINE# #UNINDENT# } ) #NEWLINE# return HttpResponseRedirect ( url ) #NEWLINE# #UNINDENT# ( valid , msg , dl_product ) = _validate_key ( request . session [ 'download_key' ] ) #NEWLINE# if ( not valid ) : #NEWLINE# #INDENT# url = urlresolvers . reverse ( 'satchmo_download_process' , kwargs = { #NEWLINE# #INDENT# 'download_key' : request . session [ 'download_key' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# return HttpResponseRedirect ( url ) #NEWLINE# #UNINDENT# file = dl_product . downloadable_product . file #NEWLINE# file_url = ( '/%s' % file . name ) #NEWLINE# url_dict = { #NEWLINE# #INDENT# 'url' : file_url , #NEWLINE# #UNINDENT# } #NEWLINE# sendfile_url_for_file . send ( None , file = file , product = dl_product . downloadable_product , url_dict = url_dict ) #NEWLINE# file_url = url_dict [ 'url' ] #NEWLINE# file_name = os . path . basename ( file_url ) #NEWLINE# dl_product . num_attempts += 1 #NEWLINE# dl_product . save ( ) #NEWLINE# del request . session [ 'download_key' ] #NEWLINE# response = HttpResponse ( ) #NEWLINE# response [ 'X-Accel-Redirect' ] = file_url #NEWLINE# response [ 'X-Sendfile' ] = file_url #NEWLINE# response [ 'X-LIGHTTPD-send-file' ] = file_url #NEWLINE# response [ 'Content-Disposition' ] = ( 'attachment; filename=%s' % file_name ) #NEWLINE# response [ 'Content-length' ] = file . size #NEWLINE# ( contenttype , encoding ) = mimetypes . guess_type ( file_name ) #NEWLINE# if contenttype : #NEWLINE# #INDENT# response [ 'Content-type' ] = contenttype #NEWLINE# #UNINDENT# return request