From 5569a11dfebd55da10ce650a8f8b90a0c0c3d4ba Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 21 Mar 2017 11:30:14 +0000 Subject: [PATCH] views: Support wildcarded 'series' parameter 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 --- patchwork/views/patch.py | 6 +++--- patchwork/views/utils.py | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index 3c8cb256..4c1a3631 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -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=' + \ diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py index 49d9c0c4..7198c2d7 100644 --- a/patchwork/views/utils.py +++ b/patchwork/views/utils.py @@ -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 = [] -- 2.47.3