Allow disabling gravatar with WAGTAIL_GRAVATAR_PROVIDER_URL=None. Fixes #1286

pull/4503/head
Matt Westcott 2018-01-16 16:06:50 +00:00
rodzic 96118cdb9a
commit bcbfe226ee
2 zmienionych plików z 7 dodań i 3 usunięć

Wyświetl plik

@ -235,7 +235,7 @@ Allows the default ``LoginForm`` to be extended with extra fields.
WAGTAIL_GRAVATAR_PROVIDER_URL = '//www.gravatar.com/avatar'
Allows to set your own Gravatar-like URL or alternatives like robohash.org
If a user has not uploaded a profile picture, Wagtail will look for an avatar linked to their email address on gravatar.com. This setting allows you to specify an alternative provider such as like robohash.org, or can be set to ``None`` to disable the use of remote avatars completely.
Images

Wyświetl plik

@ -1,5 +1,6 @@
import hashlib
from django.conf import settings
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.utils.http import urlencode
from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME
@ -25,10 +26,13 @@ def user_can_delete_user(current_user, user_to_delete):
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_provider_url = getattr(settings, 'WAGTAIL_GRAVATAR_PROVIDER_URL', '//www.gravatar.com/avatar')
if gravatar_provider_url is None:
return static('wagtailadmin/images/default-user-avatar.png')
gravatar_url = "{gravatar_provider_url}/{hash}?{params}".format(
gravatar_provider_url=gravatar_provider_url,
gravatar_provider_url=gravatar_provider_url.rstrip('/'),
hash=hashlib.md5(email.lower().encode('utf-8')).hexdigest(),
params=urlencode({'s': size, 'd': default})
)