kpsul/kfet/templatetags/kfet_tags.py
Martin Pepin 75ff77c4ec Merge branch 'Aufinal/search_account' into 'k-fet'
Popup de recherche de compte

Quand on clique sur l'icone de recherche (ou qu'on appuie sur Ctrl+F depuis la zone de saisie de trigramme) un popup apparaît pour rechercher les comptes par prénom ou par nom, en utilisant `autocomplete`.

Fix #109

See merge request !153
2017-01-25 23:58:08 +01:00

46 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
from django import template
from django.utils.html import escape
from django.utils.safestring import mark_safe
from kfet.models import Settings
from math import floor
import re
register = template.Library()
@register.filter()
def highlight_text(text, q):
q2 = "|".join(q.split())
pattern = re.compile(r"(?P<filter>%s)" % q2, re.IGNORECASE)
return mark_safe(
re.sub(pattern,
r"<span class='highlight_autocomplete'>\g<filter></span>",
escape(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(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(text, q)
@register.filter()
def ukf(balance, is_cof):
grant = is_cof and (1 + Settings.SUBVENTION_COF() / 100) or 1
# float nécessaire car sinon problème avec le round de future.builtins
return floor(float(balance) * 10 * grant)