Beispiel #1
0
    def test_is_gob_geo_type(self):
        all_types = _gob_types_dict.keys()

        for type in all_types:
            # Same test, different approach
            is_geo = type.startswith("GOB.Geo.")
            self.assertTrue(is_geo == is_gob_geo_type(type))
Beispiel #2
0
    def _select_expression(self, relation: dict, field: str):
        if field == self.CURSOR_ID:
            return f"{relation['alias']}.{FIELD.GOBID} AS {self.CURSOR_ID}"

        field_snake = to_snake(field)
        expression = f"{relation['alias']}.{field_snake}"

        # If geometry field, transform to WKT
        if field_snake in relation['attributes'] and is_gob_geo_type(relation['attributes'][field_snake]['type']):
            return f"ST_AsText({expression}) {field_snake}"

        return expression
Beispiel #3
0
def _get_special_column_type(column_type: str):
    """Returns special column type such as 'geo' or 'json', or else None

    :param column_type:
    :return:
    """
    if is_gob_geo_type(column_type):
        return "geo"
    elif is_gob_json_type(column_type):
        return "json"
    else:
        return None
Beispiel #4
0
def get_field_order(model):
    """
    Return the fields of the given model in a standard order

    :param model:
    :return: list of field names
    """
    if is_relation(model):
        # The relation fields are already ordered
        return REL_FIELDS

    # Start with the regular model fields
    model_fields = [k for k in model['fields'].keys()]

    # Get id fields
    id_fields = [model['entity_id']]
    if FIELD.SEQNR in model_fields:
        id_fields.append(FIELD.SEQNR)

    # Split this in relations, geometries and other fields
    relation_fields = [
        k for k in model_fields
        if is_gob_reference_type(model['fields'][k]['type'])
    ]
    geo_fields = [
        k for k in model_fields if is_gob_geo_type(model['fields'][k]['type'])
    ]
    data_fields = [
        k for k in model_fields
        if k not in relation_fields + geo_fields + id_fields
    ]

    # Basic order is identification, plain data fields, then all references, then geo fields and then the unique id
    fields = id_fields + data_fields + relation_fields + geo_fields + [
        UNIQUE_ID
    ]

    # Add all meta fields
    fields += [k for k in model['all_fields'].keys() if k not in fields]

    # Finally filter the list for fields that should be skipped
    fields = [
        k for k in fields if k not in SKIP_FIELDS
        and model['all_fields'][k]['type'] not in SKIP_TYPES
    ]
    return fields