# -*- 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 from math import floor import re register = template.Library() 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)) @register.filter(is_safe=True) def highlight_user(user, q): if user.first_name and user.last_name: text = "%s %s (%s)" % (user.first_name, user.last_name, user.username) else: text = user.username return highlight_text(escape(text), q) @register.filter(is_safe=True) def highlight_clipper(clipper, q): if clipper.fullname: text = "%s (%s)" % (clipper.fullname, clipper.username) else: text = clipper.username return highlight_text(escape(text), q) @register.filter() def ukf(balance, is_cof): grant = is_cof and (1 + Settings.SUBVENTION_COF() / 100) or 1 return floor(balance * 10 * grant)