def filter(self, search_term): self._filter = search_term.lower() self_pass = False if RKeynoteFilters.UsedOnly.code in self._filter: self_pass = self.used elif RKeynoteFilters.UnusedOnly.code in self._filter: self_pass = not self.used elif RKeynoteFilters.LockedOnly.code in self._filter: self_pass = self.locked elif RKeynoteFilters.UnlockedOnly.code in self._filter: self_pass = not self.locked cleaned_sfilter = RKeynoteFilters.remove_filters(self._filter) has_smart_filter = cleaned_sfilter != self._filter if cleaned_sfilter: sterm = self.key + ' ' + self.text + ' ' + self.owner # here is where matching against the string happens self_pass_keyword = \ coreutils.fuzzy_search_ratio(sterm.lower(), cleaned_sfilter) > 80 if has_smart_filter: self_pass = self_pass_keyword and self_pass else: self_pass = self_pass_keyword # filter children now self._filtered_children = \ [x for x in self._children if x.filter(self._filter)] return self_pass or self._filtered_children
def filter(self, search_term): self._filter = search_term.lower() self_pass = False # use regex for string matching? use_regex = RKeynoteFilters.UseRegex.code in self._filter use_regex_not = RKeynoteFilters.UseRegexNegate.code in self._filter if RKeynoteFilters.ViewOnly.code in self._filter: self_pass = self.key in RKeynoteFilters.ViewOnly elif RKeynoteFilters.UsedOnly.code in self._filter: self_pass = self.used elif RKeynoteFilters.UnusedOnly.code in self._filter: self_pass = not self.used elif RKeynoteFilters.LockedOnly.code in self._filter: self_pass = self.locked elif RKeynoteFilters.UnlockedOnly.code in self._filter: self_pass = not self.locked cleaned_sfilter = RKeynoteFilters.remove_filters(self._filter) has_smart_filter = cleaned_sfilter != self._filter if cleaned_sfilter: sterm = self.key + ' ' + self.text + ' ' + self.owner sterm = sterm.lower() # here is where matching against the string happens if use_regex or use_regex_not: # check if pattern is valid try: self_pass = re.search( cleaned_sfilter, sterm, re.IGNORECASE ) except Exception: self_pass = False if use_regex_not: self_pass = not self_pass else: self_pass_keyword = \ coreutils.fuzzy_search_ratio(sterm, cleaned_sfilter) > 80 if has_smart_filter: self_pass = self_pass_keyword and self_pass else: self_pass = self_pass_keyword # filter children now self._filtered_children = \ [x for x in self._children if x.filter(self._filter)] return self_pass or self._filtered_children