Example #1
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
        })
Example #2
0
def load_metadata_from_db(schema, table):
    """Get comment for a table in OEP database (contains the metadata)

    :param schema: name of the OEP schema
    :param table: name of the OEP table in the OEP schema
    :return:
    """
    metadata = actions.get_comment_table(schema, table)
    metadata = parse_meta_data(metadata, schema, table)
    return metadata
Example #3
0
def load_metadata_from_db(schema, table):
    """Get comment for a table in OEP database (contains the metadata)

    :param schema: name of the OEP schema
    :param table: name of the OEP table in the OEP schema
    :return:
    """
    metadata = actions.get_comment_table(schema, table)
    if "error" in metadata:
        return metadata
    if not metadata:
        metadata = __LATEST.get_empty(schema, table)
    else:
        if "error" in metadata:
            return {
                "description": metadata["content"],
                "error": metadata["error"]
            }
        try:
            version = get_metadata_version(metadata)
            if version:
                if not isinstance(version, tuple):
                    version = (version, )
                if len(version) < 2:
                    version = (version[0], 0)
                if version[0] == 1:
                    if version[1] == 1:
                        metadata = __LATEST.from_v1_1(metadata, schema, table)
                    elif version[1] == 2:
                        metadata = __LATEST.from_v1_2(metadata)
                    elif version[1] == 3:
                        # This is not part of the actual metadata-schema. We move the fields to
                        # a higher level in order to avoid fetching the first resource in the
                        # templates.
                        metadata["fields"] = metadata["resources"][0]["fields"]

                    elif version[1] == 4:
                        # This is not part of the actual metadata-schema. We move the fields to
                        # a higher level in order to avoid fetching the first resource in the
                        # templates.
                        metadata["fields"] = metadata["resources"][0][
                            "schema"]["fields"]
                elif version[0] == 0:
                    metadata = __LATEST.from_v0(metadata, schema, table)
            else:
                metadata = __LATEST.from_v0(metadata, schema, table)
        except MetadataException as me:
            return {
                "description":
                metadata,
                "error":
                me.error.message
                if hasattr(me.error, "message") else str(me.error),
            }
    return metadata
Example #4
0
def load_comment_from_db(schema, table):
    comment = actions.get_comment_table(schema, table)
    if 'error' in comment:
        return comment
    if not comment:
        comment_on_table = __LATEST.get_empty(schema, table)
    else:
        if 'error' in comment:
            return {'description': comment['content'], 'error': comment['error']}
        try:
            if 'metadata_version' in comment:
                version = __parse_version(comment['metadata_version'])
            elif 'meta_version' in comment:
                version = __parse_version(comment['meta_version'])
            elif 'resources' in comment:
                versions = [__parse_version(x['meta_version'])
                            for x in comment['resources'] if 'meta_version' in x]
                if not versions:
                    version = None
                else:
                    version = min(versions)
            else:
                version = (0,0)
            if version:
                if not isinstance(version, tuple):
                    version = (version,)
                if len(version) < 2:
                    version = (version[0], 0)
                if version[0] == 1:
                    if version[1] == 1:
                        comment_on_table = __LATEST.from_v1_1(comment, schema, table)
                    elif version[1] == 2:
                        comment_on_table = __LATEST.from_v1_2(comment)
                    elif version[1] == 3:
                        comment_on_table = comment
                elif version[0] == 0:
                    comment_on_table = __LATEST.from_v0(comment, schema, table)
                else:
                    comment_on_table = comment
            else:
                comment_on_table = __LATEST.from_v0(comment, schema, table)
        except MetadataException as me:
            return {'description': comment, 'error': me.error.message if hasattr(me.error, 'message') else str(me.error)}

    # This is not part of the actual metadata-schema. We move the fields to
    # a higher level in order to avoid fetching the first resource in the
    # templates.
    comment_on_table['fields'] = comment_on_table['resources'][0][
        'fields']

    return comment_on_table
Example #5
0
    def get(self, request, schema, table):

        if schema not in schema_whitelist or schema.startswith('_'):
            raise Http404("Schema not accessible")

        tags = []
        db = sec.dbname
        actions.create_meta(schema, table)

        comment_on_table = actions.get_comment_table(db, schema, table)
        comment_columns = {
            d["name"]: d
            for d in comment_on_table["Table fields"]
        } if "Table fields" in comment_on_table else {}

        if 'error' in comment_on_table:
            comment_on_table['Notes'] = [comment_on_table['content']]

        comment_on_table = OrderedDict([(label, comment_on_table[key])
                                        for key, label in COMMENT_KEYS
                                        if key in comment_on_table])

        columns = actions.get_columns({'schema': schema, 'table': table})
        has_row_comments = '_comment' in {
            col['name']
            for col in columns if 'name' in col
        }

        repo = svn.local.LocalClient(sec.datarepowc)
        TableRevision.objects.all().delete()
        available_revisions = TableRevision.objects.filter(table=table,
                                                           schema=schema)
        revisions = []
        for rev in repo.log_default():
            try:
                rev_obj = available_revisions.get(revision=rev.revision)
            except TableRevision.DoesNotExist:
                rev_obj = None
            revisions.append((rev, rev_obj))
        return render(
            request, 'dataedit/dataedit_overview.html', {
                'has_row_comments': has_row_comments,
                'comment_on_table': dict(comment_on_table),
                'comment_columns': comment_columns,
                'revisions': revisions,
                'kinds': ['table', 'map', 'graph'],
                'table': table,
                'schema': schema,
                'tags': tags
            })
Example #6
0
    def get(self, request, schema, table):

        if schema not in schema_whitelist or schema.startswith('_'):
            raise Http404("Schema not accessible")

        tags = []
        db = sec.dbname
        actions.create_meta(schema, table)

        comment_on_table = actions.get_comment_table(db, schema, table)
        comment_columns = {d["name"]: d for d in comment_on_table[
            "Table fields"]} if "Table fields" in comment_on_table else {}

        if 'error' in comment_on_table:
            comment_on_table['Notes'] = [comment_on_table['content']]

        comment_on_table = OrderedDict(
            [(label, comment_on_table[key]) for key, label in
             COMMENT_KEYS
             if key in comment_on_table])

        columns = actions.get_columns({'schema': schema, 'table': table})
        has_row_comments = '_comment' in {col['name'] for col in columns if
                                          'name' in col}

        repo = svn.local.LocalClient(sec.datarepowc)
        TableRevision.objects.all().delete()
        available_revisions = TableRevision.objects.filter(table=table,
                                                           schema=schema)
        revisions = []
        for rev in repo.log_default():
            try:
                rev_obj = available_revisions.get(revision=rev.revision)
            except TableRevision.DoesNotExist:
                rev_obj = None
            revisions.append((rev, rev_obj))
        return render(request,
                      'dataedit/dataedit_overview.html',
                      {
                          'has_row_comments': has_row_comments,
                          'comment_on_table': dict(comment_on_table),
                          'comment_columns': comment_columns,
                          'revisions': revisions,
                          'kinds': ['table', 'map', 'graph'],
                          'table': table,
                          'schema': schema,
                          'tags': tags
                      })
Example #7
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
        })
Example #8
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