Fail safe when gravatar is done

Fixes #1358
This commit is contained in:
Joseph Schorr 2016-04-11 13:46:32 -04:00
parent affb600423
commit 4a55e34cb1

View file

@ -1,5 +1,10 @@
import hashlib import hashlib
import math import math
import logging
from requests.exceptions import RequestException
logger = logging.getLogger(__name__)
class Avatar(object): class Avatar(object):
def __init__(self, app=None): def __init__(self, app=None):
@ -32,10 +37,13 @@ class BaseAvatar(object):
if url is not None: if url is not None:
# Try to load the gravatar. If we get a non-404 response, then we use it in place of # Try to load the gravatar. If we get a non-404 response, then we use it in place of
# the CSS avatar. # the CSS avatar.
response = self.http_client.get(url) try:
response = self.http_client.get(url, timeout=5)
if response.status_code == 200: if response.status_code == 200:
return """<img src="%s" width="%s" height="%s" alt="%s" return """<img src="%s" width="%s" height="%s" alt="%s"
style="vertical-align: middle;">""" % (url, size, size, kind) style="vertical-align: middle;">""" % (url, size, size, kind)
except RequestException:
logger.exception('Could not retrieve avatar for user %s', name)
radius = '50%' if kind == 'team' else '0%' radius = '50%' if kind == 'team' else '0%'
letter = '&Omega;' if kind == 'team' and data['name'] == 'owners' else data['name'].upper()[0] letter = '&Omega;' if kind == 'team' and data['name'] == 'owners' else data['name'].upper()[0]