From e5370d2a7bce4976d030f6b2923fb63b0be62b95 Mon Sep 17 00:00:00 2001 From: "D. Can Celasun" Date: Sat, 22 Sep 2018 10:23:14 +0200 Subject: [PATCH] Add synonym handling for tags This fixes #247, but can be used handle other synonyms in the future. --- tildes/tests/test_topic_tags.py | 6 ++++++ tildes/tildes/schemas/topic.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tildes/tests/test_topic_tags.py b/tildes/tests/test_topic_tags.py index 5fc8104..a988be4 100644 --- a/tildes/tests/test_topic_tags.py +++ b/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"] diff --git a/tildes/tildes/schemas/topic.py b/tildes/tildes/schemas/topic.py index 8e6fc0b..0019555 100644 --- a/tildes/tildes/schemas/topic.py +++ b/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