From 875ad09b000b624fc33d1716a2a8304a597b42a4 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Wed, 26 Oct 2016 10:08:04 +0000 Subject: [PATCH] Fixt a ValueError in .matches() + pep8 --- src/documents/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/documents/models.py b/src/documents/models.py index c65e5f351..56c330f75 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -84,7 +84,9 @@ class MatchingModel(models.Model): if self.matching_algorithm == self.MATCH_ALL: for word in self.match.split(" "): - if not re.search(r"\b{}\b".format(word), text, **search_kwargs): + search_result = re.search( + r"\b{}\b".format(word), text, **search_kwargs) + if not search_result: return False return True @@ -95,10 +97,12 @@ class MatchingModel(models.Model): return False if self.matching_algorithm == self.MATCH_LITERAL: - return bool(re.search(r"\b{}\b".format(self.match), text, **search_kwargs)) + return bool(re.search( + r"\b{}\b".format(self.match), text, **search_kwargs)) if self.matching_algorithm == self.MATCH_REGEX: - return bool(re.search(re.compile(self.match), text, **search_kwargs)) + return bool(re.search( + re.compile(self.match, **search_kwargs), text)) raise NotImplementedError("Unsupported matching algorithm")