From 5d954b2f580e47d8083628f402756b7c313782e4 Mon Sep 17 00:00:00 2001 From: John Donaldson Date: Thu, 18 Jul 2019 18:48:16 +0100 Subject: [PATCH] Adding validator to detect duplicate authors --- devel/validate.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/devel/validate.py b/devel/validate.py index 3f94e5b..150f0d3 100644 --- a/devel/validate.py +++ b/devel/validate.py @@ -94,13 +94,27 @@ class MothValidator: if len(duplicate_answers) > 0: raise MothValidationError("Duplicate answer(s) %s" % ", ".join(duplicate_answers)) - @staticmethod def check_has_authors(puzzle): """Check if the puzzle has authors defined""" if len(puzzle.authors) == 0: raise MothValidationError("No authors provided") + @staticmethod + def check_unique_authors(puzzle): + """Check if puzzle authors are unique""" + known_authors = [] + duplicate_authors = [] + + for author in puzzle.authors: + if author not in known_authors: + known_authors.append(author) + else: + duplicate_authors.append(author) + + if len(duplicate_authors) > 0: + raise MothValidationError("Duplicate author(s) %s" % ", ".join(duplicate_authors)) + @staticmethod def check_has_summary(puzzle): """Check if the puzzle has a summary"""