From patchwork Tue Jun 21 15:22:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Limit the length of patch names when they are used in the heading of a page Date: Tue, 21 Jun 2011 05:22:34 -0000 From: Guilherme Salgado X-Patchwork-Id: 101296 Message-Id: <20110621151833.9689.67713.stgit@localhost6.localdomain6> To: patchwork@lists.ozlabs.org Cc: patches@linaro.org If we don't do this they may span multiple lines, causing the top-bar to expand and look awful. Signed-off-by: Guilherme Salgado --- An example of a patch which has a name too long: http://patchwork.ozlabs.org/patch/99869/ Oh, the 70-chars length was chosen because with that added to the other (fixed) elements of the heading it still fits in one line on a 1280px wide screen. Feel free to tweak it to a smaller number if you'd like it to fit on a 1024px wide screen. apps/patchwork/templatetags/truncate.py | 10 ++++++++++ templates/patchwork/patch.html | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletions(-) create mode 100644 apps/patchwork/templatetags/truncate.py diff --git a/apps/patchwork/templatetags/truncate.py b/apps/patchwork/templatetags/truncate.py new file mode 100644 index 0000000..3097826 --- /dev/null +++ b/apps/patchwork/templatetags/truncate.py @@ -0,0 +1,10 @@ +from django import template +register = template.Library() + +@register.filter +def truncate(text, chars): + """Truncates the given text after the given number of chars.""" + if len(text) > chars: + return text[:chars] + "..." + else: + return text diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html index 25c9962..3c52e61 100644 --- a/templates/patchwork/patch.html +++ b/templates/patchwork/patch.html @@ -3,9 +3,10 @@ {% load syntax %} {% load person %} {% load patch %} +{% load truncate %} {% block title %}{{patch.name}}{% endblock %} -{% block heading %}{{patch.name}}{%endblock%} +{% block heading %}{{patch.name|truncate:70}}{%endblock%} {% block body %}