From e9de0eca0886794ae48aeec66991a7ff758f981e Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Fri, 12 Jun 2009 15:22:11 +0200 Subject: [PATCH] auto-truncate channel and player names --- pyweb/mumble/templatetags/mumble_extras.py | 6 ++++++ template/mumble/content.htm | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pyweb/mumble/templatetags/mumble_extras.py b/pyweb/mumble/templatetags/mumble_extras.py index f5afdd0..64f8567 100644 --- a/pyweb/mumble/templatetags/mumble_extras.py +++ b/pyweb/mumble/templatetags/mumble_extras.py @@ -28,4 +28,10 @@ def mrange( value ): register.filter( 'mrange', mrange ); +### FILTER: trunc -- converts "a very very extaordinary long text" to "a very very extra..." +def trunc( string, maxlen = 50 ): + if len(string) < maxlen: + return string; + return string[:(maxlen - 3)] + "..."; +register.filter( 'trunc', trunc ); diff --git a/template/mumble/content.htm b/template/mumble/content.htm index 3aed433..7cbe061 100644 --- a/template/mumble/content.htm +++ b/template/mumble/content.htm @@ -26,14 +26,14 @@ {% endspaceless %} {% if item.1.is_player %} player - {{ item.1.name }} + {{ item.1.name|trunc:30 }} {% else %} {% if item.1.linked %} linked channel {% else %} channel {% endif %} - {{ item.1.name }} + {{ item.1.name|trunc:30 }} {% endif %}