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
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
@cache_with_key(realm_rendered_description_cache_key, timeout=3600 * 24 * 7)
|
2019-03-18 08:42:13 +01:00
|
|
|
def get_realm_rendered_description(realm: Realm) -> str:
|
|
|
|
realm_description_raw = realm.description or "The coolest place in the universe."
|
2021-06-17 12:20:40 +02:00
|
|
|
return markdown_convert(
|
|
|
|
realm_description_raw, message_realm=realm, no_previews=True
|
|
|
|
).rendered_content
|
2019-04-24 04:30:15 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
|
|
|
@cache_with_key(realm_text_description_cache_key, timeout=3600 * 24 * 7)
|
2019-04-24 04:30:15 +02:00
|
|
|
def get_realm_text_description(realm: Realm) -> str:
|
|
|
|
html_description = get_realm_rendered_description(realm)
|
2021-02-12 08:20:45 +01:00
|
|
|
return html_to_text(html_description, {"p": " | ", "li": " * "})
|