misc: add unaccent filter (#44811)

This commit is contained in:
Lauréline Guérin 2020-07-21 15:24:54 +02:00
parent 28293e81a1
commit 19ecf683f2
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 16 additions and 0 deletions

View File

@ -158,6 +158,14 @@ def test_strip_templatetag():
assert tmpl.render({'foo': ' foo barXX'}) == ' foo bar'
def test_unaccent_templatetag():
tmpl = Template('{{ foo|unaccent }}')
assert tmpl.render() == ''
assert tmpl.render({'foo': None}) == ''
assert tmpl.render({'foo': 'FOO bar'}) == 'FOO bar'
assert tmpl.render({'foo': 'félé'}) == 'fele'
def test_template_encoding():
# django
tmpl = Template('{{ foo }} à vélo')

View File

@ -22,6 +22,7 @@ import hashlib
import math
import string
import random
import unicodedata
import pyproj
from pyproj import Geod
@ -89,6 +90,13 @@ def strip(string, chars=None):
return force_text(string).strip()
@register.filter
def unaccent(value):
if not value:
return ''
return force_text(unicodedata.normalize('NFKD', value).encode('ascii', 'ignore'))
@register.filter
def parse_date(date_string):
try: