Skip to content

Commit 66fd197

Browse files
loudonlunestephenfin
authored andcommitted
models: Add fields for series dependencies
* Add a ManyToMany field to represent a dependency relationship between patch series and a helper method to add dependencies. * Add the parse_dependency field to the Project model. Signed-off-by: Adam Hassick <[email protected]> Acked-by: Aaron Conole <[email protected]> [stephenfin: Rename Project field from parse_dependencies to show_dependencies. Also add 'blank=True' to Series.cover_letter field] Signed-off-by: Stephen Finucane <[email protected]>
1 parent 359a856 commit 66fd197

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from django.db import migrations, models
2+
import django.db.models.deletion
3+
4+
5+
class Migration(migrations.Migration):
6+
dependencies = [
7+
('patchwork', '0047_add_database_indexes'),
8+
]
9+
10+
operations = [
11+
migrations.AddField(
12+
model_name='series',
13+
name='dependencies',
14+
field=models.ManyToManyField(
15+
blank=True,
16+
help_text='Optional dependencies on this patch.',
17+
related_name='dependents',
18+
related_query_name='dependent',
19+
to='patchwork.series',
20+
),
21+
),
22+
migrations.AddField(
23+
model_name='project',
24+
name='show_dependencies',
25+
field=models.BooleanField(
26+
default=False,
27+
help_text='Enable dependency tracking for patches and cover '
28+
'letters.',
29+
),
30+
),
31+
migrations.AlterField(
32+
model_name='series',
33+
name='cover_letter',
34+
field=models.OneToOneField(
35+
blank=True,
36+
null=True,
37+
on_delete=django.db.models.deletion.CASCADE,
38+
related_name='series',
39+
to='patchwork.cover',
40+
),
41+
),
42+
]

patchwork/models.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class Project(models.Model):
100100
# configuration options
101101

102102
send_notifications = models.BooleanField(default=False)
103+
show_dependencies = models.BooleanField(
104+
default=False,
105+
help_text='Enable dependency tracking for patches and cover letters.',
106+
)
103107
use_tags = models.BooleanField(default=True)
104108

105109
def is_editable(self, user):
@@ -837,7 +841,21 @@ class Series(FilenameMixin, models.Model):
837841

838842
# content
839843
cover_letter = models.OneToOneField(
840-
Cover, related_name='series', null=True, on_delete=models.CASCADE
844+
Cover,
845+
related_name='series',
846+
null=True,
847+
blank=True,
848+
on_delete=models.CASCADE,
849+
)
850+
851+
# dependencies
852+
dependencies = models.ManyToManyField(
853+
'self',
854+
symmetrical=False,
855+
blank=True,
856+
help_text='Optional dependencies on this patch.',
857+
related_name='dependents',
858+
related_query_name='dependent',
841859
)
842860

843861
# metadata
@@ -879,6 +897,22 @@ def received_total(self):
879897
def received_all(self):
880898
return self.total <= self.received_total
881899

900+
def add_dependencies(self, dependencies):
901+
"""Add dependencies to this series.
902+
903+
Helper method to add any found dependencies to this series.
904+
The method will filter out self and any series not from the
905+
same project.
906+
"""
907+
self.dependencies.add(
908+
*(
909+
dep
910+
for dep in dependencies
911+
if dep.id != self.id and dep.project == self.project
912+
)
913+
)
914+
self.save()
915+
882916
def add_cover_letter(self, cover):
883917
"""Add a cover letter to the series.
884918

0 commit comments

Comments
 (0)