Browse Source

Add content types for Ask subtypes (e.g. Survey)

Adds content types for the three main Ask subtypes: Survey,
Recommendations, and Advice.
merge-requests/85/head
Deimos 5 years ago
parent
commit
5a5f564d93
  1. 7
      tildes/tildes/enums.py
  2. 17
      tildes/tildes/models/topic/topic.py
  3. 2
      tildes/tildes/templates/macros/topics.jinja2

7
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()

17
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".

2
tildes/tildes/templates/macros/topics.jinja2

@ -46,7 +46,7 @@
</ul>
{% endif %}
<span class="topic-content-type">{{ topic.content_type.display_name if topic.content_type else "Link" }}</span>
<span class="topic-content-type">{{ topic.content_type_for_display }}</span>
{% if topic.content_metadata_for_display %}
<span class="topic-content-metadata">{{ topic.content_metadata_for_display }}</span>

Loading…
Cancel
Save