[PATCH] Limit the length of patch names when they are used in the heading of a page

Guilherme Salgado guilherme.salgado at linaro.org
Wed Jun 22 01:22:34 EST 2011


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 at 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

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()
+
+ at 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>



More information about the Patchwork mailing list