def render(self, context): output = self.nodelist.render(context) terms = self.terms if terms[0] == terms[-1] and terms[0] in ("'", '"'): terms = terms[1:-1] else: terms = self.terms_var.resolve(context) return highlight(output, remove_duplicates(RE_ARG_SPLIT.split(terms)))
def process_response(self, request, response): """ Transform the HTML if keywords are present. """ if (response.status_code != 200 or not 'text/html' in response['Content-Type']): return response referrer = request.META.get('HTTP_REFERER') engine, domain, terms = self.parse_search(referrer) for GET_varname in GET_VARNAMES: if request.GET.get(GET_varname): terms.extend(request.GET[GET_varname].split()) if not terms: return response response.content = highlight(response.content, remove_duplicates(terms)) return response
def test_remove_duplicates_with_void_value(self): self.assertEquals( remove_duplicates(['titi', ' ', 'toto', '', ' titi']), ['titi', 'toto'])
def test_remove_duplicates_with_spaces(self): self.assertEquals(remove_duplicates(['titi', 'toto', 'tata', ' titi']), ['titi', 'toto', 'tata'])
def excerpt_filter(value, terms): return excerpt(value, remove_duplicates(RE_ARG_SPLIT.split(terms)))
def highlight_filter(value, terms, autoescape=None): esc = autoescape and conditional_escape or (lambda x: x) return mark_safe( highlight(esc(value), remove_duplicates(RE_ARG_SPLIT.split(terms))))
def test_remove_duplicates_with_spaces(self): self.assertEquals( remove_duplicates(['titi', 'toto', 'tata', ' titi']), ['titi', 'toto', 'tata'])
def highlight_filter(value, terms, autoescape=None): esc = autoescape and conditional_escape or (lambda x: x) return mark_safe(highlight(esc(value), remove_duplicates(RE_ARG_SPLIT.split(terms))))