Exemplo n.º 1
0
 def post(self, request, schema, table):
     columns = actions.analyze_columns(sec.dbname, schema, table)
     comment = {
         'Name': request.POST['name'],
         'Source': self._load_url_list(request, 'source'),
         'Reference date': self._load_list(request, 'ref_date'),
         'Date of Collection': self._load_list(request, 'date_col'),
         'Spatial Resolution': self._load_list(request, 'spat_res'),
         'Licence': self._load_url_list(request, 'licence'),
         'Description': self._load_list(request, 'descr'),
         'Column': self._load_col_list(request, columns),
         'Changes':[],
         'Notes': self._load_list(request, 'notes'),
         'Instructions for proper use': self._load_list(request, 'instr'),
     }
     engine = actions._get_engine()
     conn = engine.connect()
     trans = conn.begin()
     try:
         conn.execute(
             sqla.text("COMMENT ON TABLE {schema}.{table} IS :comment ;".format(
                 schema=schema,
                 table=table)),
             comment=json.dumps(comment)
         )
     except Exception as e:
         raise e
     else:
         trans.commit()
     finally:
         conn.close()
     return redirect('/dataedit/view/{schema}/{table}'.format(schema=schema,
                                                             table=table))
Exemplo n.º 2
0
 def post(self, request, schema, table):
     columns = actions.analyze_columns(sec.dbname, schema, table)
     comment = {
         'Name': request.POST['name'],
         'Source': self._load_url_list(request, 'source'),
         'Reference date': self._load_list(request, 'ref_date'),
         'Date of Collection': self._load_list(request, 'date_col'),
         'Spatial Resolution': self._load_list(request, 'spat_res'),
         'Licence': self._load_url_list(request, 'licence'),
         'Description': self._load_list(request, 'descr'),
         'Column': self._load_col_list(request, columns),
         'Changes': [],
         'Notes': self._load_list(request, 'notes'),
         'Instructions for proper use': self._load_list(request, 'instr'),
     }
     engine = actions._get_engine()
     conn = engine.connect()
     trans = conn.begin()
     try:
         conn.execute(sqla.text(
             "COMMENT ON TABLE {schema}.{table} IS :comment ;".format(
                 schema=schema, table=table)),
                      comment=json.dumps(comment))
     except Exception as e:
         raise e
     else:
         trans.commit()
     finally:
         conn.close()
     return redirect('/dataedit/view/{schema}/{table}'.format(schema=schema,
                                                              table=table))
Exemplo n.º 3
0
    def post(self, request, schema, table):
        """
        Handles the send event of the form created in the get-method. The
        metadata is transformed into a JSON-dictionary and stored in the tables
        comment inside the database.
        :param request: A HTTP-request object sent by the Django framework
        :param schema: Name of a schema
        :param table: Name of a table
        :return: Redirects to the view of the specified table
        """
        columns = actions.analyze_columns(sec.dbname, schema, table)

        comment = load_meta(request.POST)

        engine = actions._get_engine()
        conn = engine.connect()
        trans = conn.begin()
        try:
            conn.execute(sqla.text(
                "COMMENT ON TABLE {schema}.{table} IS :comment ;".format(
                    schema=schema, table=table)),
                         comment=json.dumps(comment))
        except Exception as e:
            raise e
        else:
            trans.commit()
        finally:
            conn.close()
        return redirect('/dataedit/view/{schema}/{table}'.format(schema=schema,
                                                                 table=table))
Exemplo n.º 4
0
    def get(self, request, schema, table):
        db = sec.dbname
        comment_on_table = actions.get_comment_table(db, schema, table)
        columns = actions.analyze_columns(db, schema, table)
        if 'error' in comment_on_table:
            comment_on_table = {'Notes': [comment_on_table['content']]}
        comment_on_table = {
            k.replace(' ', '_'): v
            for (k, v) in comment_on_table.items()
        }
        if 'Column' not in comment_on_table:
            comment_on_table['Column'] = []
        commented_cols = [col['Name'] for col in comment_on_table['Column']]
        for col in columns:
            if not col['id'] in commented_cols:
                comment_on_table['Column'].append({
                    'Name': col['id'],
                    'Description': '',
                    'Unit': ''
                })

        return render(request, 'dataedit/meta_edit.html', {
            'schema': schema,
            'table': table,
            'comment_on_table': comment_on_table
        })
Exemplo n.º 5
0
def get_empty(schema, table):
    template = TEMPLATE_V1_4.copy()
    columns = actions.analyze_columns(schema, table)
    # TODO: check how the fields should
    template["resources"][0]["schema"]["fields"] = [{
        "name": col["id"],
        "description": "",
        "unit": ""
    } for col in columns]
    return template
Exemplo n.º 6
0
def get_empty(schema, table):
    columns = actions.analyze_columns(schema, table)
    comment_on_table = {
        'title':
        '',
        'description':
        '',
        'language': ['eng'],
        'spatial': {
            'location': '',
            'extent': '',
            'resolution': ''
        },
        'temporal': {
            'reference_date': '',
            'start': '',
            'end': '',
            'resolution': ''
        },
        'sources': [{
            'name': '',
            'description': '',
            'url': '',
            'license': '',
            'copyright': ''
        }],
        'license': {
            'id': '',
            'name': '',
            'version': '',
            'url': '',
            'instruction': '',
            'copyright': ''
        },
        'contributors': [],
        'resources': [{
            'name':
            '',
            'format':
            'PostgreSQL',
            'fields': [{
                'name': col['id'],
                'description': '',
                'unit': ''
            } for col in columns]
        }],
        'metadata_version':
        '1.3'
    }
    return comment_on_table
Exemplo n.º 7
0
def get_empty(schema, table):
    columns = actions.analyze_columns(schema, table)
    comment_on_table = {
        "title":
        "",
        "description":
        "",
        "language": ["eng"],
        "spatial": {
            "location": "",
            "extent": "",
            "resolution": ""
        },
        "temporal": {
            "reference_date": "",
            "start": "",
            "end": "",
            "resolution": ""
        },
        "sources": [{
            "name": "",
            "description": "",
            "url": "",
            "license": "",
            "copyright": ""
        }],
        "license": {
            "id": "",
            "name": "",
            "version": "",
            "url": "",
            "instruction": "",
            "copyright": "",
        },
        "contributors": [],
        "resources": [{
            "name":
            "",
            "format":
            "PostgreSQL",
            "fields": [{
                "name": col["id"],
                "description": "",
                "unit": ""
            } for col in columns],
        }],
        "metadata_version":
        "1.3",
    }
    return comment_on_table
Exemplo n.º 8
0
    def post(self, request, schema, table):
        """
        Handles the send event of the form created in the get-method. The
        metadata is transformed into a JSON-dictionary and stored in the tables
        comment inside the database.
        :param request: A HTTP-request object sent by the Django framework
        :param schema: Name of a schema
        :param table: Name of a table
        :return: Redirects to the view of the specified table
        """
        columns = actions.analyze_columns(schema, table)

        comment = read_metadata_from_post(request.POST, schema, table)
        save_metadata_as_table_comment(schema, table, metadata=comment)

        return redirect("/dataedit/view/{schema}/{table}".format(schema=schema,
                                                                 table=table))
Exemplo n.º 9
0
    def get(self, request, schema, table):
        db = sec.dbname
        comment_on_table = actions.get_comment_table(db, schema, table)
        columns = actions.analyze_columns(db, schema, table)
        if 'error' in comment_on_table:
            comment_on_table = {'Notes':[comment_on_table['content']]}
        comment_on_table = {k.replace(' ', '_'): v for (k, v) in comment_on_table.items()}
        if 'Column' not in comment_on_table:
            comment_on_table['Column'] = []
        commented_cols = [col['Name'] for col in comment_on_table['Column']]
        for col in columns:
            if not col['id'] in commented_cols:
                comment_on_table['Column'].append({
                    'Name':col['id'],
                    'Description': '',
                    'Unit': ''})

        return render(request, 'dataedit/meta_edit.html',{
            'schema': schema,
            'table': table,
            'comment_on_table': comment_on_table
        })
Exemplo n.º 10
0
def from_v0(comment_on_table, schema, table):
    columns = actions.analyze_columns(schema, table)
    refdate = comment_on_table.get("Reference date")
    try:
        if "resources" not in comment_on_table:
            comment_on_table = {
                "title":
                comment_on_table.get("Name"),
                "description":
                "; ".join(comment_on_table.get("Description", [])),
                "language": [],
                "reference_date":
                refdate[0] if isinstance(refdate, list) else refdate,
                "spatial": [{
                    "extent": x,
                    "resolution": ""
                } for x in comment_on_table.get("Spatial resolution")],
                "temporal": [{
                    "start": x,
                    "end": "",
                    "resolution": ""
                } for x in comment_on_table.get("Temporal resolution", [])],
                "sources": [{
                    "name": x.get("Name"),
                    "description": "",
                    "url": x.get("URL"),
                    "license": " ",
                    "copyright": " ",
                } for x in comment_on_table.get("Source", [])],
                "license": [{
                    "id": "",
                    "name": x,
                    "version": "",
                    "url": "",
                    "instruction": "",
                    "copyright": "",
                } for x in comment_on_table.get("Licence", [])],
                "contributors": [{
                    "name": x["Name"],
                    "email": x["Mail"],
                    "date": x["Date"],
                    "comment": x["Comment"],
                } for x in comment_on_table.get("Changes", [])],
                "resources": [{
                    "name":
                    "",
                    "format":
                    "sql",
                    "fields": [{
                        "name": x.get("Name"),
                        "description": x.get("Description"),
                        "unit": x["Unit"],
                    } for x in comment_on_table.get("Column", [])],
                }],
                "meta_version":
                "1.1",
            }

            comment_on_table["fields"] = comment_on_table.get(
                "resources", [{}])[0].get("fields")

            commented_cols = [
                col.get("name") for col in comment_on_table.get("fields", [])
            ]
        else:
            comment_on_table["fields"] = comment_on_table.get(
                "resources", [{}])[0].get("fields")

            if "fields" not in comment_on_table.get("resources", [{}])[0]:
                comment_on_table["fields"] = []
            else:
                comment_on_table["fields"] = comment_on_table.get(
                    "resources", [{}])[0].get("fields")

            commented_cols = [
                col.get("name") for col in comment_on_table.get("fields", [])
            ]
    except Exception as e:
        raise MetadataException(comment_on_table, e)

    for col in columns:
        if not col.get("id") in commented_cols:
            comment_on_table["fields"].append({
                "name": col["id"],
                "description": "",
                "unit": ""
            })

    return comment_on_table
Exemplo n.º 11
0
def load_comments(schema, table):
    comment_on_table = actions.get_comment_table(sec.dbname, schema, table)
    columns = actions.analyze_columns(sec.dbname, schema, table)
    try:
        if 'error' in comment_on_table:
            comment_on_table = {
                'description': [comment_on_table['content']],
                'fields': []
            }
            commented_cols = []
        elif 'resources' not in comment_on_table:
            comment_on_table = {
                'title':
                comment_on_table['Name'],
                'description':
                "; ".join(comment_on_table['Description']),
                'language': [],
                'reference_date':
                comment_on_table['Reference date'],
                'sources': [{
                    'name': x['Name'],
                    'description': '',
                    'url': x['URL'],
                    'license': ' ',
                    'copyright': ' '
                } for x in comment_on_table['Source']],
                'spatial': [{
                    'extend': x,
                    'resolution': ''
                } for x in comment_on_table['Spatial resolution']],
                'license': [{
                    'id': '',
                    'name': x,
                    'version': '',
                    'url': '',
                    'instruction': '',
                    'copyright': ''
                } for x in comment_on_table['Licence']],
                'contributors': [{
                    'name': x['Name'],
                    'email': x['Mail'],
                    'date': x['Date'],
                    'comment': x['Comment']
                } for x in comment_on_table['Changes']],
                'resources': [{
                    'schema': {
                        'fields': [{
                            'name': x['Name'],
                            'description': x['Description'],
                            'unit': x['Unit']
                        } for x in comment_on_table['Column']]
                    },
                    'meta_version': '1.2'
                }]
            }

            comment_on_table['fields'] = \
            comment_on_table['resources'][0]['schema']['fields']

            commented_cols = [
                col['name'] for col in comment_on_table['fields']
            ]
        else:
            comment_on_table['fields'] = \
            comment_on_table['resources'][0]['schema'][
                'fields']

            if 'fields' not in comment_on_table['resources'][0]['schema']:
                comment_on_table['fields'] = []
            else:
                comment_on_table['fields'] = \
                comment_on_table['resources'][0]['schema'][
                    'fields']

            commented_cols = [
                col['name'] for col in comment_on_table['fields']
            ]
    except Exception as e:
        comment_on_table = {'description': comment_on_table, 'fields': []}
        commented_cols = []

    for col in columns:
        if not col['id'] in commented_cols:
            comment_on_table['fields'].append({
                'name': col['id'],
                'description': '',
                'unit': ''
            })

    return comment_on_table
Exemplo n.º 12
0
def from_v1_1(comment_on_table, schema, table):
    columns = actions.analyze_columns(schema, table)
    try:
        if "resources" not in comment_on_table:
            comment_on_table = {
                "title":
                comment_on_table["Name"],
                "description":
                "; ".join(comment_on_table["Description"]),
                "language": [],
                "reference_date":
                comment_on_table["Reference date"],
                "sources": [{
                    "name": x["Name"],
                    "description": "",
                    "url": x["URL"],
                    "license": " ",
                    "copyright": " ",
                } for x in comment_on_table["Source"]],
                "spatial": [{
                    "extend": x,
                    "resolution": ""
                } for x in comment_on_table["Spatial resolution"]],
                "license": [{
                    "id": "",
                    "name": x,
                    "version": "",
                    "url": "",
                    "instruction": "",
                    "copyright": "",
                } for x in comment_on_table["Licence"]],
                "contributors": [{
                    "name": x["Name"],
                    "email": x["Mail"],
                    "date": x["Date"],
                    "comment": x["Comment"],
                } for x in comment_on_table["Changes"]],
                "resources": [{
                    "schema": {
                        "fields": [{
                            "name": x["Name"],
                            "description": x["Description"],
                            "unit": x["Unit"],
                        } for x in comment_on_table["Column"]]
                    },
                    "meta_version": "1.2",
                }],
            }

            comment_on_table["fields"] = comment_on_table["resources"][0][
                "schema"]["fields"]

            commented_cols = [
                col["name"] for col in comment_on_table["fields"]
            ]
        else:
            comment_on_table["resources"] = [{
                "schema": x
            } for x in comment_on_table["resources"]]
            if "fields" not in comment_on_table["resources"][0]:
                comment_on_table["fields"] = []
            else:
                comment_on_table["fields"] = comment_on_table["resources"][0][
                    "fields"]

            commented_cols = [
                col["name"] for col in comment_on_table["fields"]
            ]
    except Exception as e:
        comment_on_table = {"description": comment_on_table, "fields": []}
        commented_cols = []

    for col in columns:
        if not col["id"] in commented_cols:
            comment_on_table["fields"].append({
                "name": col["id"],
                "description": "",
                "unit": ""
            })

    return comment_on_table