]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Add list archive lookup
authorAndrew Donnellan <ajd@linux.ibm.com>
Thu, 22 Aug 2019 07:12:58 +0000 (17:12 +1000)
committerDaniel Axtens <dja@axtens.net>
Thu, 22 Aug 2019 11:14:08 +0000 (21:14 +1000)
Add a list_archive_url_format field to Project, which will contain the
address of a Message-ID redirector, e.g. "https://lore.kernel.org/r/{}".

Add a list_archive_url property to Submission and Comment, to generate an
archive lookup URL based on the Message-ID.

We will use this to display links to mailing list archives.

Also add the new field to the default patchwork project fixture.

Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Daniel Axtens <dja@axtens.net>
patchwork/fixtures/default_projects.xml
patchwork/migrations/0035_project_list_archive_url_format.py [new file with mode: 0644]
patchwork/models.py

index 39d269836394b5052e4c676cfde4546664c293de..0895502dac71b199ab8c2bf5712918a9d63292cc 100644 (file)
@@ -6,5 +6,6 @@
     <field type="CharField" name="listid">patchwork.ozlabs.org</field>
     <field type="CharField" name="listemail">patchwork@lists.ozlabs.org</field>
     <field type="CharField" name="list_archive_url">https://lists.ozlabs.org/pipermail/patchwork/</field>
+    <field type="CharField" name="list_archive_url_format">http://mid.mail-archive.com/{}</field>
   </object>
 </django-objects>
diff --git a/patchwork/migrations/0035_project_list_archive_url_format.py b/patchwork/migrations/0035_project_list_archive_url_format.py
new file mode 100644 (file)
index 0000000..376d6ed
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.21 on 2019-07-01 12:57
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0034_project_list_archive_url'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='project',
+            name='list_archive_url_format',
+            field=models.CharField(blank=True, help_text=b"URL format for the list archive's Message-ID redirector. {} will be replaced by the Message-ID.", max_length=2000),
+        ),
+    ]
index e43b062b6f89a5f0281e0b007d30dc4985f4d460..4d23396033cfa8dd24227ec6a046cd1f93755434 100644 (file)
@@ -78,6 +78,10 @@ class Project(models.Model):
     scm_url = models.CharField(max_length=2000, blank=True)
     webscm_url = models.CharField(max_length=2000, blank=True)
     list_archive_url = models.CharField(max_length=2000, blank=True)
+    list_archive_url_format = models.CharField(
+        max_length=2000, blank=True,
+        help_text="URL format for the list archive's Message-ID redirector. "
+        "{} will be replaced by the Message-ID.")
 
     # configuration options
 
@@ -358,6 +362,15 @@ class Submission(FilenameMixin, EmailMixin, models.Model):
 
     name = models.CharField(max_length=255)
 
+    @property
+    def list_archive_url(self):
+        if not self.project.list_archive_url_format:
+            return None
+        if not self.msgid:
+            return None
+        return self.project.list_archive_url_format.format(
+            self.msgid.strip('<>'))
+
     # patchwork metadata
 
     def is_editable(self, user):
@@ -591,6 +604,15 @@ class Comment(EmailMixin, models.Model):
                                    related_query_name='comment',
                                    on_delete=models.CASCADE)
 
+    @property
+    def list_archive_url(self):
+        if not self.submission.project.list_archive_url_format:
+            return None
+        if not self.msgid:
+            return None
+        return self.project.list_archive_url_format.format(
+            self.msgid.strip('<>'))
+
     def get_absolute_url(self):
         return reverse('comment-redirect', kwargs={'comment_id': self.id})