-
Notifications
You must be signed in to change notification settings - Fork 20
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
Custom rest endpoint for Up #1384
Comments
Add Base64ImageField.to_native() to include the full path to the image in any API use and add the option of requesting a thumbnail as part of an API get request. See docstring and comments in to_native() for more details.
The project_up endpoint is tailored to the needs of the Up app. It includes the full primary_location object and allows the requesting of an image thumbnail of arbitrary size using the Base64ImageField.to_native() method.
Test planThis PR adds new functionality to the rest API for the models that have an image, i.e. Project, Organisation and ProjectUpdate. By default the image field for those models now return a path to a thumbnail. This thumb is 191px wide, the format used by the updates on akvo.org. The larger change/addition this feature adds is that it's now possible to request thumbnails and specify their size. The size is specified by either width or height to get the image to scale correctly in the other dimension or to specify both thereby setting an absolute maximum size of the image, while keeping the aspect ratio. Example:An example is the easiest way to show what's going on. Calling ...
"current_image": {
"default": "/media/cache/86/12/8612ee8e96c3f34ea213f8e1f8a06666.jpg",
"big": "/media/cache/39/14/3914d362ec01ac9f8d2f5483457a8ddb.jpg",
"small": "/media/cache/5a/13/5a139c48492af14223ac24c8d7a9aa07.jpg",
"original": "/media/db/project/16/Project_16_current_image_2015-04-07_14.34.24.jpg"
},
... for each project. Adding format=xml to the query and the result looks like: ...
<current_image>
<default>/media/cache/86/12/8612ee8e96c3f34ea213f8e1f8a06666.jpg</default>
<big>/media/cache/39/14/3914d362ec01ac9f8d2f5483457a8ddb.jpg</big>
<small>/media/cache/5a/13/5a139c48492af14223ac24c8d7a9aa07.jpg</small>
<original>/media/db/project/16/Project_16_current_image_2015-04-07_14.34.24.jpg</original>
</current_image>
... Full testingThere are a number of combinations to test. The pattern for the query is thus:
where
Really thorough testing would include generating URLs for all combinations and checking that the generated thumbs are there and have the correct size. I think this is probably overkill though, since the underlying code is essentially the same for all API endpoints. For easier testing it might be better to use the single object API call, Also, because thumbnails aren't created if there is no size specified, the degenerated query ?image_thumb_name=foo will return only the default thumgnail and the original, so this can be used if only the original is needed. Testing UpUp uses this call:
Cache testingTo test the caching of thumbs, tests should include fetching an image using the same query string parameters several times and checking that the image path, and thus the image, is the same. This should hold for different users requesting a thumb with the same parameters and also for the same image using different endpoints, like project_update and project_update_extra. Also test that the thumbnail changes if the original image is updated, for example if Project.current_image is changed. |
See akvo.rest.fields.Base64ImageField.to_native() docstring
And set the default thumb width to 191px.
Catch parsing error in get_thumbnail call Fix a couple of spelling error in the get_thumb logic Change size to max_size for the image size query param when limiting the image in both dimensions Update the docstring to reflect this
[#1384] Project rest endpoint for Up
The old Tastypie based API is struggling when Up requests all projects for large organisations. This is probably due to the nature of the code that returns the data, possibly in combination with Postgres being slower than MySQL for this complicated query.
Since we want to move away from the Tastypie API anyway, this seems like a good time to create a custom endpoint in RSR's new, DRF-based API.
The new endpoint will include the full Project model, including any thumbnails of current_image and also the Primary location as an inline object.
The text was updated successfully, but these errors were encountered: