{"action":"created","issue":{"url":"https://api.github.com/repos/akvo/akvo-rsr/issues/1384","labels_url":"https://api.github.com/repos/akvo/akvo-rsr/issues/1384/labels{/name}","comments_url":"https://api.github.com/repos/akvo/akvo-rsr/issues/1384/comments","events_url":"https://api.github.com/repos/akvo/akvo-rsr/issues/1384/events","html_url":"https://github.com/akvo/akvo-rsr/issues/1384","id":65463217,"number":1384,"title":"Custom rest endpoint for Up","user":{"login":"zzgvh","id":142613,"avatar_url":"https://avatars.githubusercontent.com/u/142613?v=3","gravatar_id":"","url":"https://api.github.com/users/zzgvh","html_url":"https://github.com/zzgvh","followers_url":"https://api.github.com/users/zzgvh/followers","following_url":"https://api.github.com/users/zzgvh/following{/other_user}","gists_url":"https://api.github.com/users/zzgvh/gists{/gist_id}","starred_url":"https://api.github.com/users/zzgvh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzgvh/subscriptions","organizations_url":"https://api.github.com/users/zzgvh/orgs","repos_url":"https://api.github.com/users/zzgvh/repos","events_url":"https://api.github.com/users/zzgvh/events{/privacy}","received_events_url":"https://api.github.com/users/zzgvh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/akvo/akvo-rsr/labels/In%20Progress","name":"In Progress","color":"fef2c0"}],"state":"open","locked":false,"assignee":{"login":"zzgvh","id":142613,"avatar_url":"https://avatars.githubusercontent.com/u/142613?v=3","gravatar_id":"","url":"https://api.github.com/users/zzgvh","html_url":"https://github.com/zzgvh","followers_url":"https://api.github.com/users/zzgvh/followers","following_url":"https://api.github.com/users/zzgvh/following{/other_user}","gists_url":"https://api.github.com/users/zzgvh/gists{/gist_id}","starred_url":"https://api.github.com/users/zzgvh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzgvh/subscriptions","organizations_url":"https://api.github.com/users/zzgvh/orgs","repos_url":"https://api.github.com/users/zzgvh/repos","events_url":"https://api.github.com/users/zzgvh/events{/privacy}","received_events_url":"https://api.github.com/users/zzgvh/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/akvo/akvo-rsr/milestones/46","html_url":"https://github.com/akvo/akvo-rsr/milestones/3.2%20Flying%20Fish%20Cove","labels_url":"https://api.github.com/repos/akvo/akvo-rsr/milestones/46/labels","id":993145,"number":46,"title":"3.2 Flying Fish Cove","description":"","creator":{"login":"KasperBrandt","id":1497367,"avatar_url":"https://avatars.githubusercontent.com/u/1497367?v=3","gravatar_id":"","url":"https://api.github.com/users/KasperBrandt","html_url":"https://github.com/KasperBrandt","followers_url":"https://api.github.com/users/KasperBrandt/followers","following_url":"https://api.github.com/users/KasperBrandt/following{/other_user}","gists_url":"https://api.github.com/users/KasperBrandt/gists{/gist_id}","starred_url":"https://api.github.com/users/KasperBrandt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KasperBrandt/subscriptions","organizations_url":"https://api.github.com/users/KasperBrandt/orgs","repos_url":"https://api.github.com/users/KasperBrandt/repos","events_url":"https://api.github.com/users/KasperBrandt/events{/privacy}","received_events_url":"https://api.github.com/users/KasperBrandt/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":17,"state":"open","created_at":"2015-02-24T10:33:34Z","updated_at":"2015-04-07T09:14:06Z","due_on":"2015-04-08T22:00:00Z","closed_at":null},"comments":1,"created_at":"2015-03-31T14:21:23Z","updated_at":"2015-04-07T20:20:42Z","closed_at":null,"body":"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.\r\n\r\nSince 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.\r\n\r\nThe new endpoint will include the full Project model, including any thumbnails of current_image and also the Primary location as an inline object."},"comment":{"url":"https://api.github.com/repos/akvo/akvo-rsr/issues/comments/90719369","html_url":"https://github.com/akvo/akvo-rsr/issues/1384#issuecomment-90719369","issue_url":"https://api.github.com/repos/akvo/akvo-rsr/issues/1384","id":90719369,"user":{"login":"zzgvh","id":142613,"avatar_url":"https://avatars.githubusercontent.com/u/142613?v=3","gravatar_id":"","url":"https://api.github.com/users/zzgvh","html_url":"https://github.com/zzgvh","followers_url":"https://api.github.com/users/zzgvh/followers","following_url":"https://api.github.com/users/zzgvh/following{/other_user}","gists_url":"https://api.github.com/users/zzgvh/gists{/gist_id}","starred_url":"https://api.github.com/users/zzgvh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzgvh/subscriptions","organizations_url":"https://api.github.com/users/zzgvh/orgs","repos_url":"https://api.github.com/users/zzgvh/repos","events_url":"https://api.github.com/users/zzgvh/events{/privacy}","received_events_url":"https://api.github.com/users/zzgvh/received_events","type":"User","site_admin":false},"created_at":"2015-04-07T20:20:42Z","updated_at":"2015-04-07T20:20:42Z","body":"## Test plan\r\n\r\nThis PR adds new functionality to the rest API for the models that have an image, i.e. Project, Organisation and ProjectUpdate. It is now possible request an image thumbnail and specify its size, either by specifying width **or** height to get the image to scale correctly in the other dimension or to specify both, but then risking that it becomes \"squashed\" if the width:height ratio doesn't match the original.\r\n\r\nTo get a thumbnail add the key *image_thumb_name* to the query string part of the request, followed by *width* and/or *height*. \r\n\r\n#### Example:\r\n\r\nCalling ```http://test./rest/v1/project/?image_thumb_name=small&width=120``` should result in the returned JSON including somthing like\r\n```json\r\n...\r\n    \"current_image\": {\r\n        \"original\": \"/media/db/project/2/Project_2_current_image_2009-04-20_23.44.38.jpg\",\r\n        \"small\": \"/media/cache/73/df/73dfcdb34d9b2aa658b0ce713040369e.jpg\"\r\n    }\r\n...\r\n```\r\nfor each project. Adding format=xml to the query looks like:\r\n```xml\r\n...\r\n<current_image>\r\n    <small>/media/cache/73/df/73dfcdb34d9b2aa658b0ce713040369e.jpg</small>\r\n    <original>/media/db/project/16/Project_16_current_image_2015-04-07_14.34.24.jpg</original>\r\n</current_image>\r\n...\r\n```\r\n### Full testing\r\n\r\nThere are a number of combinations to test:\r\n```\r\n/rest/v1/<endpoint>/format=<API format>&image_thumb_name=<thumb identifier>&width=<thumb width>\r\n/rest/v1/<endpoint>/format=<API format>&image_thumb_name=<thumb identifier>&height=<thumb height>\r\n/rest/v1/<endpoint>/format=<API format>&image_thumb_name=<thumb identifier>&width=<thumb width>&height=<thumb height>\r\n```\r\nwhere &lt;endpoint&gt; is one of **organisation**, **project**, **project_extra**, **project_up**, **project_update** or **project_update_extra**, &lt;API format&gt; is **json** (default, can be omitted) or **xml** and &lt;thumb width&gt; and &lt;thumb height&gt; are the value of that dimension as an integer. &lt;thumb identifier&gt; is the identifier is used in the returned data structure, either a JSON field name or an XML tag.\r\n\r\nReally thorough testing would include running all those URLs in 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.\r\n\r\n### Testing Up\r\nUp uses this call:\r\n```\r\n/rest/v1/project_up/format=xml&image_thumb_name=<thumb identifier>&width=<thumb width>\r\n```\r\nwhere &lt;thumb identifier&gt; should match the thumbnail tag in the Up XML parser and &lt;thumb width&gt; should be the width the image is to have in the app.\r\n\r\n### Cache testing\r\nTo 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**.\r\n\r\nAlso test that the thumbnail *changes* if the original image is updated, for example if Project.current_image is changed.\r\n\r\n"}}