2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.cache import (
|
|
|
|
cache_with_key,
|
|
|
|
realm_rendered_description_cache_key,
|
|
|
|
realm_text_description_cache_key,
|
|
|
|
)
|
2019-04-24 04:30:15 +02:00
|
|
|
from zerver.lib.html_to_text import html_to_text
|
2020-07-04 14:34:46 +02:00
|
|
|
from zerver.lib.markdown import markdown_convert
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.models import Realm
|
|
|
|
|
2019-03-18 08:42:13 +01:00
|
|
|
|
|
|
|
@cache_with_key(realm_rendered_description_cache_key, timeout=3600*24*7)
|
|
|
|
def get_realm_rendered_description(realm: Realm) -> str:
|
|
|
|
realm_description_raw = realm.description or "The coolest place in the universe."
|
2020-06-28 12:26:18 +02:00
|
|
|
return markdown_convert(realm_description_raw, message_realm=realm,
|
|
|
|
no_previews=True)
|
2019-04-24 04:30:15 +02:00
|
|
|
|
|
|
|
@cache_with_key(realm_text_description_cache_key, timeout=3600*24*7)
|
|
|
|
def get_realm_text_description(realm: Realm) -> str:
|
|
|
|
html_description = get_realm_rendered_description(realm)
|
2019-05-02 02:35:20 +02:00
|
|
|
return html_to_text(html_description, {'p': ' | ', 'li': ' * '})
|