Patchwork Limit the length of patch names when they are used in the heading of a page

login
register
mail settings
Submitter Guilherme Salgado
Date June 21, 2011, 3:22 p.m.
Message ID <20110621151833.9689.67713.stgit@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/101296/
State Superseded
Headers show

Comments

Guilherme Salgado - June 21, 2011, 3:22 p.m.
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 <guilherme.salgado@linaro.org>
---

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

Patch

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 %}
 <script language="JavaScript" type="text/javascript">
@@ -33,6 +34,10 @@  function toggle_headers(link_id, headers_id)
   <td>{{ patch.submitter|personify }}</td></tr>
  </tr>
  <tr>
+  <th>Subject</th>
+  <td>{{ patch.name }}</td></tr>
+ </tr>
+ <tr>
   <th>Date</th>
   <td>{{ patch.date }}</td>
  </tr>