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.

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 <step...@that.guru>
---
 patchwork/fixtures/default_labels.xml         |  9 +++++++
 patchwork/migrations/0026_add_patch_labels.py | 39 +++++++++++++++++++++++++++
 patchwork/models.py                           | 35 ++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 patchwork/fixtures/default_labels.xml
 create mode 100644 patchwork/migrations/0026_add_patch_labels.py

diff --git a/patchwork/fixtures/default_labels.xml 
b/patchwork/fixtures/default_labels.xml
new file mode 100644
index 00000000..31313745
--- /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">1</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">15592941</field>
+  </object>
+</django-objects>
\ No newline at end of file
diff --git a/patchwork/migrations/0026_add_patch_labels.py 
b/patchwork/migrations/0026_add_patch_labels.py
new file mode 100644
index 00000000..af503143
--- /dev/null
+++ b/patchwork/migrations/0026_add_patch_labels.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-04-13 13:22
+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', '0025_add_regex_validators'),
+    ]
+
+    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, on_delete=django.db.models.deletion.CASCADE, related_name='labels', 
related_query_name='label', to='patchwork.Project')),
+            ],
+            options={
+                'ordering': ['name'],
+            },
+        ),
+        migrations.AddField(
+            model_name='patch',
+            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 f91b994c..9b7b8ceb 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -36,6 +36,7 @@ from django.utils.functional import cached_property
 
 from patchwork.compat import is_authenticated
 from patchwork.compat import reverse
+from patchwork.fields import ColorField
 from patchwork.fields import HashField
 from patchwork.hasher import hash_diff
 
@@ -237,6 +238,39 @@ class State(models.Model):
         ordering = ['ordering']
 
 
+@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,
+        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)
@@ -424,6 +458,7 @@ class Patch(SeriesMixin, Submission):
     commit_ref = models.CharField(max_length=255, null=True, blank=True)
     pull_url = models.CharField(max_length=255, null=True, blank=True)
     tags = models.ManyToManyField(Tag, through=PatchTag)
+    labels = models.ManyToManyField(Label)
 
     # patchwork metadata
 
-- 
2.14.3

_______________________________________________
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to