Skip to content

Commit 5913fc2

Browse files
stephenfinfstachura
authored andcommitted
models: Add submission labels
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".
1 parent bacb840 commit 5913fc2

4 files changed

Lines changed: 148 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<django-objects version="1.0">
3+
<object model="patchwork.label" pk="1">
4+
<field name="project" rel="ManyToOneRel" to="patchwork.project"><None></None></field>
5+
<field name="name" type="CharField">RFC</field>
6+
<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>
7+
<field name="color" type="PositiveIntegerField">#EDEDED</field>
8+
</object>
9+
</django-objects>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Generated by Django 6.0.7 on 2026-07-31 21:26
2+
3+
import django.db.models.deletion
4+
import patchwork.fields
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
dependencies = [
10+
('patchwork', '0053_series_ordering_indexes'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Label',
16+
fields=[
17+
(
18+
'id',
19+
models.AutoField(
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
verbose_name='ID',
24+
),
25+
),
26+
(
27+
'name',
28+
models.CharField(
29+
help_text='The label value.', max_length=25
30+
),
31+
),
32+
(
33+
'description',
34+
models.TextField(
35+
blank=True,
36+
help_text='A description of what the label is '
37+
'and when it should be applied.',
38+
null=True,
39+
),
40+
),
41+
(
42+
'color',
43+
patchwork.fields.ColorField(
44+
help_text='The color code to use in the UI.'
45+
),
46+
),
47+
(
48+
'project',
49+
models.ForeignKey(
50+
blank=True,
51+
help_text='The project this label is associated with. '
52+
'If unset, this label is global to the instance',
53+
null=True,
54+
on_delete=django.db.models.deletion.CASCADE,
55+
related_name='labels',
56+
related_query_name='label',
57+
to='patchwork.project',
58+
),
59+
),
60+
],
61+
options={
62+
'ordering': ['name'],
63+
'unique_together': {('project', 'name')},
64+
},
65+
),
66+
migrations.AddField(
67+
model_name='cover',
68+
name='labels',
69+
field=models.ManyToManyField(to='patchwork.label'),
70+
),
71+
migrations.AddField(
72+
model_name='patch',
73+
name='labels',
74+
field=models.ManyToManyField(to='patchwork.label'),
75+
),
76+
]

‎patchwork/models.py‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from django.utils.functional import cached_property
2020
from django.utils import timezone as tz_utils
2121

22-
from patchwork.fields import HashField
22+
from patchwork.fields import HashField, ColorField
2323
from patchwork.hasher import hash_diff
2424

2525
if settings.ENABLE_REST_API:
@@ -261,6 +261,56 @@ class Meta:
261261
ordering = ['ordering']
262262

263263

264+
class Label(models.Model):
265+
"""Labels for patches.
266+
267+
Labels are arbitrary bits of metadata attached to a patch. They can
268+
be used to signify priority, category, or other similar information.
269+
They can also be used to filter patches and identify the ones most
270+
interesting to a given user.
271+
"""
272+
273+
project = models.ForeignKey(
274+
Project,
275+
related_name='labels',
276+
related_query_name='label',
277+
null=True,
278+
blank=True,
279+
on_delete=models.CASCADE,
280+
help_text='The project this label is associated with. If unset, this '
281+
'label is global to the instance',
282+
)
283+
284+
name = models.CharField(max_length=25, help_text='The label value.')
285+
description = models.TextField(
286+
null=True,
287+
blank=True,
288+
help_text='A description of what the label is and when it should be '
289+
'applied.',
290+
)
291+
color = ColorField(help_text='The color code to use in the UI.')
292+
293+
def __str__(self):
294+
return self.name
295+
296+
@staticmethod
297+
def get_project_labels(project):
298+
result = {}
299+
project_labels = Label.objects.filter(
300+
models.Q(project=project) | models.Q(project__isnull=True)
301+
).all()
302+
303+
for label in project_labels:
304+
if label.name not in result or label.project is not None:
305+
result[label.name] = label
306+
307+
return list(result.values())
308+
309+
class Meta:
310+
ordering = ['name']
311+
unique_together = [('project', 'name')]
312+
313+
264314
class Tag(models.Model):
265315
name = models.CharField(max_length=20)
266316
pattern = models.CharField(
@@ -441,6 +491,7 @@ class SubmissionMixin(FilenameMixin, EmailMixin, models.Model):
441491
# submission metadata
442492

443493
name = models.CharField(max_length=255)
494+
labels = models.ManyToManyField(Label)
444495

445496
@cached_property
446497
def list_archive_url(self):
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
features:
3+
- |
4+
Add support for patch labels. Labels are a way to organize and prioritize
5+
submissions. You can apply labels to patches and cover letters to signify
6+
priority, category, or any other marker you wish.
7+
8+
Labels can be either global or tied to the project they are created in.
9+
Labels can have an optional description attached, which will provide a
10+
little insight into the purpose of the label. Labels are completely
11+
customizable and the labels available will vary by instance.

0 commit comments

Comments
 (0)