Ejemplo n.º 1
0
    def matches(self, message):
        if message.contact.fields:
            contact_value = normalize(message.contact.fields.get(self.key, ""))

            for value in self.values:
                if value == contact_value:
                    return True
        return False
Ejemplo n.º 2
0
    def matches(self, message):
        if message.contact.fields:
            contact_value = normalize(message.contact.fields.get(self.key, ""))

            for value in self.values:
                if value == contact_value:
                    return True
        return False
Ejemplo n.º 3
0
    def matches(self, message):
        text = normalize(message.text)

        def keyword_check(w):
            return lambda: bool(regex.search(r'\b' + w + r'\b', text, flags=regex.UNICODE | regex.V0))

        checks = [keyword_check(keyword) for keyword in self.keywords]

        return self.quantifier.evaluate(checks)
Ejemplo n.º 4
0
    def matches(self, message):
        text = normalize(message.text)

        def keyword_check(w):
            return lambda: bool(regex.search(r"\b" + w + r"\b", text, flags=regex.UNICODE | regex.V0))

        checks = [keyword_check(keyword) for keyword in self.keywords]

        return self.quantifier.evaluate(checks)
Ejemplo n.º 5
0
    def clean_keywords(self):
        keywords = parse_csv(self.cleaned_data['keywords'])
        clean_keywords = []
        for keyword in keywords:
            clean_keyword = normalize(keyword)

            if not ContainsTest.is_valid_keyword(keyword):
                raise forms.ValidationError(_("Invalid keyword: %s") % keyword)

            clean_keywords.append(clean_keyword)

        return ', '.join(clean_keywords)
Ejemplo n.º 6
0
    def clean_keywords(self):
        keywords = parse_csv(self.cleaned_data['keywords'])
        clean_keywords = []
        for keyword in keywords:
            clean_keyword = normalize(keyword)

            if not ContainsTest.is_valid_keyword(keyword):
                raise forms.ValidationError(_("Invalid keyword: %s") % keyword)

            clean_keywords.append(clean_keyword)

        return ', '.join(clean_keywords)
Ejemplo n.º 7
0
    def clean_keywords(self):
        keywords = parse_csv(self.cleaned_data['keywords'])
        clean_keywords = []
        for keyword in keywords:
            clean_keyword = normalize(keyword)

            if len(keyword) < Label.KEYWORD_MIN_LENGTH:
                raise forms.ValidationError(_("Keywords must be at least %d characters long")
                                            % Label.KEYWORD_MIN_LENGTH)

            if not Label.is_valid_keyword(keyword):
                raise forms.ValidationError(_("Invalid keyword: %s") % keyword)

            clean_keywords.append(clean_keyword)

        return ','.join(clean_keywords)
Ejemplo n.º 8
0
 def __init__(self, key, values):
     self.key = key
     self.values = [normalize(v) for v in values]
Ejemplo n.º 9
0
 def __init__(self, keywords, quantifier):
     self.keywords = [normalize(word) for word in keywords]
     self.quantifier = quantifier
Ejemplo n.º 10
0
 def __init__(self, key, values):
     self.key = key
     self.values = [normalize(v) for v in values]
Ejemplo n.º 11
0
 def __init__(self, keywords, quantifier):
     self.keywords = [normalize(word) for word in keywords]
     self.quantifier = quantifier