From 34a933e6d3b572df989dddcf3013aa63cfc659b0 Mon Sep 17 00:00:00 2001 From: Deimos Date: Sun, 5 Aug 2018 15:30:21 -0600 Subject: [PATCH] Refactor text topic excerpt display into a macro --- tildes/tildes/models/topic/topic.py | 5 ++ tildes/tildes/templates/macros/topics.jinja2 | 51 ++++++++++---------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index a981b88..ea2e11e 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -310,6 +310,11 @@ class Topic(DatabaseModel): return (self.get_content_metadata('domain') or get_domain_from_url(self.link)) + @property + def is_spoiler(self) -> bool: + """Return whether the topic is marked as a spoiler.""" + return 'spoiler' in self.tags + def get_content_metadata(self, key: str) -> Any: """Get a piece of content metadata "safely". diff --git a/tildes/tildes/templates/macros/topics.jinja2 b/tildes/tildes/templates/macros/topics.jinja2 index 4519847..63980ca 100644 --- a/tildes/tildes/templates/macros/topics.jinja2 +++ b/tildes/tildes/templates/macros/topics.jinja2 @@ -47,31 +47,7 @@ {% if topic.is_text_type and topic.get_content_metadata('excerpt') %} - {# warn about spoilers #} - {% if 'spoiler' in topic.tags %} -
- - Warning: this post may contain spoilers. - - {{ topic.rendered_html|safe }} -
- {% else %} - {# if the "excerpt" is the full text, don't wrap in
#} - {% if not topic.get_content_metadata('excerpt').endswith('...') %} -

{{ topic.get_content_metadata('excerpt') }}

- {% else %} -
- - {{ topic.get_content_metadata('excerpt') }} - - {{ topic.rendered_html|safe }} -
- {% endif %} - {% endif %} + {{ topic_excerpt_expandable(topic) }} {% endif %}