[v3,9/9] templates: Add "download series" links

Message ID 20170307194624.21582-10-stephen@that.guru
State Superseded
Headers show

Commit Message

Stephen Finucane March 7, 2017, 7:46 p.m.
This will allow users to download entire series including the current
patch. Since a patch can belong to many series a dropdown is used.

Signed-off-by: Stephen Finucane <stephen@that.guru>
---
v3:
- Add unit tests
---
 patchwork/templates/patchwork/submission.html | 12 ++++++++++++
 patchwork/tests/test_detail.py                | 16 ++++++++++++++++
 2 files changed, 28 insertions(+)

Comments

Daniel Axtens March 9, 2017, 6:38 a.m. | #1
Hi Stephen,

I thought we were putting detection of one vs multiple series in v3,
and only doing a dropdown if there are more than 1?

Regards,
Daniel

Stephen Finucane <stephen@that.guru> writes:

> This will allow users to download entire series including the current
> patch. Since a patch can belong to many series a dropdown is used.
>
> Signed-off-by: Stephen Finucane <stephen@that.guru>
> ---
> v3:
> - Add unit tests
> ---
>  patchwork/templates/patchwork/submission.html | 12 ++++++++++++
>  patchwork/tests/test_detail.py                | 16 ++++++++++++++++
>  2 files changed, 28 insertions(+)
>
> diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html
> index 66c1159..5e86ac3 100644
> --- a/patchwork/templates/patchwork/submission.html
> +++ b/patchwork/templates/patchwork/submission.html
> @@ -288,6 +288,18 @@ function toggle_div(link_id, headers_id)
>    <a href="{% url 'patch-mbox' patch_id=submission.id %}"
>     class="btn btn-default" role="button" data-toggle="tooltip"
>     title="Download patch mbox">mbox</a>
> +  {% if submission.latest_series %}
> +   <button type="button" class="btn btn-default dropdown-toggle"
> +    data-toggle="dropdown">
> +    series <span class="caret"></span>
> +   </button>
> +   <ul class="dropdown-menu" role="menu">
> +   {% for series in submission.series.all %}
> +    <li><a href="{% url 'series-mbox' series_id=series.id %}"
> +     >{{ series }}</a></li>
> +   {% endfor %}
> +   </ul>
> +  {% endif %}
>   </div>
>  </h2>
>  
> diff --git a/patchwork/tests/test_detail.py b/patchwork/tests/test_detail.py
> index cf29691..ef93bbf 100644
> --- a/patchwork/tests/test_detail.py
> +++ b/patchwork/tests/test_detail.py
> @@ -25,6 +25,7 @@ from django.test import TestCase
>  from patchwork.tests.utils import create_comment
>  from patchwork.tests.utils import create_cover
>  from patchwork.tests.utils import create_patch
> +from patchwork.tests.utils import create_series
>  
>  
>  class CoverLetterViewTest(TestCase):
> @@ -50,6 +51,21 @@ class PatchViewTest(TestCase):
>          response = self.client.get(requested_url)
>          self.assertRedirects(response, redirect_url)
>  
> +    def test_series_dropdown(self):
> +        patch = create_patch()
> +        series = [create_series() for x in range(5)]
> +
> +        for series_ in series:
> +            series_.add_patch(patch, 1)
> +
> +        response = self.client.get(
> +            reverse('patch-detail', kwargs={'patch_id': patch.id}))
> +
> +        for series_ in series:
> +            self.assertContains(
> +                response,
> +                reverse('series-mbox', kwargs={'series_id': series_.id}))
> +
>  
>  class CommentRedirectTest(TestCase):
>  
> -- 
> 2.9.3
>
> _______________________________________________
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
Stephen Finucane March 10, 2017, 5:41 p.m. | #2
On Thu, 2017-03-09 at 17:38 +1100, Daniel Axtens wrote:
> Hi Stephen,
> 
> I thought we were putting detection of one vs multiple series in v3,
> and only doing a dropdown if there are more than 1?

Oops. So it was. Corrected in v4 which should be winging its way to you
now.

Stephen

Patch

diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html
index 66c1159..5e86ac3 100644
--- a/patchwork/templates/patchwork/submission.html
+++ b/patchwork/templates/patchwork/submission.html
@@ -288,6 +288,18 @@  function toggle_div(link_id, headers_id)
   <a href="{% url 'patch-mbox' patch_id=submission.id %}"
    class="btn btn-default" role="button" data-toggle="tooltip"
    title="Download patch mbox">mbox</a>
+  {% if submission.latest_series %}
+   <button type="button" class="btn btn-default dropdown-toggle"
+    data-toggle="dropdown">
+    series <span class="caret"></span>
+   </button>
+   <ul class="dropdown-menu" role="menu">
+   {% for series in submission.series.all %}
+    <li><a href="{% url 'series-mbox' series_id=series.id %}"
+     >{{ series }}</a></li>
+   {% endfor %}
+   </ul>
+  {% endif %}
  </div>
 </h2>
 
diff --git a/patchwork/tests/test_detail.py b/patchwork/tests/test_detail.py
index cf29691..ef93bbf 100644
--- a/patchwork/tests/test_detail.py
+++ b/patchwork/tests/test_detail.py
@@ -25,6 +25,7 @@  from django.test import TestCase
 from patchwork.tests.utils import create_comment
 from patchwork.tests.utils import create_cover
 from patchwork.tests.utils import create_patch
+from patchwork.tests.utils import create_series
 
 
 class CoverLetterViewTest(TestCase):
@@ -50,6 +51,21 @@  class PatchViewTest(TestCase):
         response = self.client.get(requested_url)
         self.assertRedirects(response, redirect_url)
 
+    def test_series_dropdown(self):
+        patch = create_patch()
+        series = [create_series() for x in range(5)]
+
+        for series_ in series:
+            series_.add_patch(patch, 1)
+
+        response = self.client.get(
+            reverse('patch-detail', kwargs={'patch_id': patch.id}))
+
+        for series_ in series:
+            self.assertContains(
+                response,
+                reverse('series-mbox', kwargs={'series_id': series_.id}))
+
 
 class CommentRedirectTest(TestCase):