2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
2013-06-10 21:35:48 +02:00
|
|
|
from django.conf import settings
|
2013-04-23 18:51:17 +02:00
|
|
|
|
2016-06-05 04:20:00 +02:00
|
|
|
if False:
|
|
|
|
from zerver.models import UserProfile
|
|
|
|
|
2016-12-21 13:17:53 +01:00
|
|
|
from typing import Text
|
2012-10-17 04:07:35 +02:00
|
|
|
|
2016-09-28 00:12:18 +02:00
|
|
|
from zerver.lib.avatar_hash import gravatar_hash, user_avatar_hash
|
2016-09-20 21:48:48 +02:00
|
|
|
from zerver.lib.upload import upload_backend, MEDIUM_AVATAR_SIZE
|
2013-06-10 21:35:48 +02:00
|
|
|
|
2016-09-20 21:48:48 +02:00
|
|
|
def avatar_url(user_profile, medium=False):
|
2016-12-21 13:17:53 +01:00
|
|
|
# type: (UserProfile, bool) -> Text
|
2013-09-21 16:32:29 +02:00
|
|
|
return get_avatar_url(
|
|
|
|
user_profile.avatar_source,
|
2016-09-20 21:48:48 +02:00
|
|
|
user_profile.email,
|
|
|
|
medium=medium)
|
2013-09-21 16:32:29 +02:00
|
|
|
|
2016-09-20 21:48:48 +02:00
|
|
|
def get_avatar_url(avatar_source, email, medium=False):
|
2016-12-21 13:17:53 +01:00
|
|
|
# type: (Text, Text, bool) -> Text
|
2016-06-12 14:22:20 +02:00
|
|
|
if avatar_source == u'U':
|
2013-09-21 16:32:29 +02:00
|
|
|
hash_key = user_avatar_hash(email)
|
2016-09-20 21:48:48 +02:00
|
|
|
return upload_backend.get_avatar_url(hash_key, medium=medium)
|
2013-11-15 22:25:02 +01:00
|
|
|
elif settings.ENABLE_GRAVATAR:
|
2016-09-20 21:48:48 +02:00
|
|
|
gravitar_query_suffix = "&s=%s" % (MEDIUM_AVATAR_SIZE,) if medium else ""
|
2013-09-21 16:32:29 +02:00
|
|
|
hash_key = gravatar_hash(email)
|
2016-09-20 21:48:48 +02:00
|
|
|
return u"https://secure.gravatar.com/avatar/%s?d=identicon%s" % (hash_key, gravitar_query_suffix)
|
2013-11-15 22:25:02 +01:00
|
|
|
else:
|
2013-11-18 16:58:39 +01:00
|
|
|
return settings.DEFAULT_AVATAR_URI+'?x=x'
|