2024-07-12 02:30:17 +02:00
|
|
|
from typing import Any
|
2019-08-19 13:58:46 +02:00
|
|
|
|
2018-08-16 01:26:55 +02:00
|
|
|
from django.conf import settings
|
2023-01-25 00:30:24 +01:00
|
|
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
2018-08-16 01:26:55 +02:00
|
|
|
|
|
|
|
from zerver.lib.upload import upload_backend
|
|
|
|
from zerver.models import Realm
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-06-08 11:53:24 +02:00
|
|
|
def get_realm_logo_source(realm: Realm, night: bool) -> str:
|
2021-10-18 23:28:17 +02:00
|
|
|
if realm.plan_type == Realm.PLAN_TYPE_LIMITED:
|
2020-06-08 11:53:24 +02:00
|
|
|
return Realm.LOGO_DEFAULT
|
2019-08-19 15:04:45 +02:00
|
|
|
if night:
|
2020-06-08 11:53:24 +02:00
|
|
|
return realm.night_logo_source
|
|
|
|
return realm.logo_source
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-06-08 11:53:24 +02:00
|
|
|
def get_realm_logo_url(realm: Realm, night: bool) -> str:
|
|
|
|
logo_source = get_realm_logo_source(realm, night)
|
|
|
|
|
|
|
|
if logo_source == Realm.LOGO_UPLOADED:
|
|
|
|
if night:
|
|
|
|
logo_version = realm.night_logo_version
|
|
|
|
else:
|
|
|
|
logo_version = realm.logo_version
|
2019-08-19 15:04:45 +02:00
|
|
|
return upload_backend.get_realm_logo_url(realm.id, logo_version, night)
|
2023-01-25 00:30:24 +01:00
|
|
|
if settings.DEFAULT_LOGO_URI is not None:
|
|
|
|
return settings.DEFAULT_LOGO_URI
|
|
|
|
return staticfiles_storage.url("images/logo/zulip-org-logo.svg") + "?version=0"
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-08-19 13:58:46 +02:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def get_realm_logo_data(realm: Realm, night: bool) -> dict[str, Any]:
|
2019-08-19 13:58:46 +02:00
|
|
|
if night:
|
2021-02-12 08:19:30 +01:00
|
|
|
return dict(
|
|
|
|
night_logo_url=get_realm_logo_url(realm, night),
|
|
|
|
night_logo_source=realm.night_logo_source,
|
|
|
|
)
|
|
|
|
return dict(logo_url=get_realm_logo_url(realm, night), logo_source=realm.logo_source)
|