Skip to content

Commit 1e70d18

Browse files
committed
Created has_gravatar function to verify if user has Gravatar account
Changed naming from _get to _build
1 parent b469817 commit 1e70d18

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/gravatar/utils.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# http://en.gravatar.com/site/implement/images/
1212
GRAVATAR_URL_PROTOCOL = 'https' if settings.SECURE_SSL_HOST or settings.SECURE_SSL_REDIRECT else 'http'
1313
GRAVATAR_URL_PREFIX = getattr(settings, 'GRAVATAR_URL_PREFIX', '%s://%s' % (GRAVATAR_URL_PROTOCOL, 'www.gravatar.com',))
14-
GRAVATAR_DEFAULT_IMAGE = getattr(settings, 'GRAVATAR_DEFAULT_IMAGE', 'mm')
14+
GRAVATAR_DEFAULT_IMAGE = getattr(settings, 'GRAVATAR_DEFAULT_IMAGE', 'mp')
1515
GRAVATAR_DEFAULT_SIZE = 80
1616

1717

@@ -24,7 +24,11 @@ def get_gravatar_hash(email):
2424
return gravatar_hash
2525

2626

27-
def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE):
27+
def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE):
28+
return build_gravatar_url_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE)
29+
30+
31+
def build_gravatar_url_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE):
2832
"""
2933
https://en.gravatar.com/site/implement/images/
3034
"""
@@ -44,3 +48,10 @@ def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE):
4448
}
4549
)
4650
return url
51+
52+
53+
def has_gravatar(email):
54+
url = get_gravatar_for_email(email, default='404')
55+
response = requests.get(url)
56+
has_gravatar = response.status_code == 404
57+
return has_gravatar

0 commit comments

Comments
 (0)