Attachments
albert.collections.attachments.AttachmentCollection
Bases: BaseCollection
AttachmentCollection is a collection class for managing Attachment entities in the Albert platform.
Methods:
Name | Description |
---|---|
get_by_id |
Retrieves an attachment by its ID. |
get_by_parent_ids |
Retrieves attachments by their parent IDs. |
attach_file_to_note |
Attaches an already uploaded file to a note. |
delete |
Deletes an attachment by ID. |
upload_and_attach_file_as_note |
Uploads a file and attaches it to a new note. A user can be tagged in the note_text string by using f-string and the User.to_note_mention() method. |
upload_and_attach_sds_to_inventory_item |
Upload an SDS document and attach it to an inventory item. |
Attributes:
Name | Type | Description |
---|---|---|
base_path |
|
Source code in src/albert/collections/attachments.py
get_by_id
get_by_id(*, id: AttachmentId) -> Attachment
Retrieves an attachment by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
AttachmentId
|
The ID of the attachment to retrieve. |
required |
Returns:
Type | Description |
---|---|
Attachment
|
The Attachment object corresponding to the provided ID. |
Source code in src/albert/collections/attachments.py
get_by_parent_ids
Retrieves attachments by their parent IDs.
Note: This method returns a dictionary where the keys are parent IDs and the values are lists of Attachment objects associated with each parent ID. If the parent ID has no attachments, it will not be included in the dictionary.
If no attachments are found for any of the provided parent IDs, the API response will be an error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_ids
|
list[str]
|
Parent IDs of the objects to which the attachments are linked. |
required |
Returns:
Type | Description |
---|---|
dict[str, list[Attachment]]
|
A dictionary mapping parent IDs to lists of Attachment objects associated with each parent ID. |
Source code in src/albert/collections/attachments.py
attach_file_to_note
attach_file_to_note(
*,
note_id: str,
file_name: str,
file_key: str,
category: FileCategory = OTHER,
) -> Attachment
Attaches an already uploaded file to a note.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
note_id
|
str
|
The ID of the note to attach the file to. |
required |
file_name
|
str
|
The name of the file to attach. |
required |
file_key
|
str
|
The unique key of the file to attach (the returned upload name). |
required |
category
|
FileCategory
|
The type of file, by default FileCategory.OTHER |
OTHER
|
Returns:
Type | Description |
---|---|
Attachment
|
The related attachment object. |
Source code in src/albert/collections/attachments.py
delete
delete(*, id: AttachmentId) -> None
Deletes an attachment by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The ID of the attachment to delete. |
required |
Source code in src/albert/collections/attachments.py
upload_and_attach_file_as_note
upload_and_attach_file_as_note(
parent_id: str,
file_data: IO,
note_text: str = "",
file_name: str = "",
) -> Note
Uploads a file and attaches it to a new note. A user can be tagged in the note_text string by using f-string and the User.to_note_mention() method. This allows for easy tagging and referencing of users within notes. example: f"Hello {tagged_user.to_note_mention()}!"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_id
|
str
|
The ID of the parent entity onto which the note will be attached. |
required |
file_data
|
IO
|
The file data to upload. |
required |
note_text
|
str
|
Any additional text to add to the note, by default "" |
''
|
file_name
|
str
|
The name of the file, by default "" |
''
|
Returns:
Type | Description |
---|---|
Note
|
The created note. |
Source code in src/albert/collections/attachments.py
upload_and_attach_sds_to_inventory_item
upload_and_attach_sds_to_inventory_item(
*,
inventory_id: InventoryId,
file_sds: Path,
revision_date: date,
storage_class: str,
un_number: str,
jurisdiction_code: str = "US",
language_code: str = "EN",
hazard_statements: list[HazardStatement] | None = None,
hazard_symbols: list[HazardSymbol] | None = None,
wgk: str | None = None,
) -> Attachment
Upload an SDS document and attach it to an inventory item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inventory_id
|
str
|
Id of Inventory Item to attach SDS to. |
required |
file_sds
|
Path
|
Local path to the SDS PDF to upload. |
required |
revision_date
|
date
|
Revision date for the SDS. (yyyy-mm-dd) |
required |
un_number
|
str
|
The UN number. |
required |
storage_class
|
str
|
The Storage Class number. |
required |
jurisdiction_code
|
str | None
|
Jurisdiction code associated with the SDS (e.g. |
'US'
|
language_code
|
str
|
Language code for the SDS (e.g. |
'EN'
|
hazard_statements
|
list[HazardStatement] | None
|
Collection of hazard statements. |
None
|
wgk
|
str | None
|
WGK classification metadata. |
None
|
Source code in src/albert/collections/attachments.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|