mirror of https://github.com/dirtbags/moth.git
Adding validator to detect duplicate authors
This commit is contained in:
parent
ecb20713aa
commit
5d954b2f58
|
@ -94,13 +94,27 @@ class MothValidator:
|
||||||
if len(duplicate_answers) > 0:
|
if len(duplicate_answers) > 0:
|
||||||
raise MothValidationError("Duplicate answer(s) %s" % ", ".join(duplicate_answers))
|
raise MothValidationError("Duplicate answer(s) %s" % ", ".join(duplicate_answers))
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_has_authors(puzzle):
|
def check_has_authors(puzzle):
|
||||||
"""Check if the puzzle has authors defined"""
|
"""Check if the puzzle has authors defined"""
|
||||||
if len(puzzle.authors) == 0:
|
if len(puzzle.authors) == 0:
|
||||||
raise MothValidationError("No authors provided")
|
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
|
@staticmethod
|
||||||
def check_has_summary(puzzle):
|
def check_has_summary(puzzle):
|
||||||
"""Check if the puzzle has a summary"""
|
"""Check if the puzzle has a summary"""
|
||||||
|
|
Loading…
Reference in New Issue