[damned-lies] Fixes bug #569915: make comments with special syntax to be rendered as bugzilla links



commit dbf8b07d1f46d2054649ce98bcfd9bc3727ac0f9
Author: Gil Forcada <gforcada gnome org>
Date:   Wed Jan 4 01:43:03 2012 +0100

    Fixes bug #569915: make comments with special syntax to be rendered as bugzilla links

 stats/templatetags/stats_extras.py      |   13 +++++++++++++
 templates/vertimus/vertimus_detail.html |    2 +-
 2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index 6d22f3a..5ffee1c 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -1,3 +1,5 @@
+import re
+
 from django import template
 from django.conf import settings
 from django.utils.safestring import mark_safe
@@ -156,3 +158,14 @@ def as_tr(field):
     return mark_safe(u'<tr><th>%s:</th><td>%s%s%s%s</td></tr>' % (
         field.label_tag(), errors_html, field.as_widget(), help_link, help_html)
     )
+
+ register filter
+def bugzilla_linkify(text):
+    """Searches within the given text if a text matching a bugzilla bug reference
+    is found and transforms it to a link to that bug"""
+    bug_id = re.compile('(?P<id>#[0-9]+)')
+    repl = u'<a rel="nofollow" href="https://bugzilla.gnome.org/show_bug.cgi?id=\g<id>">\g<id></a>'
+
+    result = bug_id.sub(repl, text)
+    result = result.replace('.cgi?id=#', '.cgi?id=')
+    return mark_safe(result)
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 860755e..b5a9efe 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -184,7 +184,7 @@ $(document).ready(function() {
       </div>
       {% endif %}
       {% if action.comment %}
-        <p class="vertimus_action_comment">{{ action.comment|urlize|linebreaksbr }}</p>
+        <p class="vertimus_action_comment">{{ action.comment|urlize|linebreaksbr|bugzilla_linkify }}</p>
       {% else %}
         <p><em>{% trans "No comment" %}</em></p>
       {% endif %}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]