parent
affb600423
commit
4a55e34cb1
1 changed files with 12 additions and 4 deletions
|
@ -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:
|
||||||
if response.status_code == 200:
|
response = self.http_client.get(url, timeout=5)
|
||||||
return """<img src="%s" width="%s" height="%s" alt="%s"
|
if response.status_code == 200:
|
||||||
style="vertical-align: middle;">""" % (url, size, size, kind)
|
return """<img src="%s" width="%s" height="%s" alt="%s"
|
||||||
|
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 = 'Ω' if kind == 'team' and data['name'] == 'owners' else data['name'].upper()[0]
|
letter = 'Ω' if kind == 'team' and data['name'] == 'owners' else data['name'].upper()[0]
|
||||||
|
|
Reference in a new issue