Files
zulip/zerver/lib/realm_description.py
PIG208 75cea329b4 markdown: Refactor out additional properties added to Message.
This adds a new class called MessageRenderingResult to contain the
additional properties we added to the Message object (like alert_words)
as well as the rendered content to ensure typesafe reference. No
behavioral change is made except changes in typing.

This is a preparatory change for adding django-stubs to the backend.

Related: #18777
2021-06-24 18:14:53 -07:00

23 lines
864 B
Python

from zerver.lib.cache import (
cache_with_key,
realm_rendered_description_cache_key,
realm_text_description_cache_key,
)
from zerver.lib.html_to_text import html_to_text
from zerver.lib.markdown import markdown_convert
from zerver.models import Realm
@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."
return markdown_convert(
realm_description_raw, message_realm=realm, no_previews=True
).rendered_content
@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)
return html_to_text(html_description, {"p": " | ", "li": " * "})