def collection_private(db, provider, request): from app.models import Collection collection = Collection.create(name="test-collection-private1", is_public=False, provider_uuid=provider["uuid"]) Collection.session.commit() return collection.to_dict()
def collection2(db, provider2, request): from app.models import Collection collection = Collection.create(name="test-collection1", is_public=True, provider_uuid=provider2["uuid"]) Collection.session.commit() return collection.to_dict()
def copy_collection_to_new( user: InternalUserDTO, src_collection_uuid: UUID, dst_collection_dto: CollectionDTO, ) -> CollectionDTO: try: src_collection = Collection.find_readable_or_fail(user, src_collection_uuid) except ModelNotFoundError: raise PermissionError() dst_collection_dto.provider_uuid = user.provider_uuid dst_collection = Collection.create(**dst_collection_dto.to_dict()) copy_items_by_collection_uuid(src_collection_uuid, dst_collection.uuid) src_collection.session.commit() return to_model(dst_collection, CollectionDTO)
def sensors(db, provider, request): import json import os.path from shapely.geometry.geo import shape from app.models import Collection, Item collection = Collection.create(name="sensors", is_public=True, provider_uuid=provider["uuid"]) my_path = os.path.abspath(os.path.dirname(__file__)) path = os.path.join(my_path, "../../data/sensors.json") with open(path) as f: data = json.load(f) for feature in data["features"]: Item.create( collection_uuid=collection.uuid, properties=feature["properties"], geometry=shape(feature["geometry"]).to_wkt(), ) Collection.session.commit() return collection.to_dict()
def seed_initial_collection(provider_uuid: str) -> Collection: collection = Collection.create(provider_uuid=provider_uuid, name="__test", is_public=True) return collection