...
 
Commits (4)
......@@ -155,10 +155,13 @@ outline: inherit;
{% endif %}
{% if not max_photos %}
<p>
<a href="{% url 'upload_photo' %}" class="button">{% trans 'Upload a new photo' %}</a>&nbsp;
<a href="{% url 'import_photo' %}" class="button">{% trans 'Import photo from other services' %}</a>
</p>
<p>
<a href="{% url 'upload_photo' %}" class="button">{% trans 'Upload a new photo' %}</a>&nbsp;
<a href="{% url 'import_photo' %}" class="button">{% trans 'Import photo from other services' %}</a>
</p>
{% else %}
{% trans "You've reached the maximum number of allowed images!" %}<br/>
{% trans "No further images can be uploaded." %}
{% endif %}
<div style="height:40px"></div>
{% endblock content %}
......@@ -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
......
......@@ -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
......@@ -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)
......