Commit cda07946 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

Add a way for searching series with msg-id

We already have /patch/msgid/$MSGID to look up a single patch.

This change adds /series/msgid/$MSGID so we can look up a whole series.
This works with patch and cover letter message-ids.

Fixes: #36Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent b7c9303e
# Patchwork - automated patch tracking system
# Copyright (C) 2020 Arkadiusz Hiler <arkadiusz.hiler@intel.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 patchwork.models import Patch, Series
from .test_series import Series0010
class SeriesMsgIDLookup(Series0010):
url = '/series/msgid/{}/'
def series(self):
return Series.objects.get()
def testCoverLetterRedirects(self):
response = self.client.get(self.url.format(self.root_msgid))
self.assertRedirects(response, self.series().get_absolute_url())
def testPatchMsgIdRedirects(self):
msg_id = Patch.objects.first().msgid
response = self.client.get(self.url.format(msg_id))
self.assertRedirects(response, self.series().get_absolute_url())
def testNoAngleBracketsRedirects(self):
msg_id = Patch.objects.first().msgid
msg_id = msg_id.strip("<>")
response = self.client.get(self.url.format(msg_id))
self.assertRedirects(response, self.series().get_absolute_url())
def testWrongMsgId404(self):
msg_id = "toto@tata"
response = self.client.get(self.url.format(msg_id))
self.assertEqual(404, response.status_code)
......@@ -115,6 +115,9 @@ urlpatterns = [
url(r'^series/(?P<series>\d+)/$', SeriesView.as_view(),
name='series'),
url(r'^series/msgid/(?P<msgid>[^/]+)/$', patchwork.views.series.msgid,
name='series_msgid'),
# patch views
url(r'^patch/(?P<patch_id>\d+)/$', patchwork.views.patch.patch,
name='patch'),
......
......@@ -18,12 +18,37 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.conf import settings
from django.shortcuts import render, get_object_or_404, get_list_or_404
from django.http import Http404
from django.shortcuts import (render, redirect, get_object_or_404,
get_list_or_404)
from django.views.generic import View
from patchwork.models import Project, Series, SeriesRevision, TestResult
from patchwork.models import Patch, Project, Series, SeriesRevision, TestResult
from patchwork.permissions import Can
def msgid(request, msgid):
series = None
if not (msgid.startswith('<') and msgid.endswith('>')):
msgid = '<{}>'.format(msgid)
revisions = SeriesRevision.objects.filter(root_msgid=msgid)
revision = revisions.first()
if revision is not None:
series = revision.series
if series is None:
patches = Patch.objects.filter(msgid=msgid)
patch = patches.first()
if patch is not None:
series = patch.series()
if series is None:
raise Http404("msg-id not found")
return redirect(series)
class SeriesListView(View):
def get(self, request, *args, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment