Loading rpc/methods.py +55 −1 Original line number Diff line number Diff line Loading @@ -632,7 +632,8 @@ def delete_collection(user: User, collection_id: int, recursive: bool = False) - Delete collection given its id. Collection MUST be empty of any content (no children collections and no resources), unless the 'recursive'parameter is set to True. unless the 'recursive'parameter is set to True, in which case ALL descendants will be deleted. """ query_set: Union[Iterator[Collection], QuerySet] = Collection.objects.filter( pk=collection_id, deleted_at__isnull=True Loading Loading @@ -2820,3 +2821,56 @@ def picture_rotate_crop( return serializers.file(reloaded_file, include_metas=False) except pyvips.error.Error: raise ServiceException(CANT_CREATE_IMAGE) @_log_call @_rpc_groups(["Resources", "Collections"]) def remove_items(user: User, parent_collection_id: int, selection: dict = None) -> bool: """ Will mass remove items based on parent collection Use such an object for exclusion: ``` { "exclude": { "resources_ids": [12, 10, 15] "collections_ids:" [4, 254, 17] } } ``` deleteCollection (with recursion) and deleteResource are used under the hood. The parent collection is left as-is. """ if not selection: selection = {} if not parent_collection_id: raise ServiceException(NO_SUCH_COLLECTION) parent_collection = Collection.objects.filter(pk=parent_collection_id).first() if not parent_collection: raise ServiceException(NO_SUCH_COLLECTION) children_collections_set = parent_collection.children() if selection.get("exclude"): if selection["exclude"].get("collections_ids"): children_collections_set = children_collections_set.exclude( id__in=selection["exclude"].get("collections_ids") ) for collection_instance in children_collections_set.all(): delete_collection(user, collection_instance.id, True) res_set = parent_collection.resources.all() if selection.get("exclude"): if selection["exclude"].get("resources_ids"): res_set = res_set.exclude(id__in=selection["exclude"].get("resources_ids")) for resource_instance in res_set.all(): # is resource anywhere else ? if resource_instance.collections.filter(deleted_at__isnull=True).count() < 2: delete_resource(user, resource_instance.id) else: remove_resource_from_collection( user, resource_instance.id, parent_collection.id ) return True Loading
rpc/methods.py +55 −1 Original line number Diff line number Diff line Loading @@ -632,7 +632,8 @@ def delete_collection(user: User, collection_id: int, recursive: bool = False) - Delete collection given its id. Collection MUST be empty of any content (no children collections and no resources), unless the 'recursive'parameter is set to True. unless the 'recursive'parameter is set to True, in which case ALL descendants will be deleted. """ query_set: Union[Iterator[Collection], QuerySet] = Collection.objects.filter( pk=collection_id, deleted_at__isnull=True Loading Loading @@ -2820,3 +2821,56 @@ def picture_rotate_crop( return serializers.file(reloaded_file, include_metas=False) except pyvips.error.Error: raise ServiceException(CANT_CREATE_IMAGE) @_log_call @_rpc_groups(["Resources", "Collections"]) def remove_items(user: User, parent_collection_id: int, selection: dict = None) -> bool: """ Will mass remove items based on parent collection Use such an object for exclusion: ``` { "exclude": { "resources_ids": [12, 10, 15] "collections_ids:" [4, 254, 17] } } ``` deleteCollection (with recursion) and deleteResource are used under the hood. The parent collection is left as-is. """ if not selection: selection = {} if not parent_collection_id: raise ServiceException(NO_SUCH_COLLECTION) parent_collection = Collection.objects.filter(pk=parent_collection_id).first() if not parent_collection: raise ServiceException(NO_SUCH_COLLECTION) children_collections_set = parent_collection.children() if selection.get("exclude"): if selection["exclude"].get("collections_ids"): children_collections_set = children_collections_set.exclude( id__in=selection["exclude"].get("collections_ids") ) for collection_instance in children_collections_set.all(): delete_collection(user, collection_instance.id, True) res_set = parent_collection.resources.all() if selection.get("exclude"): if selection["exclude"].get("resources_ids"): res_set = res_set.exclude(id__in=selection["exclude"].get("resources_ids")) for resource_instance in res_set.all(): # is resource anywhere else ? if resource_instance.collections.filter(deleted_at__isnull=True).count() < 2: delete_resource(user, resource_instance.id) else: remove_resource_from_collection( user, resource_instance.id, parent_collection.id ) return True