From 154ed0c4f9fa6032bfda7977b3fbb8230c3a1720 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 20 Feb 2019 19:25:39 +0100 Subject: [PATCH 1/3] Make padding better, depending on the size; Fixes #48 --- ivatar/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ivatar/views.py b/ivatar/views.py index 300d267..db0be2d 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -157,6 +157,10 @@ class AvatarImageView(TemplateView): 'rgb(141,69,170)'] background = 'rgb(224,224,224)' padwidth = int(size/10) + if padwidth < 10: + padwidth = 10 + if size < 60: + padwidth = 0 padding = (padwidth, padwidth, padwidth, padwidth) # Since padding is _added_ around the generated image, we # need to reduce the image size by padding*2 (left/right, top/bottom) From bfaa79c0c4b2585e101c284d9cc2e2640bf57731 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 20 Feb 2019 21:29:41 +0100 Subject: [PATCH 2/3] Regression from fixing #45. Closes #45 again. --- ivatar/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ivatar/views.py b/ivatar/views.py index db0be2d..f330c34 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -221,7 +221,7 @@ class GravatarProxyView(View): url = reverse_lazy( 'avatar_view', args=[kwargs['digest']]) + '?s=%i' % size + '&forcedefault=y' - if default: + if default != None: url += '&default=%s' % default return HttpResponseRedirect(url) @@ -230,7 +230,8 @@ class GravatarProxyView(View): default = None try: - default = request.GET['default'] + if str(request.GET['default']) != 'None': + default = request.GET['default'] except: pass From 05f32f1011f2ef031bab34138f0147e19f0a0701 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 20 Feb 2019 21:31:26 +0100 Subject: [PATCH 3/3] Adapt tests, now that default is correctly carried out to gravatarproxy. Issue #45 --- ivatar/ivataraccount/test_views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ivatar/ivataraccount/test_views.py b/ivatar/ivataraccount/test_views.py index a17051f..1058980 100644 --- a/ivatar/ivataraccount/test_views.py +++ b/ivatar/ivataraccount/test_views.py @@ -1228,7 +1228,7 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods response = self.client.get(url, follow=True) self.assertRedirects( response=response, - expected_url='/static/img/nobody/80.png', + expected_url='/static/img/mm/80.png', msg_prefix='Why does this not redirect to the default img?') # Eventually one should check if the data is the same @@ -1302,8 +1302,8 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods response = self.client.get(url, follow=True) self.assertRedirects( response=response, - expected_url='/static/img/nobody/80.png', - msg_prefix='Why does this not redirect to the default img?') + expected_url='/static/img/nobody.png', + msg_prefix='Why does this not redirect to nobody img?') def test_avatar_url_default_gravatarproxy_disabled(self): # pylint: disable=invalid-name ''' @@ -1339,7 +1339,7 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods response = self.client.get(url, follow=False) self.assertRedirects( response=response, - expected_url='/gravatarproxy/fb7a6d7f11365642d44ba66dc57df56f?s=80', + expected_url='/gravatarproxy/fb7a6d7f11365642d44ba66dc57df56f?s=80&default=http://host.tld/img.png', fetch_redirect_response=False, msg_prefix='Why does this not redirect to the default img?')