Browse Source

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.
merge-requests/68/head
Chad Birch 6 years ago
parent
commit
cefd5a0c51
  1. 9
      tildes/tildes/views/topic.py

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

Loading…
Cancel
Save