Fixt a ValueError in .matches() + pep8

This commit is contained in:
Daniel Quinn 2016-10-26 10:08:04 +00:00
parent ee939ae3bc
commit 875ad09b00

View File

@ -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")