-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Change file/image field serializers to return a dict with additional metadata #115
Conversation
RelationValue to a NamedBlobFile field
|
||
url = u'http://nohost/plone/doc1/@@download/testFileField' | ||
self.assertEqual( | ||
{u'filename': '', |
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.
This part confused me - I wasn't able to set a filename for an atapi.FileField
for the life of me. Does this field type actually support filenames? I wasn't able to find a clear reference for or against that. @buchi you probably know this.
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.
To set the filename, you need to do (also works for AT blob fields):
file.getField('file').get(file).setFilename('newname.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.
@erral thank you, that works. Though after looking at it again, it also seems to work for that field type by passing a keyword argument to the mutator - which I somehow couldn't get to work at first for that field type.
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.
We've been hit several times by the filenames (specially when running large imports), I think it's a bit obscure 😉
@lukasgraf Awesome!!! I will make a release as soon as this pr has been merged! |
aaeeec0
to
6e93384
Compare
I strongly recommend to include the image dimensions in the output. Without the dimensions it's not possible to render "good" image tags. See also Google Page Speed Guide: "If no dimensions are specified in the containing document, or if the dimensions specified don't match those of the actual images, the browser will require a reflow and repaint once the images are downloaded. To prevent reflows, specify the width and height of all images, either in the HTML tag, or in CSS." |
"thumb": "http://localhost:55001/plone/image/@@images/image/thumb", | ||
"tile": "http://localhost:55001/plone/image/@@images/image/tile" | ||
"content-type": "image/png", | ||
"download": "http://localhost:55001/plone/image/@@images/image", |
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.
I would only include either the "download" or the "original" link, because both point to the same url.
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.
Ok, I'll drop the original
scale.
Ok, I'll update the PR to also include image dimensions with the scales. |
@buchi +1 for including the image dimensions. I had the same feeling, but did not want to complain before looking into it. :) As soon as we have framing in place we can minimize the output if we need to... |
6e93384
to
abf9ab4
Compare
|
abf9ab4
to
f043db0
Compare
result = { | ||
'filename': self.field.getFilename(self.context), | ||
'content-type': self.field.getContentType(self.context), | ||
'size': self.field .get_size(self.context), |
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.
unnecessary space after self.field
The returned image dimensions should be the real dimensions of the scaled image and not the scales defined in image scaling. E.g. when scaling an image of size 500 x 400 to an image scale of 200 x 200 the resulting image will have the size 200 x 160, not 200 x 200 because the scaling is maintaining aspect ratio. |
@buchi good point, I'll look into this. |
instead of just the download URL.
instead of just the download URLs to image scales.
f043db0
to
d9d83e6
Compare
Using the
I briefly discussed this with @buchi, and I went with a solution that basically just applies the aspect ratio of the original image to the scale's (usually square) bounding box, which should result in the final scaled image's actual dimensions. There's a couple boundary conditions to handle, but nothing too major:
|
"..." : {} | ||
} | ||
|
||
(For non-square images, those will be the actual scaled images' dimensions, |
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.
I would simply drop this remark because maintaining aspect ratio is not related to square or non-square images. One could also define non-square image sizes (e.g. 600 x 400).
d9d83e6
to
c2d011e
Compare
@buchi updated |
Wohoo! I will go over the docs one last time and do some final checks and then make a first alpha release! |
The Archetypes part of this needs a thorough review, I was struggling slightly with the different File / Image field type's APIs.
This changes the serialization format for file and image fields from returning a simple string to returning dictionaries that contain the download URL in a
download
key, according to #9 and #10.There's also a change in behavior regarding empty file / image fields: Previously, those were still serialized to an URL that would have returned a 404 (or 500, not exactly sure). Now they'll be serialized to
None
.