0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Makes it possible to set a custom Gravatar source like robohash or your own.

This commit is contained in:
Pierre Geier 2018-01-04 15:05:12 +01:00 committed by Matt Westcott
parent f81c7d619c
commit 96118cdb9a
3 changed files with 20 additions and 7 deletions

View File

@ -231,6 +231,13 @@ This setting lets you change the number of items shown at 'Your most recent edit
Allows the default ``LoginForm`` to be extended with extra fields.
.. code-block:: python
WAGTAIL_GRAVATAR_PROVIDER_URL = '//www.gravatar.com/avatar'
Allows to set your own Gravatar-like URL or alternatives like robohash.org
Images
------

View File

@ -106,7 +106,7 @@ class UserProfile(models.Model):
return self.default_avatar
if self.avatar_choice == self.GRAVATAR and self.user.email:
return get_gravatar_url(self.user.email, default=None, size=50)
return get_gravatar_url(self.user.email, size=50)
return self.default_avatar

View File

@ -1,4 +1,5 @@
import hashlib
from django.conf import settings
from django.utils.http import urlencode
from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME
@ -21,10 +22,15 @@ def user_can_delete_user(current_user, user_to_delete):
return True
def get_gravatar_url(email, default=None, size=50):
params = {'s': str(size), 'd': 'mm'}
if default is not None:
params['default'] = default
gravatar_url = "https://www.gravatar.com/avatar/" + hashlib.md5(email.lower().encode('utf-8')).hexdigest() + "?"
gravatar_url += urlencode(params)
def get_gravatar_url(email, size=50):
default = "mm"
size = int(size) * 2 # requested at retina size by default and scaled down at point of use with css
gravatar_provider_url = getattr(settings, 'WAGTAIL_GRAVATAR_PROVIDER_URL', '//www.gravatar.com/avatar').rstrip('/')
gravatar_url = "{gravatar_provider_url}/{hash}?{params}".format(
gravatar_provider_url=gravatar_provider_url,
hash=hashlib.md5(email.lower().encode('utf-8')).hexdigest(),
params=urlencode({'s': size, 'd': default})
)
return gravatar_url