Changeset f0e64eb in OpenWorkouts-current
- Timestamp:
- Feb 15, 2019, 11:00:35 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- 0fa21cd
- Parents:
- eb20dc8
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/templates/dashboard.pt
reb20dc8 rf0e64eb 101 101 <tal:c tal:condition="getattr(context, 'picture', None)"> 102 102 <a href="" tal:attributes="href request.resource_url(context, 'profile')"> 103 <img tal:attributes="src request.resource_path(context, 'picture' )"103 <img tal:attributes="src request.resource_path(context, 'picture', query={'size': 200})" 104 104 width="450" /> 105 105 </a> -
ow/templates/edit_profile.pt
reb20dc8 rf0e64eb 49 49 <label for="current_picture" i18n:translate=""> 50 50 Current picture:</label> 51 <img id="current_picture" tal:attributes="src request.resource_path(context, 'picture')" width="150"> 51 <img id="current_picture" 52 tal:attributes="src request.resource_path(context, 'picture', query={'size': 200})" 53 width="150"> 52 54 </tal:c> 53 55 </div> -
ow/templates/profile.pt
reb20dc8 rf0e64eb 18 18 <div> 19 19 <tal:c tal:condition="getattr(user, 'picture', None)"> 20 <img tal:attributes="src request.resource_path(user, 'picture' )"20 <img tal:attributes="src request.resource_path(user, 'picture', query={'size': 200})" 21 21 width="450" /> 22 22 </tal:c> -
ow/tests/views/test_user.py
reb20dc8 rf0e64eb 5 5 from shutil import copyfileobj 6 6 from unittest.mock import Mock, patch 7 from io import BytesIO 7 8 8 9 import pytest … … 15 16 16 17 from webob.multidict import MultiDict 18 19 from PIL import Image 17 20 18 21 from ow.models.root import OpenWorkouts … … 417 420 assert response.status_int == 200 418 421 assert response.content_type == 'image' 422 # as we did not pass a specific size as a get parameter, the size is 423 # the same as the original image 424 original_image = Image.open(image_path) 425 returned_image = Image.open(BytesIO(response.body)) 426 assert original_image.size == returned_image.size 427 428 # now, ask for a smaller image 429 request.GET['size'] = original_image.size[0] - 20 430 response = user_views.profile_picture(user, request) 431 assert isinstance(response, Response) 432 assert response.status_int == 200 433 assert response.content_type == 'image' 434 # now the size of the original image is bigger 435 returned_image = Image.open(BytesIO(response.body)) 436 assert original_image.size > returned_image.size 437 438 # now, ask for a size that is bigger than the original image, 439 # image will be the same size, as we do not "grow" its size 440 request.GET['size'] = original_image.size[0] + 1000 441 response = user_views.profile_picture(user, request) 442 assert isinstance(response, Response) 443 assert response.status_int == 200 444 assert response.content_type == 'image' 445 # now the size of the original image is bigger 446 returned_image = Image.open(BytesIO(response.body)) 447 assert original_image.size == returned_image.size 448 419 449 420 450 def test_edit_profile_get(self, dummy_request, john): -
ow/views/user.py
reb20dc8 rf0e64eb 3 3 from datetime import datetime, timezone, timedelta 4 4 from decimal import Decimal 5 from io import BytesIO 5 6 6 7 from pyramid.httpexceptions import HTTPFound, HTTPNotFound … … 11 12 from pyramid_simpleform import Form, State 12 13 from pytz import common_timezones 14 from PIL import Image 13 15 14 16 from ..models.user import User … … 212 214 permission='view') 213 215 def profile_picture(context, request): 214 return Response( 215 content_type='image', 216 body_file=context.picture.open()) 216 if context.picture is None: 217 return HTTPNotFound() 218 219 size = request.GET.get('size', 0) 220 # we will need a tuple, it does not matter if both values are the same, 221 # Pillow will keep aspect ratio 222 size = (int(size), int(size)) 223 224 image = Image.open(context.picture.open()) 225 226 if size > (0, 0) and size < image.size: 227 # resize only if they are asking for smaller size, prevent 228 # someone asking for a "too big" image 229 image.thumbnail(size) 230 231 body_file = BytesIO() 232 image.save(body_file, format=image.format) 233 return Response(content_type='image', body=body_file.getvalue()) 217 234 218 235 -
setup.py
reb20dc8 rf0e64eb 31 31 'pytz', 32 32 'fitparse', 33 'splinter' 33 'splinter', 34 'Pillow' 34 35 ] 35 36
Note: See TracChangeset
for help on using the changeset viewer.