2017-02-21 03:41:20 +01:00
|
|
|
from django.conf import settings
|
2023-01-25 00:30:24 +01:00
|
|
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
2017-02-21 03:41:20 +01:00
|
|
|
|
2019-02-02 23:53:55 +01:00
|
|
|
from zerver.lib.avatar_hash import gravatar_hash
|
2017-02-21 03:41:20 +01:00
|
|
|
from zerver.lib.upload import upload_backend
|
|
|
|
from zerver.models import Realm
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-05-10 19:13:36 +02:00
|
|
|
def realm_icon_url(realm: Realm) -> str:
|
2017-02-21 03:41:20 +01:00
|
|
|
return get_realm_icon_url(realm)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-05-10 19:13:36 +02:00
|
|
|
def get_realm_icon_url(realm: Realm) -> str:
|
2021-02-12 08:20:45 +01:00
|
|
|
if realm.icon_source == "U":
|
2017-02-21 03:41:20 +01:00
|
|
|
return upload_backend.get_realm_icon_url(realm.id, realm.icon_version)
|
|
|
|
elif settings.ENABLE_GRAVATAR:
|
2017-03-13 19:48:49 +01:00
|
|
|
hash_key = gravatar_hash(realm.string_id)
|
2020-06-10 06:41:04 +02:00
|
|
|
return f"https://secure.gravatar.com/avatar/{hash_key}?d=identicon"
|
2023-01-25 00:30:24 +01:00
|
|
|
elif settings.DEFAULT_AVATAR_URI is not None:
|
|
|
|
return settings.DEFAULT_AVATAR_URI
|
2017-02-21 03:41:20 +01:00
|
|
|
else:
|
2023-01-25 00:30:24 +01:00
|
|
|
return staticfiles_storage.url("images/default-avatar.png") + "?version=0"
|