mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-17 21:48:02 +00:00
Merge branch 'devel' into 'master'
Merge in latest devel Closes #66 See merge request oliver/ivatar!173
This commit is contained in:
@@ -159,6 +159,9 @@ outline: inherit;
|
|||||||
<a href="{% url 'upload_photo' %}" class="button">{% trans 'Upload a new photo' %}</a>
|
<a href="{% url 'upload_photo' %}" class="button">{% trans 'Upload a new photo' %}</a>
|
||||||
<a href="{% url 'import_photo' %}" class="button">{% trans 'Import photo from other services' %}</a>
|
<a href="{% url 'import_photo' %}" class="button">{% trans 'Import photo from other services' %}</a>
|
||||||
</p>
|
</p>
|
||||||
|
{% else %}
|
||||||
|
{% trans "You've reached the maximum number of allowed images!" %}<br/>
|
||||||
|
{% trans "No further images can be uploaded." %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div style="height:40px"></div>
|
<div style="height:40px"></div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|||||||
@@ -898,6 +898,18 @@ class ProfileView(TemplateView):
|
|||||||
self._confirm_claimed_openid()
|
self._confirm_claimed_openid()
|
||||||
return super().get(self, request, args, kwargs)
|
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):
|
def _confirm_claimed_openid(self):
|
||||||
openids = self.request.user.useropenid_set.all()
|
openids = self.request.user.useropenid_set.all()
|
||||||
# If there is only one OpenID, we eventually need to add it to the user account
|
# 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]
|
var3 = var2[0:-1]
|
||||||
return (openid, var1, var2, var3)
|
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
|
Return an MM (mystery man) image, based on a given hash
|
||||||
add some red, green or blue, if specified
|
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
|
# Make sure the lightest bg color we paint is e0, else
|
||||||
# we do not see the MM any more
|
# 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?
|
# How large is the circle?
|
||||||
circlesize = size*0.6
|
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
|
# All are the same, based on the input hash
|
||||||
# this should always result in a "gray-ish" background
|
# this should always result in a "gray-ish" background
|
||||||
red = hash[0:2]
|
red = idhash[0:2]
|
||||||
green = hash[0:2]
|
green = idhash[0:2]
|
||||||
blue = hash[0:2]
|
blue = idhash[0:2]
|
||||||
|
|
||||||
# Add some red (i/a) and make sure it's not over 255
|
# Add some red (i/a) and make sure it's not over 255
|
||||||
red = hex(int(red, 16)+add_red).replace('0x', '')
|
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
|
# Add some green (i/a) and make sure it's not over 255
|
||||||
green = hex(int(green, 16)+add_green).replace('0x', '')
|
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
|
# Add some blue (i/a) and make sure it's not over 255
|
||||||
blue = hex(int(blue, 16)+add_blue).replace('0x', '')
|
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'
|
# Assemable the bg color "string" in webnotation. Eg. '#d3d3d3'
|
||||||
bg_color = '#' + red + green + blue
|
bg_color = '#' + red + green + blue
|
||||||
@@ -86,6 +96,10 @@ def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0):
|
|||||||
draw.ellipse((start_x, start_y, end_x, end_y), fill='white')
|
draw.ellipse((start_x, start_y, end_x, end_y), fill='white')
|
||||||
|
|
||||||
# Draw MMs 'body'
|
# 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
|
return image
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class AvatarImageView(TemplateView):
|
|||||||
charset=centry['charset'])
|
charset=centry['charset'])
|
||||||
|
|
||||||
# In case no digest at all is provided, return to home page
|
# 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'))
|
return HttpResponseRedirect(reverse_lazy('home'))
|
||||||
|
|
||||||
if 'd' in request.GET:
|
if 'd' in request.GET:
|
||||||
@@ -248,7 +248,7 @@ class AvatarImageView(TemplateView):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
if str(default) == 'mmng':
|
if str(default) == 'mmng':
|
||||||
mmngimg = mm_ng(hash=kwargs['digest'], size=size)
|
mmngimg = mm_ng(idhash=kwargs['digest'], size=size)
|
||||||
data = BytesIO()
|
data = BytesIO()
|
||||||
mmngimg.save(data, 'PNG', quality=JPEG_QUALITY)
|
mmngimg.save(data, 'PNG', quality=JPEG_QUALITY)
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user