summaryrefslogtreecommitdiff
path: root/patchwork/templatetags
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2015-05-27 09:56:36 +0800
committerJeremy Kerr <jk@ozlabs.org>2015-05-28 09:05:45 +0800
commit3b8a61c68fa61eadebf7b19329e8d3bffde9e6b4 (patch)
tree88f53364498523371c2bd1fc33b2e0dbbbb41372 /patchwork/templatetags
parentdaa3ae42eee5e569881070bcc2958b361743f70a (diff)
downloadpatchwork-3b8a61c68fa61eadebf7b19329e8d3bffde9e6b4.tar
patchwork-3b8a61c68fa61eadebf7b19329e8d3bffde9e6b4.tar.gz
Add patch tag infrastructure
This change add patch 'tags', eg 'Acked-by' / 'Reviewed-by', etc., to patchwork. Tag parsing is implemented in the patch parser's extract_tags function, which returns a Counter object of the tags in a comment. These are stored in the PatchTag (keyed to Tag) objects associated with each patch. We need to ensure that the main patch lists do not cause per-patch queries on the Patch.tags ManyToManyField (this would result in ~500 queries per page), so we introduce a new QuerySet (and Manager) for Patch, adding a with_tag_counts() method to populate the tag counts in a single query. As users may be migrating from previous patchwork versions (ie, with no tag counts in the database), we add a 'retag' management command. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'patchwork/templatetags')
-rw-r--r--patchwork/templatetags/patch.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/patchwork/templatetags/patch.py b/patchwork/templatetags/patch.py
index bec0cab..ea23ebd 100644
--- a/patchwork/templatetags/patch.py
+++ b/patchwork/templatetags/patch.py
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django import template
+from django.utils.safestring import mark_safe
import re
register = template.Library()
@@ -63,3 +64,15 @@ class EditablePatchNode(template.Node):
return self.nodelist_false.render(context)
return self.nodelist_true.render(context)
+
+@register.filter(name='patch_tags')
+def patch_tags(patch):
+ counts = []
+ titles = []
+ for tag in patch.project.tags:
+ count = getattr(patch, tag.attr_name)
+ titles.append('%d %s' % (count, tag.name))
+ counts.append(str(count))
+ return mark_safe('<span title="%s">%s</span>' % (
+ ' / '.join(titles),
+ ' '.join(counts)))