Merge branch 'devel' into 'master'

Pull in latest devel

Closes #49

See merge request oliver/ivatar!126
This commit is contained in:
Oliver Falk
2019-02-28 17:28:42 +01:00
4 changed files with 19 additions and 8 deletions

View File

@@ -37,10 +37,10 @@ from .gravatar import get_photo as get_gravatar_photo
def file_format(image_type):
'''
Helper method returning a 3 character long image type
Helper method returning a short image type
'''
if image_type == 'JPEG':
return 'jpg'
return 'jpeg'
elif image_type == 'PNG':
return 'png'
elif image_type == 'GIF':
@@ -52,7 +52,7 @@ def pil_format(image_type):
'''
Helper method returning the 'encoder name' for PIL
'''
if image_type == 'jpg':
if image_type == 'jpg' or image_type == 'jpeg':
return 'JPEG'
elif image_type == 'png':
return 'PNG'

View File

@@ -358,7 +358,7 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
# Probably not the best way to access the content type
self.assertEqual(
response['Content-Type'],
'image/jpg',
'image/jpeg',
'Content type wrong!?')
self.assertEqual(
@@ -638,10 +638,10 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
self.assertEqual(
str(list(response.context[0]['messages'])[0]),
'Successfully uploaded',
'JPG upload failed?!')
'JPEG upload failed?!')
self.assertEqual(
self.user.photo_set.first().format, 'jpg',
'Format must be jpg, since we uploaded a jpg!')
self.user.photo_set.first().format, 'jpeg',
'Format must be jpeg, since we uploaded a jpeg!')
self.test_confirm_email()
self.user.confirmedemail_set.first().photo = self.user.photo_set.first()
urlobj = urlsplit(

View File

@@ -18,7 +18,7 @@ from PIL import Image
from monsterid.id import build_monster as BuildMonster
import Identicon
from pydenticon5 import Pydenticon5
import pagan
from robohash import Robohash
from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE
@@ -166,6 +166,16 @@ class AvatarImageView(TemplateView):
data,
content_type='image/png')
if str(default) == 'pagan':
paganobj = pagan.Avatar(kwargs['digest'])
data = BytesIO()
img = paganobj.img.resize((size, size), Image.ANTIALIAS)
img.save(data, 'PNG', quality=JPEG_QUALITY)
data.seek(0)
return HttpResponse(
data,
content_type='image/png')
if str(default) == 'identicon':
p = Pydenticon5()
# In order to make use of the whole 32 bytes digest, we need to redigest them.

View File

@@ -37,3 +37,4 @@ git+https://github.com/ofalk/Robohash.git@devel
python-memcached
git+https://github.com/ercpe/pydenticon5.git
git+https://github.com/flavono123/identicon.git
pagan