]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
views: Support wildcarded 'series' parameter
authorStephen Finucane <stephen@that.guru>
Tue, 21 Mar 2017 11:30:14 +0000 (11:30 +0000)
committerStephen Finucane <stephen@that.guru>
Tue, 4 Apr 2017 15:24:08 +0000 (16:24 +0100)
There are many times that we would want to just test against the latest
series. Make this possible by wildcarding, like so:

    GET /patch/{patchID}/mbox/?series=*

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/views/patch.py
patchwork/views/utils.py

index 3c8cb2566071117659efeeda4a8de3da5157620f..4c1a36315d2e77da2db626d1e4a6ca946c0a594d 100644 (file)
@@ -132,11 +132,11 @@ def patch_raw(request, patch_id):
 
 def patch_mbox(request, patch_id):
     patch = get_object_or_404(Patch, id=patch_id)
-    series_num = request.GET.get('series')
+    series_id = request.GET.get('series')
 
     response = HttpResponse(content_type='text/plain')
-    if series_num:
-        response.write(series_patch_to_mbox(patch, series_num))
+    if series_id:
+        response.write(series_patch_to_mbox(patch, series_id))
     else:
         response.write(patch_to_mbox(patch))
     response['Content-Disposition'] = 'attachment; filename=' + \
index 49d9c0c4333b1421d640bb5a2d41afa2ae68a476..7198c2d730f1ac7335ee25019e4102bc34d47333 100644 (file)
@@ -120,26 +120,30 @@ def bundle_to_mbox(bundle):
     return '\n'.join([patch_to_mbox(p) for p in bundle.ordered_patches()])
 
 
-def series_patch_to_mbox(patch, series_num):
+def series_patch_to_mbox(patch, series_id):
     """Get an mbox representation of a patch with dependencies.
 
     Arguments:
         patch: The Patch object to convert.
-        series_num: The series number to retrieve dependencies from.
+        series_id: The series number to retrieve dependencies from, or
+            '*' if using the latest series.
 
     Returns:
         A string for the mbox file.
     """
-    try:
-        series_num = int(series_num)
-    except ValueError:
-        raise Http404('Expected integer series value. Received: %r' %
-                      series_num)
-
-    try:
-        series = patch.series.get(id=series_num)
-    except Series.DoesNotExist:
-        raise Http404('Patch does not belong to series %d' % series_num)
+    if series_id == '*':
+        series = patch.latest_series
+    else:
+        try:
+            series_id = int(series_id)
+        except ValueError:
+            raise Http404('Expected integer series value or *. Received: %r' %
+                          series_id)
+
+        try:
+            series = patch.series.get(id=series_id)
+        except Series.DoesNotExist:
+            raise Http404('Patch does not belong to series %d' % series_id)
 
     mbox = []