Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding delete function for Attachment Cursors #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion swimlane/core/fields/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,6 +34,24 @@ def add(self, filename, stream, content_type=None):

return attachment

def delete(self, attachment):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is not issue linked or jira ticket, can some information be added to the PR about why and example usage?
Will there be unit tests for this functionality?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an important functionality to add.

  1. The main use case I can think of is if you are syncing records between instances / applications and a parent record attachments have been deleted, you would want it to replicate in the child record(s).
  2. Another use case could be for record ingestion. For example, if you are ingesting an email which has attachments and a record is created but you still have yet to parse that data, if the record has attachments, but you only want attachments of a particular type, then deleting it when parsing the record would be beneficial.

"""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):

Expand Down