Esempio n. 1
0
    def get_database_model(cls, schema: schemas.Item) -> dict:
        """Decompose pydantic model to data model"""
        indexed_fields = {}
        for field in config.settings.indexed_fields:
            # Use getattr to accommodate extension namespaces
            field_value = getattr(schema.properties, field)
            if field == "datetime":
                field_value = datetime.strptime(field_value, DATETIME_RFC339)
            indexed_fields[field.split(":")[-1]] = field_value

        # Exclude indexed fields from the properties jsonb field
        properties = schema.properties.dict(exclude=set(config.settings.indexed_fields))
        now = datetime.utcnow().strftime(DATETIME_RFC339)
        if not properties["created"]:
            properties["created"] = now
        properties["updated"] = now

        return dict(
            collection_id=schema.collection,
            geometry=ga.shape.from_shape(shape(schema.geometry), 4326),
            properties=properties,
            **indexed_fields,
            **schema.dict(
                exclude_none=True,
                exclude=set(
                    config.settings.forbidden_fields
                    | {"geometry", "properties", "collection"}
                ),
            )
        )
Esempio n. 2
0
 def _preprocess_item(item: schemas.Item) -> Dict:
     """
     preprocess items to match data model
     # TODO: dedup with GetterDict logic (ref #58)
     """
     item = item.dict(exclude_none=True)
     item["geometry"] = json.dumps(item["geometry"])
     item["collection_id"] = item.pop("collection")
     item["datetime"] = item["properties"].pop("datetime")
     return item