From 78a35187eb10975b07389e127e680cdf9d2bd5e8 Mon Sep 17 00:00:00 2001 From: Justin Ezawa Date: Wed, 21 Oct 2020 17:51:54 -0700 Subject: [PATCH] Adding delete function for Attachment Cursors --- swimlane/core/fields/attachment.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/swimlane/core/fields/attachment.py b/swimlane/core/fields/attachment.py index 1f956488..9aeb5e76 100644 --- a/swimlane/core/fields/attachment.py +++ b/swimlane/core/fields/attachment.py @@ -5,7 +5,7 @@ class AttachmentCursor(FieldCursor): - """Allows creation and iteration of attachments""" + """Allows creation, deletion, and iteration of attachments""" def add(self, filename, stream, content_type=None): """Upload a new attachment, and add it to current fields raw data to be persisted on save @@ -34,6 +34,24 @@ def add(self, filename, stream, content_type=None): return attachment + def delete(self, attachment): + """Deletes an attachment and removes it from the current field to be persisted on save + + Args: + attachment (swimlane.core.resources.attachment.Attachment): Abstraction of an attachment from an AttachmentsField + """ + + file_id = attachment.file_id + response = self._record._swimlane.request( + 'DELETE', + 'attachment/{}'.format(file_id) + ) + + self._elements.remove(attachment) + + self._sync_field() + + class AttachmentsField(MultiSelectField):