From 0262ad850f6a7274c8ad7988cb61a08a3c12ae98 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 6 May 2020 13:07:19 +0200 Subject: [PATCH 1/3] Fix some pylint issues and issue with single digit colors --- ivatar/utils.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ivatar/utils.py b/ivatar/utils.py index ae4c8f4..3ed3f03 100644 --- a/ivatar/utils.py +++ b/ivatar/utils.py @@ -35,7 +35,7 @@ def openid_variations(openid): var3 = var2[0:-1] return (openid, var1, var2, var3) -def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0): +def mm_ng(idhash, size=80, add_red=0, add_green=0, add_blue=0): #pylint: disable=too-many-locals ''' Return an MM (mystery man) image, based on a given hash add some red, green or blue, if specified @@ -43,7 +43,8 @@ def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0): # Make sure the lightest bg color we paint is e0, else # we do not see the MM any more - if hash[0] == 'f': hash = 'e0' + if idhash[0] == 'f': + idhash = 'e0' # How large is the circle? circlesize = size*0.6 @@ -56,21 +57,30 @@ def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0): # All are the same, based on the input hash # this should always result in a "gray-ish" background - red = hash[0:2] - green = hash[0:2] - blue = hash[0:2] + red = idhash[0:2] + green = idhash[0:2] + blue = idhash[0:2] # Add some red (i/a) and make sure it's not over 255 red = hex(int(red, 16)+add_red).replace('0x', '') - if int(red, 16)>255: red='ff' + if int(red, 16) > 255: + red = 'ff' + if len(red) == 1: + red = '0%s' % red # Add some green (i/a) and make sure it's not over 255 green = hex(int(green, 16)+add_green).replace('0x', '') - if int(green, 16)>255: green='ff' + if int(green, 16) > 255: + green = 'ff' + if len(green) == 1: + green = '0%s' % green # Add some blue (i/a) and make sure it's not over 255 blue = hex(int(blue, 16)+add_blue).replace('0x', '') - if int(blue, 16)>255: blue='ff' + if int(blue, 16) > 255: + blue = 'ff' + if len(blue) == 1: + blue = '0%s' % blue # Assemable the bg color "string" in webnotation. Eg. '#d3d3d3' bg_color = '#' + red + green + blue @@ -80,12 +90,16 @@ def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0): draw = ImageDraw.Draw(image) # Draw background - draw.rectangle(((0,0), (size, size)), fill=bg_color) + draw.rectangle(((0, 0), (size, size)), fill=bg_color) # Draw MMs head draw.ellipse((start_x, start_y, end_x, end_y), fill='white') # Draw MMs 'body' - draw.polygon(((start_x+circlesize/2, size/2.5), (size*0.15, size), (size-size*0.15, size)), fill='white') + draw.polygon(( + (start_x+circlesize/2, size/2.5), + (size*0.15, size), + (size-size*0.15, size)), + fill='white') return image From feab5f6156355d6a6ec9adac1e942d4f24fe5eed Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 6 May 2020 13:11:21 +0200 Subject: [PATCH 2/3] Fix pylint warnings --- ivatar/views.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ivatar/views.py b/ivatar/views.py index 4c97939..95af253 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -99,14 +99,14 @@ class AvatarImageView(TemplateView): if centry: # For DEBUG purpose only print('Cached entry for %s' % uri) return HttpResponse( - centry['content'], - content_type=centry['content_type'], - status=centry['status'], - reason = centry['reason'], - charset = centry['charset']) + centry['content'], + content_type=centry['content_type'], + status=centry['status'], + reason=centry['reason'], + charset=centry['charset']) # In case no digest at all is provided, return to home page - if not 'digest' in kwargs: + if 'digest' not in kwargs: return HttpResponseRedirect(reverse_lazy('home')) if 'd' in request.GET: @@ -248,7 +248,7 @@ class AvatarImageView(TemplateView): return response if str(default) == 'mmng': - mmngimg = mm_ng(hash=kwargs['digest'], size=size) + mmngimg = mm_ng(idhash=kwargs['digest'], size=size) data = BytesIO() mmngimg.save(data, 'PNG', quality=JPEG_QUALITY) data.seek(0) From 31bc906fda524c3970c7aeed401b0a4186b7a516 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Mon, 11 May 2020 10:10:26 +0200 Subject: [PATCH 3/3] Missing context data (max_photos). Fixes #66 Signed-off-by: Oliver Falk --- ivatar/ivataraccount/templates/profile.html | 11 +++++++---- ivatar/ivataraccount/views.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ivatar/ivataraccount/templates/profile.html b/ivatar/ivataraccount/templates/profile.html index 03c4f0a..c4ee0fb 100644 --- a/ivatar/ivataraccount/templates/profile.html +++ b/ivatar/ivataraccount/templates/profile.html @@ -155,10 +155,13 @@ outline: inherit; {% endif %} {% if not max_photos %} -

-{% trans 'Upload a new photo' %}  -{% trans 'Import photo from other services' %} -

+

+ {% trans 'Upload a new photo' %}  + {% trans 'Import photo from other services' %} +

+{% else %} + {% trans "You've reached the maximum number of allowed images!" %}
+ {% trans "No further images can be uploaded." %} {% endif %}
{% endblock content %} diff --git a/ivatar/ivataraccount/views.py b/ivatar/ivataraccount/views.py index 6a83cd5..db18795 100644 --- a/ivatar/ivataraccount/views.py +++ b/ivatar/ivataraccount/views.py @@ -898,6 +898,18 @@ class ProfileView(TemplateView): self._confirm_claimed_openid() return super().get(self, request, args, kwargs) + def get_context_data(self, **kwargs): + ''' + Provide additional context data, like if max_photos is reached + already or not. + ''' + context = super().get_context_data(**kwargs) + context['max_photos'] = False + if self.request.user: + if self.request.user.photo_set.all().count() >= MAX_NUM_PHOTOS: + context['max_photos'] = True + return context + def _confirm_claimed_openid(self): openids = self.request.user.useropenid_set.all() # If there is only one OpenID, we eventually need to add it to the user account