Browse Source

Add synonym handling for tags

This fixes #247, but can be used handle other synonyms in the future.
merge-requests/45/head
D. Can Celasun 6 years ago
committed by Deimos
parent
commit
e5370d2a7b
  1. 6
      tildes/tests/test_topic_tags.py
  2. 6
      tildes/tildes/schemas/topic.py

6
tildes/tests/test_topic_tags.py

@ -36,3 +36,9 @@ def test_tags_lowercased(text_topic):
"""Ensure tags get converted to lowercase."""
text_topic.tags = ["ONE", "Two", "thRee"]
assert text_topic.tags == ["one", "two", "three"]
def test_tags_synonyms(text_topic):
""" Ensure synonyms are replaced."""
text_topic.tags = ["spoilers"]
assert text_topic.tags == ["spoiler"]

6
tildes/tildes/schemas/topic.py

@ -16,6 +16,7 @@ from tildes.schemas.group import GroupSchema
from tildes.schemas.user import UserSchema
TITLE_MAX_LENGTH = 200
TAG_SYNONYMS = {"spoiler": ["spoilers"]}
class TopicSchema(Schema):
@ -57,6 +58,11 @@ class TopicSchema(Schema):
if not tag or tag.isspace():
continue
# handle synonyms
for name, synonyms in TAG_SYNONYMS.items():
if tag in synonyms:
tag = name
# skip any duplicate tags
if tag in tags:
continue

Loading…
Cancel
Save