diff --git a/lib/gravatar/utils.py b/lib/gravatar/utils.py index be3bd238..354f9713 100644 --- a/lib/gravatar/utils.py +++ b/lib/gravatar/utils.py @@ -11,7 +11,7 @@ # http://en.gravatar.com/site/implement/images/ GRAVATAR_URL_PROTOCOL = 'https' if settings.SECURE_SSL_HOST or settings.SECURE_SSL_REDIRECT else 'http' GRAVATAR_URL_PREFIX = getattr(settings, 'GRAVATAR_URL_PREFIX', '%s://%s' % (GRAVATAR_URL_PROTOCOL, 'www.gravatar.com',)) -GRAVATAR_DEFAULT_IMAGE = getattr(settings, 'GRAVATAR_DEFAULT_IMAGE', 'mm') +GRAVATAR_DEFAULT_IMAGE = getattr(settings, 'GRAVATAR_DEFAULT_IMAGE', 'mp') GRAVATAR_DEFAULT_SIZE = 80 @@ -24,7 +24,11 @@ def get_gravatar_hash(email): return gravatar_hash -def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE): +def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE): + return build_gravatar_url_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE) + + +def build_gravatar_url_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE): """ https://en.gravatar.com/site/implement/images/ """ @@ -44,3 +48,10 @@ def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE): } ) return url + + +def has_gravatar(email): + url = get_gravatar_for_email(email, default='404') + response = requests.get(url) + has_gravatar = response.status_code == 404 + return has_gravatar