def get_download_file(): """Return URI for action resource download file""" file_token = request.args.get('fileToken') token = urllib.unquote(file_token) filename = AuthToken.verify(token) if filename: full_filename = filename + '.xlsx' return send_from_directory(directory=UPLOAD_FOLDER, filename=full_filename) return jsonify({'error': 'File download token expired or an error occurred!'})
def create_download_file(): """Create Excel file from action resource records and return URI to file""" if request.method == 'OPTIONS': return make_api_response() qb = QueryBuilder(request.args) if qb.query_type == 'aggregate': query_cursor = db.action.aggregate(qb.get_query()) data = [elem for elem in query_cursor] else: query_cursor = db.action.find(qb.get_query()).sort('timestamp', pymongo.DESCENDING) data = process_query_results(query_cursor, 'action') username = g.user.username filename = username + ''.join(random.choice(string.ascii_uppercase + string.digits) for x in xrange(16)) make_excel_file(filename, data) token = AuthToken.generate(filename) urlsafe_token = urllib.quote(token) tempDownloadUri = request.base_url + '/report.xlsx?fileToken=' + urlsafe_token return make_api_response(json_util.dumps({'file_token': tempDownloadUri}))