Skip to content

Commit

Permalink
Created has_gravatar function to verify if user has Gravatar account
Browse files Browse the repository at this point in the history
Changed naming from _get to _build
  • Loading branch information
lleung030 committed Dec 5, 2023
1 parent b469817 commit 1e70d18
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/gravatar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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/
"""
Expand All @@ -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

0 comments on commit 1e70d18

Please sign in to comment.