def listtables(request, schema_name): insp = actions.connect() labels = get_readable_table_names(schema_name) tables = [(table, labels[table] if table in labels else None) for table in insp.get_table_names(schema=schema_name) if not table.startswith('_')] tables = sorted(tables, key=lambda x: x[0]) return render(request, 'dataedit/dataedit_tablelist.html', {'schema': schema_name, 'tables': tables})
def listschemas(request): insp = actions.connect() schemas = sorted([(schema, len( {table for table in insp.get_table_names(schema=schema) if not table.startswith('_')})) for schema in insp.get_schema_names() if schema in schema_whitelist and not schema.startswith('_')], key=lambda x: x[0]) return render(request, 'dataedit/dataedit_schemalist.html', {'schemas': schemas})
def listtables(request, schema_name): insp = actions.connect() labels = get_readable_table_names(schema_name) tables = [(table, labels[table] if table in labels else None) for table in insp.get_table_names(schema=schema_name) if not table.startswith('_')] tables = sorted(tables, key=lambda x: x[0]) return render(request, 'dataedit/dataedit_tablelist.html', { 'schema': schema_name, 'tables': tables })
def listschemas(request): insp = actions.connect() schemas = sorted( [(schema, len({ table for table in insp.get_table_names(schema=schema) if not table.startswith('_') })) for schema in insp.get_schema_names() if schema in schema_whitelist and not schema.startswith('_')], key=lambda x: x[0]) return render(request, 'dataedit/dataedit_schemalist.html', {'schemas': schemas})
def listschemas(request): """ Loads all schemas that are present in the external database specified in oeplatform/securitysettings.py. Only schemas that are present in the whitelist are processed that do not start with an underscore. :param request: A HTTP-request object sent by the Django framework :return: Renders the schema list """ insp = actions.connect() engine = actions._get_engine() conn = engine.connect() query = 'SELECT schemaname, count(tablename) as tables FROM pg_tables WHERE pg_has_role(\'{user}\', tableowner, \'MEMBER\') AND tablename NOT LIKE \'\_%%\' group by schemaname;'.format( user=sec.dbuser) response = conn.execute(query) schemas = sorted([(row.schemaname, row.tables) for row in response if row.schemaname in schema_whitelist and not row.schemaname.startswith('_')], key=lambda x: x[0]) return render(request, 'dataedit/dataedit_schemalist.html', {'schemas': schemas})
def listschemas(request): """ Loads all schemas that are present in the external database specified in oeplatform/securitysettings.py. Only schemas that are present in the whitelist are processed that do not start with an underscore. :param request: A HTTP-request object sent by the Django framework :return: Renders the schema list """ searchedQueryString = request.GET.get("query") searchedTagIds = list(map( lambda t: int(t), request.GET.getlist("tags"), )) for tag_id in searchedTagIds: increment_usage_count(tag_id) insp = actions.connect() engine = actions._get_engine() conn = engine.connect() query = ( "SELECT i.schema_name as schemaname, count(distinct p.tablename) as table_count, array_agg(p.tablename) as tables, array_agg(tg.id) as tag_ids FROM pg_tables p " "right join information_schema.schemata i " "ON p.schemaname=i.schema_name " "left join table_tags t " "ON p.schemaname=t.schema_name " "left join tags tg " "ON t.tag=tg.id " "WHERE p.tablename IS NULL " " OR (pg_has_role('{user}', tableowner, 'MEMBER') " " AND p.tablename NOT LIKE '\_%%') " "GROUP BY i.schema_name;".format(user=sec.dbuser)) response = conn.execute(query) description = { "boundaries": "Data that depicts boundaries, such as geographic, administrative or political boundaries. Such data comes as polygons.", "climate": "Data related to climate and weather. This includes, for example, precipitation, temperature, cloud cover and atmospheric conditions.", "economy": "Data related to economic activities. Examples: sectoral value added, sectoral inputs and outputs, GDP, prices of commodities etc.", "demand": "Data on demand. Demand can relate to commodities but also to services.", "grid": "Energy transmission infrastructure. examples: power lines, substation, pipelines", "supply": "Data on supply. Supply can relate to commodities but also to services.", "environment": "environmental resources, protection and conservation. examples: environmental pollution, waste storage and treatment, environmental impact assessment, monitoring environmental risk, nature reserves, landscape", "society": "Demographic data such as population statistics and projections, fertility, mortality etc.", "model_draft": "Unfinished data of any kind. Note: there is no version control and data is still volatile.", "scenario": "Scenario data in the broadest sense. Includes input and output data from models that project scenarios into the future. Example inputs: assumptions made about future developments of key parameters such as energy prices and GDP. Example outputs: projected electricity transmission, projected greenhouse gas emissions. Note that inputs to one model could be an output of another model and the other way around.", "reference": "sources, literature", "emission": "Data on emissions. Examples: total greenhouse gas emissions, CO2-emissions, energy-related CO2-emissions, methane emissions, air pollutants etc.", "openstreetmap": "OpenStreetMap is a open project that collects and structures freely usable geodata and keeps them in a database for use by anyone. This data is available under a free license, the Open Database License.", "policy": "Data on policies and measures. This could, for example, include a list of renewable energy policies per European Member State. It could also be a list of climate related policies and measures in a specific country." } schemas = sorted( [(row.schemaname, description.get( row.schemaname, "No description"), row.table_count, row.tag_ids) for row in response if row.schemaname in schema_whitelist and not row.schemaname.startswith("_") and (not searchedQueryString or searchedQueryString in row.schemaname or list( filter( lambda tableName: tableName and searchedQueryString in tableName, row.tables))) and (not searchedTagIds or set( filter(lambda x: x is not None, row.tag_ids)).issuperset( searchedTagIds))], key=lambda x: x[0], ) print(schemas) return render(request, "dataedit/dataedit_schemalist.html", { "schemas": schemas, "query": searchedQueryString, "tags": searchedTagIds })