From eff37f6c89e76e531d02afd279a77cd377d578b0 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 19 Jan 2017 01:42:00 -0200 Subject: [PATCH] plain text highlighting --- kfet/templatetags/kfet_tags.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kfet/templatetags/kfet_tags.py b/kfet/templatetags/kfet_tags.py index bb8bce9f..7ab903b3 100644 --- a/kfet/templatetags/kfet_tags.py +++ b/kfet/templatetags/kfet_tags.py @@ -1,22 +1,23 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * - from django import template from django.utils.html import escape from django.utils.safestring import mark_safe -from django.core.cache import cache from kfet.models import Settings import re register = template.Library() + +@register.filter() def highlight_text(text, q): q2 = "|".join(q.split()) pattern = re.compile(r"(?P%s)" % q2, re.IGNORECASE) - return mark_safe(re.sub(pattern, r"\g", text)) + return mark_safe( + re.sub(pattern, + r"\g", + escape(text))) + @register.filter(is_safe=True) def highlight_user(user, q): @@ -24,7 +25,8 @@ def highlight_user(user, q): text = "%s %s (%s)" % (user.first_name, user.last_name, user.username) else: text = user.username - return highlight_text(escape(text), q) + return highlight_text(text, q) + @register.filter(is_safe=True) def highlight_clipper(clipper, q): @@ -32,7 +34,8 @@ def highlight_clipper(clipper, q): text = "%s (%s)" % (clipper.fullname, clipper.username) else: text = clipper.username - return highlight_text(escape(text), q) + return highlight_text(text, q) + @register.filter() def ukf(balance, is_cof):