From a76955011f2d2e4a243e21cb685a38e5d101bd70 Mon Sep 17 00:00:00 2001 From: Deimos Date: Fri, 11 Oct 2019 11:00:44 -0600 Subject: [PATCH] Use "Link" as the default content type for links Previously a topic with an unknown content type would display "Article". This switches to "Link" which will have some different idiosyncracies, but should be a little more correct in general. --- tildes/tildes/models/topic/topic.py | 14 ++++++++++---- tildes/tildes/templates/macros/topics.jinja2 | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index b069bb8..124135d 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -408,15 +408,16 @@ class Topic(DatabaseModel): return False - @property - def content_type(self) -> TopicContentType: + @property # noqa + 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"): return TopicContentType.ASK return TopicContentType.TEXT - else: + + if self.is_link_type: parsed_url = urlparse(self.link) # type: ignore url_path = PurePosixPath(parsed_url.path) @@ -435,7 +436,12 @@ class Topic(DatabaseModel): except IndexError: pass - return TopicContentType.ARTICLE + # consider it an article if we picked up a word count of at least 200 + word_count = self.get_content_metadata("word_count") + if word_count and word_count >= 200: + return TopicContentType.ARTICLE + + return None 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 90cc985..6381dc6 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 }} + {{ topic.content_type.display_name if topic.content_type else "Link" }} {% if topic.content_metadata_for_display %} : {{ topic.content_metadata_for_display }}