[PATCH v2 02/10] models: Add submission labels

Stephen Finucane stephen at that.guru
Sun Oct 14 23:45:33 AEDT 2018


Labels are arbitrary bits of metadata attached to a submission. They can
be used to signify priority, category, or other similar information.
They can also be used to filter patches and identify the ones most
interesting to a given user.

Labels can be associated with a project to ensure that one project can
use a totally different set of labels to another and to, in the future,
allow a project administrator to use their own labels. However, they can
also be global, which is useful for things that would be common across
multiple projects such as "RFC".

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
v2:
- Associate labels with cover letters as well as patches
- Update migration numbers
- Add release note
---
 patchwork/fixtures/default_labels.xml         |  9 +++++
 patchwork/migrations/0031_add_labels.py       | 39 +++++++++++++++++++
 patchwork/models.py                           | 35 +++++++++++++++++
 .../notes/labels-6d0096c7d8505627.yaml        | 11 ++++++
 4 files changed, 94 insertions(+)
 create mode 100644 patchwork/fixtures/default_labels.xml
 create mode 100644 patchwork/migrations/0031_add_labels.py
 create mode 100644 releasenotes/notes/labels-6d0096c7d8505627.yaml

diff --git a/patchwork/fixtures/default_labels.xml b/patchwork/fixtures/default_labels.xml
new file mode 100644
index 00000000..1e1aa705
--- /dev/null
+++ b/patchwork/fixtures/default_labels.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<django-objects version="1.0">
+  <object model="patchwork.label" pk="1">
+    <field name="project" rel="ManyToOneRel" to="patchwork.project"><None></None></field>
+    <field name="name" type="CharField">RFC</field>
+    <field name="description" type="TextField">"RFC" stands for "Request for Comment", which tells maintainers that they should review your patch thoroughly and provide feedback. RFC is typically used when sending feature patches for the first time, or anytime the patch is more than just a simple bug fix.</field>
+    <field name="color" type="PositiveIntegerField">#EDEDED</field>
+  </object>
+</django-objects>
diff --git a/patchwork/migrations/0031_add_labels.py b/patchwork/migrations/0031_add_labels.py
new file mode 100644
index 00000000..ba93ecd6
--- /dev/null
+++ b/patchwork/migrations/0031_add_labels.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.15 on 2018-09-13 03:49
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import patchwork.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0030_add_submission_covering_index'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Label',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(help_text=b'The label value.', max_length=25)),
+                ('description', models.TextField(blank=True, help_text=b'A description of what the label is and when it should be applied.', null=True)),
+                ('color', patchwork.fields.ColorField(help_text=b'The color code to use in the UI.')),
+                ('project', models.ForeignKey(help_text=b'The project this label is associated with. If unset, this label is global to the instance', null=True, blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='labels', related_query_name='label', to='patchwork.Project')),
+            ],
+            options={
+                'ordering': ['name'],
+            },
+        ),
+        migrations.AddField(
+            model_name='submission',
+            name='labels',
+            field=models.ManyToManyField(to='patchwork.Label'),
+        ),
+        migrations.AlterUniqueTogether(
+            name='label',
+            unique_together=set([('project', 'name')]),
+        ),
+    ]
diff --git a/patchwork/models.py b/patchwork/models.py
index a043844d..b6a1fe38 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -18,6 +18,7 @@ from django.urls import reverse
 from django.utils.encoding import python_2_unicode_compatible
 from django.utils.functional import cached_property
 
+from patchwork.fields import ColorField
 from patchwork.fields import HashField
 from patchwork.hasher import hash_diff
 
@@ -219,6 +220,39 @@ class State(models.Model):
         ordering = ['ordering']
 
 
+ at python_2_unicode_compatible
+class Label(models.Model):
+    """Labels for patches.
+
+    Labels are arbitrary bits of metadata attached to a patch. They can
+    be used to signify priority, category, or other similar information.
+    They can also be used to filter patches and identify the ones most
+    interesting to a given user.
+    """
+    project = models.ForeignKey(
+        Project, related_name='labels', related_query_name='label', null=True,
+        blank=True, on_delete=models.CASCADE,
+        help_text='The project this label is associated with. If unset, this '
+        'label is global to the instance')
+
+    name = models.CharField(
+        max_length=25,
+        help_text='The label value.')
+    description = models.TextField(
+        null=True, blank=True,
+        help_text='A description of what the label is and when it should be '
+        'applied.')
+    color = ColorField(
+        help_text='The color code to use in the UI.')
+
+    def __str__(self):
+        return self.name
+
+    class Meta:
+        ordering = ['name']
+        unique_together = [('project', 'name')]
+
+
 @python_2_unicode_compatible
 class Tag(models.Model):
     name = models.CharField(max_length=20)
@@ -355,6 +389,7 @@ class Submission(FilenameMixin, EmailMixin, models.Model):
     # submission metadata
 
     name = models.CharField(max_length=255)
+    labels = models.ManyToManyField(Label)
 
     # patchwork metadata
 
diff --git a/releasenotes/notes/labels-6d0096c7d8505627.yaml b/releasenotes/notes/labels-6d0096c7d8505627.yaml
new file mode 100644
index 00000000..fdebd6b7
--- /dev/null
+++ b/releasenotes/notes/labels-6d0096c7d8505627.yaml
@@ -0,0 +1,11 @@
+---
+features:
+  - |
+    Add support for patch labels. Labels are a way to organize and prioritize
+    submissions. You can apply labels to patches and cover letters to signify
+    priority, category, or any other marker you wish.
+
+    Labels can be either global or tied to the project they are created in.
+    Labels can have an optional description attached, which will provide a
+    little insight into the purpose of the label. Labels are completely
+    customizable and the labels available will vary by instance.
-- 
2.17.1



More information about the Patchwork mailing list