Changes in / [0fa21cd:5cf7630] in OpenWorkouts-current
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/templates/dashboard.pt
r0fa21cd r5cf7630 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' , query={'size': 200})"103 <img tal:attributes="src request.resource_path(context, 'picture')" 104 104 width="450" /> 105 105 </a> -
ow/templates/edit_profile.pt
r0fa21cd r5cf7630 49 49 <label for="current_picture" i18n:translate=""> 50 50 Current picture:</label> 51 <img id="current_picture" 52 tal:attributes="src request.resource_path(context, 'picture', query={'size': 200})" 53 width="150"> 51 <img id="current_picture" tal:attributes="src request.resource_path(context, 'picture')" width="150"> 54 52 </tal:c> 55 53 </div> -
ow/templates/profile.pt
r0fa21cd r5cf7630 18 18 <div> 19 19 <tal:c tal:condition="getattr(user, 'picture', None)"> 20 <img tal:attributes="src request.resource_path(user, 'picture' , query={'size': 200})"20 <img tal:attributes="src request.resource_path(user, 'picture')" 21 21 width="450" /> 22 22 </tal:c> -
ow/tests/views/test_user.py
r0fa21cd r5cf7630 5 5 from shutil import copyfileobj 6 6 from unittest.mock import Mock, patch 7 from io import BytesIO8 7 9 8 import pytest … … 16 15 17 16 from webob.multidict import MultiDict 18 19 from PIL import Image20 17 21 18 from ow.models.root import OpenWorkouts … … 420 417 assert response.status_int == 200 421 418 assert response.content_type == 'image' 422 # as we did not pass a specific size as a get parameter, the size is423 # the same as the original image424 original_image = Image.open(image_path)425 returned_image = Image.open(BytesIO(response.body))426 assert original_image.size == returned_image.size427 428 # now, ask for a smaller image429 request.GET['size'] = original_image.size[0] - 20430 response = user_views.profile_picture(user, request)431 assert isinstance(response, Response)432 assert response.status_int == 200433 assert response.content_type == 'image'434 # now the size of the original image is bigger435 returned_image = Image.open(BytesIO(response.body))436 assert original_image.size > returned_image.size437 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 size440 request.GET['size'] = original_image.size[0] + 1000441 response = user_views.profile_picture(user, request)442 assert isinstance(response, Response)443 assert response.status_int == 200444 assert response.content_type == 'image'445 # now the size of the original image is bigger446 returned_image = Image.open(BytesIO(response.body))447 assert original_image.size == returned_image.size448 449 419 450 420 def test_edit_profile_get(self, dummy_request, john): -
ow/views/user.py
r0fa21cd r5cf7630 3 3 from datetime import datetime, timezone, timedelta 4 4 from decimal import Decimal 5 from io import BytesIO6 5 7 6 from pyramid.httpexceptions import HTTPFound, HTTPNotFound … … 12 11 from pyramid_simpleform import Form, State 13 12 from pytz import common_timezones 14 from PIL import Image15 13 16 14 from ..models.user import User … … 214 212 permission='view') 215 213 def profile_picture(context, request): 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()) 214 return Response( 215 content_type='image', 216 body_file=context.picture.open()) 234 217 235 218 -
setup.py
r0fa21cd r5cf7630 31 31 'pytz', 32 32 'fitparse', 33 'splinter', 34 'Pillow' 33 'splinter' 35 34 ] 36 35
Note: See TracChangeset
for help on using the changeset viewer.