From 5a5f564d93a44e64b7d88c0c082ef27885ee85e2 Mon Sep 17 00:00:00 2001 From: Deimos Date: Mon, 25 Nov 2019 18:59:06 -0700 Subject: [PATCH] Add content types for Ask subtypes (e.g. Survey) Adds content types for the three main Ask subtypes: Survey, Recommendations, and Advice. --- tildes/tildes/enums.py | 7 +++++++ tildes/tildes/models/topic/topic.py | 17 +++++++++++++++++ tildes/tildes/templates/macros/topics.jinja2 | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tildes/tildes/enums.py b/tildes/tildes/enums.py index 0cd7bf5..0bafee1 100644 --- a/tildes/tildes/enums.py +++ b/tildes/tildes/enums.py @@ -201,6 +201,9 @@ class TopicContentType(enum.Enum): ARTICLE = enum.auto() ASK = enum.auto() + ASK_ADVICE = enum.auto() + ASK_RECOMMENDATIONS = enum.auto() + ASK_SURVEY = enum.auto() IMAGE = enum.auto() PDF = enum.auto() TEXT = enum.auto() @@ -214,6 +217,10 @@ class TopicContentType(enum.Enum): if self.name == "PDF": return self.name + if self.name.startswith("ASK_"): + subtype_name = self.name.partition("_")[-1].capitalize() + return f"Ask ({subtype_name})" + return self.name.capitalize() diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index 3469e33..9c7a575 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -440,6 +440,15 @@ class Topic(DatabaseModel): def content_type(self) -> Optional[TopicContentType]: """Return the content's type based on the topic's attributes.""" if self.is_text_type: + if self.has_tag("ask.survey"): + return TopicContentType.ASK_SURVEY + + if self.has_tag("ask.recommendations"): + return TopicContentType.ASK_RECOMMENDATIONS + + if self.has_tag("ask.advice"): + return TopicContentType.ASK_ADVICE + if self.has_tag("ask"): return TopicContentType.ASK @@ -466,6 +475,14 @@ class Topic(DatabaseModel): return None + @property + def content_type_for_display(self) -> str: + """Return a string of the topic's content type, suitable for display.""" + if not self.content_type: + return "Link" + + return self.content_type.display_name + 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 d7ba417..338d9b9 100644 --- a/tildes/tildes/templates/macros/topics.jinja2 +++ b/tildes/tildes/templates/macros/topics.jinja2 @@ -46,7 +46,7 @@ {% endif %} - {{ topic.content_type.display_name if topic.content_type else "Link" }} + {{ topic.content_type_for_display }} {% if topic.content_metadata_for_display %} {{ topic.content_metadata_for_display }}