Files
zulip/zerver/lib/avatar.py
Brock Whittaker fca61b2031 Add medium size avatars for use on the user's own settings page.
This adds a medium (500px) size avatar thumbnail, that can be
referenced as `{name}-medium.png`.  It is intended to be used on the
user's own settings page, though we may come up with other use cases
for high-resolution avatars in the future.

This will automatically generate and upload the medium avatar images
when a new avatar original is uploaded, and contains a migration
(contributed by Kirill Kanakhin) to ensure all pre-existing avatar
images have a medium avatar.

Note that this implementation does not provide an endpoint for
fetching the medium-size avatar for another user.

[substantially modified by tabbott]
2016-10-25 09:42:14 -07:00

30 lines
1.1 KiB
Python

from __future__ import absolute_import
from django.conf import settings
if False:
from zerver.models import UserProfile
from six import text_type
from zerver.lib.avatar_hash import gravatar_hash, user_avatar_hash
from zerver.lib.upload import upload_backend, MEDIUM_AVATAR_SIZE
def avatar_url(user_profile, medium=False):
# type: (UserProfile, bool) -> text_type
return get_avatar_url(
user_profile.avatar_source,
user_profile.email,
medium=medium)
def get_avatar_url(avatar_source, email, medium=False):
# type: (text_type, text_type, bool) -> text_type
if avatar_source == u'U':
hash_key = user_avatar_hash(email)
return upload_backend.get_avatar_url(hash_key, medium=medium)
elif settings.ENABLE_GRAVATAR:
gravitar_query_suffix = "&s=%s" % (MEDIUM_AVATAR_SIZE,) if medium else ""
hash_key = gravatar_hash(email)
return u"https://secure.gravatar.com/avatar/%s?d=identicon%s" % (hash_key, gravitar_query_suffix)
else:
return settings.DEFAULT_AVATAR_URI+'?x=x'