|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Dict, List, Optional, Union, cast |
| 4 | +from uuid import UUID |
| 5 | + |
| 6 | +from darwin.future.core.items.delete_items import delete_list_of_items |
| 7 | +from darwin.future.data_objects.item import ItemCore, ItemLayout, ItemSlot |
| 8 | +from darwin.future.meta.objects.base import MetaBase |
| 9 | + |
| 10 | + |
| 11 | +class Item(MetaBase[ItemCore]): |
| 12 | + """ |
| 13 | + Represents an item in a Darwin dataset. |
| 14 | +
|
| 15 | + Args: |
| 16 | + MetaBase (Stage): Generic MetaBase object expanded by ItemCore object |
| 17 | + return type |
| 18 | +
|
| 19 | + Attributes: |
| 20 | + name (str): The name of the item. |
| 21 | + id (UUID): The unique identifier of the item. |
| 22 | + slots (List[ItemSlot]): A list of slots associated with the item. |
| 23 | + path (str): The path of the item. |
| 24 | + dataset_id (int): The ID of the dataset the item belongs to. |
| 25 | + processing_status (str): The processing status of the item. |
| 26 | + archived (Optional[bool]): Whether the item is archived or not. |
| 27 | + priority (Optional[int]): The priority of the item. |
| 28 | + tags (Optional[Union[List[str], Dict[str, str]]]): The tags associated with the item. |
| 29 | + layout (Optional[ItemLayout]): The layout of the item. |
| 30 | +
|
| 31 | + Methods: |
| 32 | + delete(self) -> None: |
| 33 | + Deletes the item from the Darwin dataset. |
| 34 | +
|
| 35 | + Example usage: |
| 36 | + # Get the item object |
| 37 | + items = workflow.items.where(name='test').collect() # gets first page of items |
| 38 | +
|
| 39 | + # Delete the items |
| 40 | + [item.delete() for item in items] # will collect all pages of items and delete individually |
| 41 | +
|
| 42 | + """ |
| 43 | + |
| 44 | + def delete(self) -> None: |
| 45 | + team_slug, dataset_id = ( |
| 46 | + self.meta_params["team_slug"], |
| 47 | + self.meta_params["dataset_id"] |
| 48 | + if "dataset_id" in self.meta_params |
| 49 | + else self.meta_params["dataset_ids"], |
| 50 | + ) |
| 51 | + assert isinstance(team_slug, str) |
| 52 | + dataset_id = cast(Union[int, List[int]], dataset_id) |
| 53 | + filters = {"item_ids": [str(self.id)]} |
| 54 | + delete_list_of_items(self.client, team_slug, dataset_id, filters) |
| 55 | + |
| 56 | + @property |
| 57 | + def name(self) -> str: |
| 58 | + return self._element.name |
| 59 | + |
| 60 | + @property |
| 61 | + def id(self) -> UUID: |
| 62 | + return self._element.id |
| 63 | + |
| 64 | + @property |
| 65 | + def slots(self) -> List[ItemSlot]: |
| 66 | + return self._element.slots |
| 67 | + |
| 68 | + @property |
| 69 | + def path(self) -> str: |
| 70 | + return self._element.path |
| 71 | + |
| 72 | + @property |
| 73 | + def dataset_id(self) -> int: |
| 74 | + return self._element.dataset_id |
| 75 | + |
| 76 | + @property |
| 77 | + def processing_status(self) -> str: |
| 78 | + return self._element.processing_status |
| 79 | + |
| 80 | + @property |
| 81 | + def archived(self) -> Optional[bool]: |
| 82 | + return self._element.archived |
| 83 | + |
| 84 | + @property |
| 85 | + def priority(self) -> Optional[int]: |
| 86 | + return self._element.priority |
| 87 | + |
| 88 | + @property |
| 89 | + def tags(self) -> Optional[Union[List[str], Dict[str, str]]]: |
| 90 | + return self._element.tags |
| 91 | + |
| 92 | + @property |
| 93 | + def layout(self) -> Optional[ItemLayout]: |
| 94 | + return self._element.layout |
0 commit comments