From: Adam Hassick Date: Thu, 30 Jan 2025 19:56:36 +0000 (-0500) Subject: models: Add fields for series dependencies X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01a5b4665dd92e75727567f3d4f340ab9278538d;p=thirdparty%2Fpatchwork.git 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 Acked-by: Aaron Conole [stephenfin: Rename Project field from parse_dependencies to show_dependencies. Also add 'blank=True' to Series.cover_letter field] Signed-off-by: Stephen Finucane --- diff --git a/patchwork/migrations/0048_series_dependencies.py b/patchwork/migrations/0048_series_dependencies.py new file mode 100644 index 00000000..8368a249 --- /dev/null +++ b/patchwork/migrations/0048_series_dependencies.py @@ -0,0 +1,42 @@ +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ('patchwork', '0047_add_database_indexes'), + ] + + operations = [ + migrations.AddField( + model_name='series', + name='dependencies', + field=models.ManyToManyField( + blank=True, + help_text='Optional dependencies on this patch.', + related_name='dependents', + related_query_name='dependent', + to='patchwork.series', + ), + ), + migrations.AddField( + model_name='project', + name='show_dependencies', + field=models.BooleanField( + default=False, + help_text='Enable dependency tracking for patches and cover ' + 'letters.', + ), + ), + migrations.AlterField( + model_name='series', + name='cover_letter', + field=models.OneToOneField( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name='series', + to='patchwork.cover', + ), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index b67d1138..ae2f4a6d 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -100,6 +100,10 @@ class Project(models.Model): # configuration options send_notifications = models.BooleanField(default=False) + show_dependencies = models.BooleanField( + default=False, + help_text='Enable dependency tracking for patches and cover letters.', + ) use_tags = models.BooleanField(default=True) def is_editable(self, user): @@ -837,7 +841,21 @@ class Series(FilenameMixin, models.Model): # content cover_letter = models.OneToOneField( - Cover, related_name='series', null=True, on_delete=models.CASCADE + Cover, + related_name='series', + null=True, + blank=True, + on_delete=models.CASCADE, + ) + + # dependencies + dependencies = models.ManyToManyField( + 'self', + symmetrical=False, + blank=True, + help_text='Optional dependencies on this patch.', + related_name='dependents', + related_query_name='dependent', ) # metadata @@ -879,6 +897,22 @@ class Series(FilenameMixin, models.Model): def received_all(self): return self.total <= self.received_total + def add_dependencies(self, dependencies): + """Add dependencies to this series. + + Helper method to add any found dependencies to this series. + The method will filter out self and any series not from the + same project. + """ + self.dependencies.add( + *( + dep + for dep in dependencies + if dep.id != self.id and dep.project == self.project + ) + ) + self.save() + def add_cover_letter(self, cover): """Add a cover letter to the series.