]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Add support for comment permalink
authorStephen Finucane <stephen@that.guru>
Sun, 25 Sep 2016 20:59:37 +0000 (21:59 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 19 Nov 2016 18:45:06 +0000 (18:45 +0000)
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes-bug: #39

CHANGELOG.md
patchwork/templates/patchwork/submission.html
patchwork/tests/test_detail.py
patchwork/urls.py
patchwork/views/comment.py [new file with mode: 0644]
patchwork/views/cover.py

index 4070fa97d59683ed6b45e42279337526272ccf43..9dac8a440318e3fff35aae41f217b1cc8640c9ea 100644 (file)
@@ -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
index a7b094810e4f551147365a0f9d9cf9fa5be9914d..21c345feccf1b845bcd78a6d3434362aa8a19ac1 100644 (file)
@@ -265,10 +265,12 @@ function toggle_div(link_id, headers_id)
 <h2>Comments</h2>
 {% endif %}
 
+<a name="{{ item.id }}"></a>
 <div class="comment">
 <div class="meta">
  <span>{{ item.submitter|personify:project }}</span>
- <span class="pull-right">{{ item.date }}</span>
+ <span class="pull-right">{{ item.date }} | <a href="{% url 'comment-redirect' comment_id=item.id %}"
+   >#{{ forloop.counter }}</a></span>
 </div>
 <pre class="content">
 {{ item|commentsyntax }}
index 0890c7c027bde2a28b51861eccd335988527e33c..cf2969192f6604b84f53aea85835b240893ab777 100644 (file)
@@ -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')
index 33e4781f4394139e6b6e795e46dac9c042a0f773..98b4dbec494d979c0f6189c3796c3524304a3fb8 100644 (file)
@@ -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<cover_id>\d+)/$', cover_views.cover,
         name='cover-detail'),
 
+    # comment urls
+    url(r'^comment/(?P<comment_id>\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 (file)
index 0000000..92e2355
--- /dev/null
@@ -0,0 +1,41 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Stephen Finucane <stephen@that.guru>
+#
+# 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))
index 83f5551f7806c8bdec93bfcd572f9c4f753e225f..a9cf0ad3bef33087b9a39bef8c2bf22da560d2e6 100644 (file)
@@ -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)