Skip to content

Commit bc11677

Browse files
authored
Merge pull request #1578 from ImageMarkup/data-explorer-add-to-collection
Allow the data explorer to add to existing collections
2 parents 2f83b38 + b8f20bd commit bc11677

5 files changed

Lines changed: 413 additions & 84 deletions

File tree

isic/core/api/collection.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ def collection_list(
7676
return queryset
7777

7878

79+
IsicIds = Annotated[list[Annotated[str, Field(pattern=ISIC_ID_REGEX)]], Field(min_length=1)]
80+
81+
7982
class CreateCollectionFromIsicIdsIn(Schema):
8083
name: str
8184
description: str = ""
82-
isic_ids: Annotated[list[Annotated[str, Field(pattern=ISIC_ID_REGEX)]], Field(min_length=1)]
85+
isic_ids: IsicIds
8386

8487
model_config = {"extra": "forbid"}
8588

@@ -297,6 +300,41 @@ def collection_populate_from_search(request, id: int, payload: SearchQueryIn):
297300
return 202, {}
298301

299302

303+
class PopulateCollectionFromIsicIdsIn(Schema):
304+
isic_ids: IsicIds
305+
306+
model_config = {"extra": "forbid"}
307+
308+
309+
@router.post(
310+
"/{id}/populate-from-isic-ids/",
311+
response={202: None, 403: dict, 409: dict},
312+
include_in_schema=False,
313+
auth=is_authenticated,
314+
)
315+
def collection_populate_from_isic_ids(request, id: int, payload: PopulateCollectionFromIsicIdsIn):
316+
qs = get_visible_objects(request.user, "core.view_collection", Collection.objects.all())
317+
collection = get_object_or_404(qs.distinct(), id=id)
318+
319+
if not request.user.has_perm("core.add_images", collection):
320+
return 403, {"error": "You do not have permission to add images to this collection."}
321+
322+
if collection.locked:
323+
return 409, {"error": "Collection is locked"}
324+
325+
populate_collection_from_isic_ids_task.delay_on_commit(
326+
collection.pk, request.user.pk, payload.isic_ids
327+
)
328+
329+
messages.add_message(
330+
request,
331+
messages.INFO,
332+
f"Adding {len(payload.isic_ids)} images to '{collection.name}', this may take a few minutes.", # noqa: E501
333+
)
334+
335+
return 202, {}
336+
337+
300338
class SetPinnedIn(Schema):
301339
pinned: bool
302340

0 commit comments

Comments
 (0)