From 9301db906b0937ddbc2e573fdd3d05f4a1345f63 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sun, 25 Sep 2016 21:59:37 +0100 Subject: [PATCH] Add support for comment permalink Signed-off-by: Stephen Finucane Closes-bug: #39 --- CHANGELOG.md | 1 + patchwork/templates/patchwork/submission.html | 4 +- patchwork/tests/test_detail.py | 38 +++++++++++++---- patchwork/urls.py | 5 +++ patchwork/views/comment.py | 41 +++++++++++++++++++ patchwork/views/cover.py | 2 - 6 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 patchwork/views/comment.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 4070fa97..9dac8a44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ versions of both Django and Python. - REST API support (Django >= 1.8 only) - Cover letter support - Series support +- Comment permalinks - Django debug toolbar support for developers - Django 1.9 and 1.10 support - Python 3.5 support diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html index a7b09481..21c345fe 100644 --- a/patchwork/templates/patchwork/submission.html +++ b/patchwork/templates/patchwork/submission.html @@ -265,10 +265,12 @@ function toggle_div(link_id, headers_id)

Comments

{% endif %} +
{{ item.submitter|personify:project }} - {{ item.date }} + {{ item.date }} | #{{ forloop.counter }}
 {{ item|commentsyntax }}
diff --git a/patchwork/tests/test_detail.py b/patchwork/tests/test_detail.py
index 0890c7c0..cf296919 100644
--- a/patchwork/tests/test_detail.py
+++ b/patchwork/tests/test_detail.py
@@ -22,31 +22,53 @@ from __future__ import absolute_import
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 
-from patchwork.tests.utils import create_covers
-from patchwork.tests.utils import create_patches
+from patchwork.tests.utils import create_comment
+from patchwork.tests.utils import create_cover
+from patchwork.tests.utils import create_patch
 
 
 class CoverLetterViewTest(TestCase):
 
     def test_redirect(self):
-        patches = create_patches()
-        patch_id = patches[0].id
+        patch_id = create_patch().id
 
         requested_url = reverse('cover-detail', kwargs={'cover_id': patch_id})
         redirect_url = reverse('patch-detail', kwargs={'patch_id': patch_id})
 
-        response = self.client.post(requested_url)
+        response = self.client.get(requested_url)
         self.assertRedirects(response, redirect_url)
 
 
 class PatchViewTest(TestCase):
 
     def test_redirect(self):
-        covers = create_covers()
-        cover_id = covers[0].id
+        cover_id = create_cover().id
 
         requested_url = reverse('patch-detail', kwargs={'patch_id': cover_id})
         redirect_url = reverse('cover-detail', kwargs={'cover_id': cover_id})
 
-        response = self.client.post(requested_url)
+        response = self.client.get(requested_url)
         self.assertRedirects(response, redirect_url)
+
+
+class CommentRedirectTest(TestCase):
+
+    def _test_redirect(self, submission, submission_url, submission_id):
+        comment_id = create_comment(submission=submission).id
+
+        requested_url = reverse('comment-redirect',
+                                kwargs={'comment_id': comment_id})
+        redirect_url = '%s#%d' % (
+            reverse(submission_url, kwargs={submission_id: submission.id}),
+            comment_id)
+
+        response = self.client.get(requested_url)
+        self.assertRedirects(response, redirect_url)
+
+    def test_patch_redirect(self):
+        patch = create_patch()
+        self._test_redirect(patch, 'patch-detail', 'patch_id')
+
+    def test_cover_redirect(self):
+        cover = create_cover()
+        self._test_redirect(cover, 'cover-detail', 'cover_id')
diff --git a/patchwork/urls.py b/patchwork/urls.py
index 33e4781f..98b4dbec 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -24,6 +24,7 @@ from django.contrib.auth import views as auth_views
 
 from patchwork.views import api as api_views
 from patchwork.views import bundle as bundle_views
+from patchwork.views import comment as comment_views
 from patchwork.views import cover as cover_views
 from patchwork.views import help as help_views
 from patchwork.views import mail as mail_views
@@ -60,6 +61,10 @@ urlpatterns = [
     url(r'^cover/(?P\d+)/$', cover_views.cover,
         name='cover-detail'),
 
+    # comment urls
+    url(r'^comment/(?P\d+)/$', comment_views.comment,
+        name='comment-redirect'),
+
     # logged-in user stuff
     url(r'^user/$', user_views.profile, name='user-profile'),
     url(r'^user/todo/$', user_views.todo_lists,
diff --git a/patchwork/views/comment.py b/patchwork/views/comment.py
new file mode 100644
index 00000000..92e2355c
--- /dev/null
+++ b/patchwork/views/comment.py
@@ -0,0 +1,41 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Stephen Finucane 
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from __future__ import absolute_import
+
+from django.core import urlresolvers
+from django import http
+from django import shortcuts
+
+from patchwork import models
+
+
+def comment(request, comment_id):
+    submission = shortcuts.get_object_or_404(models.Comment,
+                                             id=comment_id).submission
+    if hasattr(submission, 'patch'):
+        url = 'patch-detail'
+        key = 'patch_id'
+    else:
+        url = 'cover-detail'
+        key = 'cover_id'
+
+    return http.HttpResponseRedirect('%s#%s' % (
+        urlresolvers.reverse(url, kwargs={key: submission.id}),
+        comment_id))
diff --git a/patchwork/views/cover.py b/patchwork/views/cover.py
index 83f5551f..a9cf0ad3 100644
--- a/patchwork/views/cover.py
+++ b/patchwork/views/cover.py
@@ -28,8 +28,6 @@ from patchwork.models import CoverLetter, Submission
 
 
 def cover(request, cover_id):
-    context = {}
-
     # redirect to patches where necessary
     try:
         cover = get_object_or_404(CoverLetter, id=cover_id)
-- 
2.47.3