Commit c4b98f06 authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

add inclusion for move_selection/remove_selection

parent 68f8e31c
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -2836,10 +2836,14 @@ def remove_selection(user: User, parent_collection_id: int, selection: dict) ->
    """
    Will mass remove items based on parent collection

    Use such an object for exclusion:
    Use such an object for inclusion/exclusion:

    ```
    {
        "include": {
            "resources_ids": [3493, 159]
            "collections_ids:" [20, 31]
        },
        "exclude": {
            "resources_ids": [12, 10, 15]
            "collections_ids:" [4, 254, 17]
@@ -2860,6 +2864,12 @@ def remove_selection(user: User, parent_collection_id: int, selection: dict) ->
        raise ServiceException(NO_SUCH_COLLECTION)

    children_collections_set = parent_collection.children()

    if selection.get("include"):
        if selection["include"].get("collections_ids"):
            children_collections_set = children_collections_set.filter(
                id__in=selection["include"].get("collections_ids")
            )
    if selection.get("exclude"):
        if selection["exclude"].get("collections_ids"):
            children_collections_set = children_collections_set.exclude(
@@ -2869,6 +2879,9 @@ def remove_selection(user: User, parent_collection_id: int, selection: dict) ->
        delete_collection(user, collection_instance.id, True)

    res_set = parent_collection.resources.all()
    if selection.get("include"):
        if selection["include"].get("resources_ids"):
            res_set = res_set.filter(id__in=selection["include"].get("resources_ids"))
    if selection.get("exclude"):
        if selection["exclude"].get("resources_ids"):
            res_set = res_set.exclude(id__in=selection["exclude"].get("resources_ids"))
@@ -2891,10 +2904,14 @@ def move_selection(
    """
    Will mass move items based on parent collection and destination collection

    Use such an object for exclusion:
    Use such an object for inclusion/exclusion:

    ```
    {
        "include": {
            "resources_ids": [3493, 159]
            "collections_ids:" [20, 31]
        },
        "exclude": {
            "resources_ids": [12, 10, 15]
            "collections_ids:" [4, 254, 17]
@@ -2916,6 +2933,11 @@ def move_selection(
        raise ServiceException(NO_SUCH_COLLECTION)

    children_collections_set = parent_collection.children()
    if selection.get("include"):
        if selection["include"].get("collections_ids"):
            children_collections_set = children_collections_set.filter(
                id__in=selection["include"].get("collections_ids")
            )
    if selection.get("exclude"):
        if selection["exclude"].get("collections_ids"):
            children_collections_set = children_collections_set.exclude(
@@ -2926,6 +2948,9 @@ def move_selection(
        collections_ids.append(collection_instance.id)

    res_set = parent_collection.resources.all()
    if selection.get("include"):
        if selection["include"].get("resources_ids"):
            res_set = res_set.filter(id__in=selection["include"].get("resources_ids"))
    if selection.get("exclude"):
        if selection["exclude"].get("resources_ids"):
            res_set = res_set.exclude(id__in=selection["exclude"].get("resources_ids"))