def get_taxon_tree(): """Get taxon tree. .. :quickref: Synthese; """ taxon_tree_table = GenericTable(tableName="v_tree_taxons_synthese", schemaName="gn_synthese", engine=DB.engine) data = DB.session.query(taxon_tree_table.tableDef).all() return [taxon_tree_table.as_dict(d) for d in data]
def export_metadata(info_role): """Route to export the metadata in CSV .. :quickref: Synthese; The table synthese is join with gn_synthese.v_metadata_for_export The column jdd_id is mandatory in the view gn_synthese.v_metadata_for_export POST parameters: Use a list of id_synthese (in POST parameters) to filter the v_synthese_for_export_view """ if request.json: filters = request.json elif request.data: # decode byte to str - compat python 3.5 filters = json.loads(request.data.decode("utf-8")) else: filters = { key: request.args.getlist(key) for key, value in request.args.items() } metadata_view = GenericTable(tableName="v_metadata_for_export", schemaName="gn_synthese", engine=DB.engine) q = DB.session.query(distinct(VSyntheseForWebApp.id_dataset), metadata_view.tableDef).join( metadata_view.tableDef, getattr( metadata_view.tableDef.columns, current_app.config["SYNTHESE"] ["EXPORT_METADATA_ID_DATASET_COL"], ) == VSyntheseForWebApp.id_dataset, ) q = select( [distinct(VSyntheseForWebApp.id_dataset), metadata_view.tableDef]) synthese_query_class = SyntheseQuery(VSyntheseForWebApp, q, filters) synthese_query_class.add_join( metadata_view.tableDef, getattr( metadata_view.tableDef.columns, current_app.config["SYNTHESE"]["EXPORT_METADATA_ID_DATASET_COL"], ), VSyntheseForWebApp.id_dataset) synthese_query_class.filter_query_all_filters(info_role) data = DB.engine.execute(synthese_query_class.query) return to_csv_resp( datetime.datetime.now().strftime("%Y_%m_%d_%Hh%Mm%S"), data=[metadata_view.as_dict(d) for d in data], separator=";", columns=[db_col.key for db_col in metadata_view.tableDef.columns], )
def export_metadata(info_role): """Route to export the metadata in CSV .. :quickref: Synthese; The table synthese is join with gn_synthese.v_metadata_for_export The column jdd_id is mandatory in the view gn_synthese.v_metadata_for_export POST parameters: Use a list of id_synthese (in POST parameters) to filter the v_synthese_for_export_view """ filters = {key: request.args.getlist(key) for key, value in request.args.items()} metadata_view = GenericTable( tableName="v_metadata_for_export", schemaName="gn_synthese", engine=DB.engine ) q = DB.session.query( distinct(VSyntheseForWebApp.id_dataset), metadata_view.tableDef ).join( metadata_view.tableDef, getattr( metadata_view.tableDef.columns, current_app.config["SYNTHESE"]["EXPORT_METADATA_ID_DATASET_COL"], ) == VSyntheseForWebApp.id_dataset, ) q = synthese_query.filter_query_all_filters( VSyntheseForWebApp, q, filters, info_role ) return to_csv_resp( datetime.datetime.now().strftime("%Y_%m_%d_%Hh%Mm%S"), data=[metadata_view.as_dict(d) for d in q.all()], separator=";", columns=[db_col.key for db_col in metadata_view.tableDef.columns], )