aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Donnellan <ajd@linux.ibm.com>2019-08-22 17:12:58 +1000
committerDaniel Axtens <dja@axtens.net>2019-08-22 21:14:08 +1000
commit02ffb131559372373f5f01c1dd9dbd248796c7bc (patch)
treecba030f619b9b735f7fc5b5a813d0d327550ea9e
parent64f39cbc2d09889bd238a93d01ab95092e538300 (diff)
downloadpatchwork-02ffb131559372373f5f01c1dd9dbd248796c7bc.tar
patchwork-02ffb131559372373f5f01c1dd9dbd248796c7bc.tar.gz
models: Add list archive lookup
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>
-rw-r--r--patchwork/fixtures/default_projects.xml1
-rw-r--r--patchwork/migrations/0035_project_list_archive_url_format.py20
-rw-r--r--patchwork/models.py22
3 files changed, 43 insertions, 0 deletions
diff --git a/patchwork/fixtures/default_projects.xml b/patchwork/fixtures/default_projects.xml
index 39d2698..0895502 100644
--- a/patchwork/fixtures/default_projects.xml
+++ b/patchwork/fixtures/default_projects.xml
@@ -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
index 0000000..376d6ed
--- /dev/null
+++ b/patchwork/migrations/0035_project_list_archive_url_format.py
@@ -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),
+ ),
+ ]
diff --git a/patchwork/models.py b/patchwork/models.py
index e43b062..4d23396 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -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})