コード例 #1
0
def create_collection_item(user: InternalUserDTO, collection_uuid: UUID,
                           item_dto: ItemDTO) -> ItemDTO:
    coll = Collection.find_writeable_or_fail(user, collection_uuid)
    item_dto.collection_uuid = coll.uuid  # type: ignore
    item = Item(**item_dto.to_dict())
    item.save()
    item.session.commit()
    return to_model(item, ItemDTO)
コード例 #2
0
 def find_readable_by_collection_uuid(
     cls,
     user: InternalUserDTO,
     collection_uuid: UUID,
     filters: dict,
     transforms: dict = {},
 ) -> List[ItemDTO]:
     user_uuid = user.uuid
     provider_uuid = user.provider_uuid
     filters["provider_uuid"] = provider_uuid
     filters["collection_uuid"] = collection_uuid
     where, exec_dict = cls.create_where(filters)
     result = (cls.session.query(
         cls.uuid,
         cls.simplified_geometry(transforms.get("simplify", 0.0)),
         cls.properties,
         cls.collection_uuid,
         cls.created_at,
         cls.updated_at,
         cls.revision,
     ).join(Item.collection).outerjoin(
         ACL,
         or_(
             ACL.granted_provider_uuid == provider_uuid,
             ACL.granted_user_uuid == user_uuid,
         ),
     ).filter(sa.text(where)).params(exec_dict).limit(
         filters["limit"]).offset(filters["offset"]).all())
     result = [
         ItemDTO(**dict(zip(res.keys(), res))) for res in result
         if filters["valid"] is False or res[1] is not None
     ]
     return result
コード例 #3
0
def map_feature_to_item_dto(feature: Feature) -> ItemDTO:
    item = ItemDTO(
        **{
            "uuid": feature.id,
            "geometry": shape(feature.geometry).to_wkt(),
            "properties": feature.properties,
        }
    )
    return item
コード例 #4
0
def map_item_dto_to_feature(item: ItemDTO) -> Optional[Feature]:
    feature = None
    if item.geometry is not None:
        if isinstance(item.geometry, str):
            item.geometry = WKTElement(item.geometry)
        feature = Feature(
            geometry=to_shape(item.geometry),
            properties=item.properties,
            id=str(item.uuid),
        )
    return feature
コード例 #5
0
 def to_dto(self) -> ItemDTO:
     return ItemDTO(
         **{
             "geometry": shape(self.geometry).to_wkt(),
             "properties": self.properties
         })
コード例 #6
0
 def to_dto(self) -> ItemDTO:
     geometry = None
     if self.geometry is not None:
         geometry = shape(self.geometry).to_wkt()
     return ItemDTO(**{"geometry": geometry, "properties": self.properties})