diff mbox series

[v2] models, templatetags: Make tag count column in patch list optional per tag

Message ID 20171219053203.24210-1-andrew.donnellan@au1.ibm.com
State Accepted
Headers show
Series [v2] models, templatetags: Make tag count column in patch list optional per tag | expand

Commit Message

Andrew Donnellan Dec. 19, 2017, 5:32 a.m. UTC
Add a field, show_column, to the Tag model to determine whether the tag
gets a tag count column in the patch list view. This allows the creation of
tags that will be collated when generating mboxes but won't take up space
in the patch list.

show_column will default to True to maintain the current behaviour by
default.

Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Closes: #142 ("Ability to add tags that don't also have a column in the UI")
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
v1->v2:
  - fix 80 column limit in models.py
  - add the correct migration file that I intended to add...

---
 patchwork/fixtures/default_tags.xml          |  5 ++++-
 patchwork/migrations/0020_tag_show_column.py | 20 ++++++++++++++++++++
 patchwork/models.py                          |  3 +++
 patchwork/templatetags/patch.py              |  2 +-
 patchwork/templatetags/project.py            |  5 +++--
 5 files changed, 31 insertions(+), 4 deletions(-)
 create mode 100644 patchwork/migrations/0020_tag_show_column.py

Comments

Stephen Finucane Jan. 4, 2018, 1:33 p.m. UTC | #1
On Tue, 2017-12-19 at 16:32 +1100, Andrew Donnellan wrote:
> Add a field, show_column, to the Tag model to determine whether the
> tag
> gets a tag count column in the patch list view. This allows the
> creation of
> tags that will be collated when generating mboxes but won't take up
> space
> in the patch list.
> 
> show_column will default to True to maintain the current behaviour by
> default.
> 
> Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
> Closes: #142 ("Ability to add tags that don't also have a column in
> the UI")
> Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

Looks fine to me, so I've gone ahead and applied it. We do need to up
test coverage of these kinds of features, but that's a job for another
day.

Reviewed-by: Stephen Finucane <stephen@that.guru>
Andrew Donnellan Jan. 9, 2018, 7:15 a.m. UTC | #2
On 19/12/17 16:32, Andrew Donnellan wrote:
> Add a field, show_column, to the Tag model to determine whether the tag
> gets a tag count column in the patch list view. This allows the creation of
> tags that will be collated when generating mboxes but won't take up space
> in the patch list.

No-one pointed out that we don't actually collate tags when generating 
mboxes by reference to Tag objects, we just use a fixed regex :) I've 
opened a GitHub issue to track that...
Stephen Finucane Jan. 9, 2018, 2:43 p.m. UTC | #3
On Tue, 2018-01-09 at 18:15 +1100, Andrew Donnellan wrote:
> On 19/12/17 16:32, Andrew Donnellan wrote:
> > Add a field, show_column, to the Tag model to determine whether the
> > tag
> > gets a tag count column in the patch list view. This allows the
> > creation of
> > tags that will be collated when generating mboxes but won't take up
> > space
> > in the patch list.
> 
> No-one pointed out that we don't actually collate tags when
> generating mboxes by reference to Tag objects, we just use a fixed
> regex :)

Indeed. I think I've a TODO there but it's on my (rather lengthy)
backlog.

> I've opened a GitHub issue to track that...

++

Stephen
diff mbox series

Patch

diff --git a/patchwork/fixtures/default_tags.xml b/patchwork/fixtures/default_tags.xml
index ca5ccfd..baffd43 100644
--- a/patchwork/fixtures/default_tags.xml
+++ b/patchwork/fixtures/default_tags.xml
@@ -4,15 +4,18 @@ 
     <field type="CharField" name="name">Acked-by</field>
     <field type="CharField" name="pattern">^Acked-by:</field>
     <field type="CharField" name="abbrev">A</field>
+    <field type="BooleanField" name="show_column">True</field>
   </object>
   <object pk="2" model="patchwork.tag">
     <field type="CharField" name="name">Reviewed-by</field>
     <field type="CharField" name="pattern">^Reviewed-by:</field>
     <field type="CharField" name="abbrev">R</field>
+    <field type="BooleanField" name="show_column">True</field>
   </object>
   <object pk="3" model="patchwork.tag">
     <field type="CharField" name="name">Tested-by</field>
     <field type="CharField" name="pattern">^Tested-by:</field>
     <field type="CharField" name="abbrev">T</field>
+    <field type="BooleanField" name="show_column">True</field>
   </object>
-</django-objects>
\ No newline at end of file
+</django-objects>
diff --git a/patchwork/migrations/0020_tag_show_column.py b/patchwork/migrations/0020_tag_show_column.py
new file mode 100644
index 0000000..62fe80a
--- /dev/null
+++ b/patchwork/migrations/0020_tag_show_column.py
@@ -0,0 +1,20 @@ 
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.8 on 2017-12-19 04:03
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0019_userprofile_show_ids'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='tag',
+            name='show_column',
+            field=models.BooleanField(default=True, help_text=b"Show a column displaying this tag's count in the patch list view"),
+        ),
+    ]
diff --git a/patchwork/models.py b/patchwork/models.py
index 7d413d9..b746588 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -230,6 +230,9 @@  class Tag(models.Model):
     abbrev = models.CharField(
         max_length=2, unique=True, help_text='Short (one-or-two letter)'
         ' abbreviation for the tag, used in table column headers')
+    show_column = models.BooleanField(help_text='Show a column displaying this'
+                                      ' tag\'s count in the patch list view',
+                                      default=True)
 
     @property
     def attr_name(self):
diff --git a/patchwork/templatetags/patch.py b/patchwork/templatetags/patch.py
index c65bd5e..4350e09 100644
--- a/patchwork/templatetags/patch.py
+++ b/patchwork/templatetags/patch.py
@@ -34,7 +34,7 @@  register = template.Library()
 def patch_tags(patch):
     counts = []
     titles = []
-    for tag in patch.project.tags:
+    for tag in [t for t in patch.project.tags if t.show_column]:
         count = getattr(patch, tag.attr_name)
         titles.append('%d %s' % (count, tag.name))
         if count == 0:
diff --git a/patchwork/templatetags/project.py b/patchwork/templatetags/project.py
index 689b486..32d8011 100644
--- a/patchwork/templatetags/project.py
+++ b/patchwork/templatetags/project.py
@@ -28,6 +28,7 @@  register = template.Library()
 
 @register.simple_tag(takes_context=True)
 def project_tags(context):
+    tags = [t for t in context['project'].tags if t.show_column]
     return mark_safe('<span title="%s">%s</span>' % (
-        ' / '.join([tag.name for tag in context['project'].tags]),
-        '/'.join([tag.abbrev for tag in context['project'].tags])))
+        ' / '.join([tag.name for tag in tags]),
+        '/'.join([tag.abbrev for tag in tags])))