Changes in / [0fa21cd:5cf7630] in OpenWorkouts-current


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ow/templates/dashboard.pt

    r0fa21cd r5cf7630  
    101101          <tal:c tal:condition="getattr(context, 'picture', None)">
    102102            <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')"
    104104                   width="450" />
    105105            </a>
  • ow/templates/edit_profile.pt

    r0fa21cd r5cf7630  
    4949                      <label for="current_picture" i18n:translate="">
    5050                          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">
    5452                  </tal:c>
    5553                </div>
  • ow/templates/profile.pt

    r0fa21cd r5cf7630  
    1818        <div>
    1919          <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')"
    2121                 width="450" />
    2222          </tal:c>
  • ow/tests/views/test_user.py

    r0fa21cd r5cf7630  
    55from shutil import copyfileobj
    66from unittest.mock import Mock, patch
    7 from io import BytesIO
    87
    98import pytest
     
    1615
    1716from webob.multidict import MultiDict
    18 
    19 from PIL import Image
    2017
    2118from ow.models.root import OpenWorkouts
     
    420417        assert response.status_int == 200
    421418        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 
    449419
    450420    def test_edit_profile_get(self, dummy_request, john):
  • ow/views/user.py

    r0fa21cd r5cf7630  
    33from datetime import datetime, timezone, timedelta
    44from decimal import Decimal
    5 from io import BytesIO
    65
    76from pyramid.httpexceptions import HTTPFound, HTTPNotFound
     
    1211from pyramid_simpleform import Form, State
    1312from pytz import common_timezones
    14 from PIL import Image
    1513
    1614from ..models.user import User
     
    214212    permission='view')
    215213def 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())
    234217
    235218
  • setup.py

    r0fa21cd r5cf7630  
    3131    'pytz',
    3232    'fitparse',
    33     'splinter',
    34     'Pillow'
     33    'splinter'
    3534]
    3635
Note: See TracChangeset for help on using the changeset viewer.