From fd0a90bb5b8777f245aae1eb77dae227575201c3 Mon Sep 17 00:00:00 2001 From: Deimos Date: Wed, 9 Oct 2019 11:51:31 -0600 Subject: [PATCH] Include sub-tags in "important" tags --- tildes/tildes/models/topic/topic.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index 3d7e76f..1eeb933 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -45,9 +45,6 @@ else: # edits inside this period after creation will not mark the topic as edited EDIT_GRACE_PERIOD = timedelta(minutes=5) -# special tags to put at the front of the tag list -SPECIAL_TAGS = ["nsfw", "spoiler"] - class Topic(DatabaseModel): """Model for a topic on the site. @@ -161,7 +158,16 @@ class Topic(DatabaseModel): @property def important_tags(self) -> List[str]: """Return only the topic's "important" tags.""" - return [tag for tag in self.tags if tag in SPECIAL_TAGS] + global_important_tags = ["nsfw", "spoiler"] + + # used with startswith() to check for sub-tags + global_important_prefixes = tuple([f"{tag}." for tag in global_important_tags]) + + return [ + tag + for tag in self.tags + if tag in global_important_tags or tag.startswith(global_important_prefixes) + ] @property def unimportant_tags(self) -> List[str]: