From cefd5a0c5167370b32013e84b7272f4f23ab3b56 Mon Sep 17 00:00:00 2001 From: Chad Birch Date: Tue, 9 Apr 2019 15:27:16 -0600 Subject: [PATCH] New topics: Remove topic tag matching group name When someone posts a new topic, this will automatically remove any tag that matches the group name. So for example, if the topic is being posted in ~music, a tag of "music" will be removed. If there turns out to be some edge case where this is important, it can be re-added through the tag editing interface, since this only applies when posting a new topic. --- tildes/tildes/views/topic.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index c3a8c0f..cca528b 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -48,9 +48,11 @@ def post_group_topics( request: Request, title: str, markdown: str, link: str, tags: str ) -> HTTPFound: """Post a new topic to a group.""" + group = request.context + if link: new_topic = Topic.create_link_topic( - group=request.context, author=request.user, title=title, link=link + group=group, author=request.user, title=title, link=link ) # if they specified both a link and markdown, use the markdown to post an @@ -66,7 +68,7 @@ def post_group_topics( ) else: new_topic = Topic.create_text_topic( - group=request.context, author=request.user, title=title, markdown=markdown + group=group, author=request.user, title=title, markdown=markdown ) try: @@ -74,6 +76,9 @@ def post_group_topics( except ValidationError: raise ValidationError({"tags": ["Invalid tags"]}) + # remove any tag that's the same as the group's name + new_topic.tags = [tag for tag in new_topic.tags if tag != str(group.path)] + request.apply_rate_limit("topic_post") request.db_session.add(new_topic)