2019-08-19 13:58:46 +02:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
2018-08-16 01:26:55 +02:00
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
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:
|
|
|
|
if realm.plan_type == Realm.LIMITED:
|
|
|
|
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)
|
2021-02-12 08:19:30 +01:00
|
|
|
return settings.DEFAULT_LOGO_URI + '?version=0'
|
|
|
|
|
2019-08-19 13:58:46 +02:00
|
|
|
|
|
|
|
def get_realm_logo_data(realm: Realm, night: bool) -> Dict[str, Any]:
|
|
|
|
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)
|