#NEWLINE# def _export_tablib( self , export_type , return_url ) : #NEWLINE# #INDENT# '\n            Exports a variety of formats using the tablib library.\n        ' #NEWLINE# if ( tablib is None ) : #NEWLINE# #INDENT# flash ( gettext ( 'Tablib dependency not installed.' ) ) #NEWLINE# return redirect ( return_url ) #NEWLINE# #UNINDENT# filename = self . get_export_name ( export_type ) #NEWLINE# disposition = ( 'attachment;filename=%s' % ( secure_filename ( filename ) , ) ) #NEWLINE# ( mimetype , encoding ) = mimetypes . guess_type ( filename ) #NEWLINE# if ( not mimetype ) : #NEWLINE# #INDENT# mimetype = 'application/octet-stream' #NEWLINE# #UNINDENT# if data : #NEWLINE# #INDENT# mimetype = ( '%s; charset=%s' % ( mimetype , encoding ) ) #NEWLINE# #UNINDENT# ds = tablib . Dataset ( headers = [ c [ 1 ] for c in self . _export_columns ] ) #NEWLINE# ( count , data ) = self . _export_data ( ) #NEWLINE# for row in data : #NEWLINE# #INDENT# vals = [ self . get_export_value ( row , c [ 0 ] ) for c in self . _export_columns ] #NEWLINE# ds . append ( vals ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# response_data = ds . export ( format = export_type ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# response_data = getattr ( ds , export_type ) #NEWLINE# #UNINDENT# #UNINDENT# except ( AttributeError , tablib . UnsupportedFormat ) : #NEWLINE# #INDENT# flash ( gettext ( 'Export type "%(type)s not supported.' , type = export_type ) ) #NEWLINE# return redirect ( return_url ) #NEWLINE# #UNINDENT# return Response ( response_data , headers = { #NEWLINE# #INDENT# 'Content-Disposition' : disposition , #NEWLINE# #UNINDENT# } , mimetype = mimetype )