-
Notifications
You must be signed in to change notification settings - Fork 41
api/rest.py: Add URLs to access attachments #1108
Conversation
2fcf44c
to
eeb2fdd
Compare
Noticed there were some issues with the previously pushed version of this code, so have changed approach. As a temporary solution, I have added an extra field which builds the url for accessing attachments. This successfully fulfils the requirement of adding a downloadable link, but doesn't look like the cleanest solution when compared to how other file downloads are handled in the code. I will explore more to see if there is a cleaner approach. |
eeb2fdd
to
808a2e5
Compare
808a2e5
to
c736fc7
Compare
c736fc7
to
e111ed0
Compare
@chaws I've added a test case to check the download url works & updated the previous attachments test case to include the download url - let me know if this looks ok or if any other changes would be required. |
e111ed0
to
38f69bd
Compare
class Meta: | ||
model = Attachment | ||
fields = ('filename', 'mimetype', 'length') | ||
fields = ('download_url', 'filename', 'mimetype', 'length') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need the 'filename' field here, that is in the download_url now or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it wouldn't hurt I think it's fine IMHO
Attachments can be accessed via testruns, by adding "attachments?filename=<filename>" to the end of the testrun URL. However, this is quite unintuitive and prone to user error. Add a "download_url" field to attachments, which creates a download URL in each file's entry in the attachments list. Signed-off-by: Katie Worton <[email protected]>
38f69bd
to
e6af066
Compare
filename = 'foo.txt' | ||
attachment = self.test_run.attachments.create(filename=filename, length=len(data), mimetype="text/plain") | ||
attachment.save_file(filename, data) | ||
# NOTE: /api/testruns/%s/attachments?filename=foo.txt redirects to /api/testruns/%s/attachments/?filename=foo.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
LGTM! I'll merge it and make 1.76.1 release so you can use it in your squad-client patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
WIP draft of support for accessing attachments. Adds an AttachmentViewSet so a hyperlink can be created.
Work in progress as I have not yet figured out how to combine the url and the filename to create a clickable link directly to the file.