diff --git a/core/templates/search/indexes/core/user_auto.txt b/core/templates/search/indexes/core/user_auto.txt index 09d8005c..9966df06 100644 --- a/core/templates/search/indexes/core/user_auto.txt +++ b/core/templates/search/indexes/core/user_auto.txt @@ -1,13 +1,13 @@ -{% load replace %} +{% load search_helpers %} {% with first=object.first_name|safe|slugify last=object.last_name|safe|slugify nick=object.nick_name|default_if_none:""|safe|slugify %} {{ first|replace:"|-| " }} {{ last|replace:"|-| " }} {{ nick|replace:"|-| " }} -{{ first|cut:"-" }} -{{ last|cut:"-" }} -{{ nick|cut:"-" }} +{% if first|count:"-" != 0 %}{{ first|cut:"-" }}{% endif %} +{% if last|count:"-" != 0 %}{{ last|cut:"-" }}{% endif %} +{% if nick|count:"-" != 0 %}{{ nick|cut:"-" }}{% endif %} {{ first|cut:"-" }}{{ last|cut:"-" }} {% endwith %} diff --git a/core/templatetags/replace.py b/core/templatetags/search_helpers.py similarity index 90% rename from core/templatetags/replace.py rename to core/templatetags/search_helpers.py index f75fa74a..537ff357 100644 --- a/core/templatetags/replace.py +++ b/core/templatetags/search_helpers.py @@ -20,3 +20,8 @@ def replace(value, arg): raise TemplateSyntaxError("badly formatted argument") return value.replace(arg[1], arg[2]) + + +@register.filter +def count(value, arg): + return value.count(arg)