diff mbox

Add support for comment permalink

Message ID 1474837177-7923-1-git-send-email-stephen@that.guru
State Accepted
Headers show

Commit Message

Stephen Finucane Sept. 25, 2016, 8:59 p.m. UTC
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes-bug: #39
---
 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 --
 5 files changed, 79 insertions(+), 11 deletions(-)
 create mode 100644 patchwork/views/comment.py

Comments

Stephen Finucane Nov. 19, 2016, 6:55 p.m. UTC | #1
On 25 Sep 21:59, Stephen Finucane wrote:
> Signed-off-by: Stephen Finucane <stephen@that.guru>
> Closes-bug: #39

Applied.
diff mbox

Patch

diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html
index 088cceb..bc0e529 100644
--- a/patchwork/templates/patchwork/submission.html
+++ b/patchwork/templates/patchwork/submission.html
@@ -212,10 +212,12 @@  function toggle_headers(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 }}
diff --git a/patchwork/tests/test_detail.py b/patchwork/tests/test_detail.py
index 0890c7c..cf29691 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 33e4781..87d4bc5 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<cover_id>\d+)/$', cover_views.cover,
         name='cover-detail'),
 
+    # comment short 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
index 0000000..0ca0bc8
--- /dev/null
+++ b/patchwork/views/comment.py
@@ -0,0 +1,41 @@ 
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Stephen Finucane <stephenfinucane@hotmail.com>
+#
+# 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 83f5551..a9cf0ad 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)