def import_do(): # retrieves the import file values (reference to the # uploaded file) and then validates if it has been # defined, in case it fails prints the template with # the appropriate error variable set import_file = quorum.get_field("import_file", None) if import_file == None or not import_file.filename: return flask.render_template( "settings/import.html.tpl", link = "settings", sub_link = "import", error = "No file defined" ) # creates a temporary file path for the storage of the file # and then saves it into that directory fd, file_path = tempfile.mkstemp() import_file.save(file_path) # retrieves the database and creates a new export manager for # the currently defined entities then imports the data defined # in the current temporary path adapter = quorum.get_adapter() manager = quorum.export.ExportManager( adapter, multiple = quorum.resolve() ) try: manager.import_data(file_path) finally: os.close(fd); os.remove(file_path) return flask.redirect( flask.url_for( "import_a", message = "Database file imported with success" ) )
def export_do(): adapter = quorum.get_adapter() file = quorum.legacy.BytesIO() manager = quorum.export.ExportManager( adapter, multiple = quorum.resolve() ) manager.export_data(file) date_time = datetime.datetime.utcnow() date_time_s = date_time.strftime("%Y%m%d") file_name = "%s_%s.dat" % (NAME, date_time_s) return flask.Response( file.getvalue(), headers = { "Content-Disposition" : "attachment; filename=\"%s\"" % file_name }, mimetype = "application/octet-stream" )