From nobody Wed May 14 16:06:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581753704944.7826588831665; Sat, 18 Aug 2018 01:42:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 727823082E06; Sat, 18 Aug 2018 08:42:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 603DF2010CBC; Sat, 18 Aug 2018 08:42:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 51F5118005D0; Sat, 18 Aug 2018 08:42:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dwD5013269 for ; Sat, 18 Aug 2018 04:39:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2E4FD61F4F; Sat, 18 Aug 2018 08:39:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2517462460 for ; Sat, 18 Aug 2018 08:39:58 +0000 (UTC) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7DF681104 for ; Sat, 18 Aug 2018 08:39:56 +0000 (UTC) Received: by mail-wm0-f53.google.com with SMTP id t25-v6so9271908wmi.3 for ; Sat, 18 Aug 2018 01:39:56 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=e6+NcYNJNyz0PrItj1ZM5Zs96sFlnJg4VqCwTGsvlNg=; b=bl7QNv+KcQJ/89XPNuzqogaapDpMYCCIykcpGkFC7nmK6iOuLn6eOkHr0B4/v5hYnD u6nMGY0Peqqf1jZzZWyuhRyRmTFWNBFp5yAm09/gCRgPemAi2Upwdhtp85qFQt67/o6W Xgn8klBwZe/O0JuEvYiqDF6Vk8FR0SUXkgNxq/SoQqiKaG4TIsTaMRKTbbfvbO74u7Rv yRnq9zklJDc2HSo1eloegc5KAoj64sFIihPmP2df43jkLZ5qshoQ3sPjq07BLa0WxFkF fXXI1/rP1cj8dVwKgIPB7Dn457k4z1N/iEePr5a8n7S31H2trSuDaXXPzKNA4RmJ90hF 2A0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=e6+NcYNJNyz0PrItj1ZM5Zs96sFlnJg4VqCwTGsvlNg=; b=P7j2f02EDIubrRcpZYh5GwYyqNPrcvnyWAw8NH2PKw2dz/zLemMxtFJ4IzDgL2CW4Q cSQco+dkUeFmzu3HciEm0u26onep7CKjXZSbzIDt2bfF/iXNj4OEUAvL4aH4As5zX10L QMa2Fby6prQDkdyfSdi5zD+DVK7Gjmixfp9HKrPD4QiadsmVkM+tcUgkw+lh2XAPo3n+ Ew1hpsHvWWI4aOnGaJPxyg1Nn/1nC0EWbOwGqFAyaR5XH1TWy8CZqhk3oE956KQvlClV PtGwlxjcYj9r/W659YQVjhHlSn85nwfEmAyvzW0b2MMcCsH5gXjfejov+J/DuS1rlX7l PdWw== X-Gm-Message-State: AOUpUlFDG6SgzL9KfEfEoMa3k73M5pNQrsgrCuNMiU96b7eqBsHr83+f Qx+9W3IPhX46HJEAe7EPmDI5S7Hu X-Google-Smtp-Source: AA+uWPydWordzsU7Sgp+qH3DZXldt494GAKLkf3jWuVe3rBRPsr+XasOzjL5fnFA/MxdVuk8L653kg== X-Received: by 2002:a1c:8f50:: with SMTP id r77-v6mr21425842wmd.44.1534581595306; Sat, 18 Aug 2018 01:39:55 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:44 +0200 Message-Id: <20180818083944.19692-10-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 18 Aug 2018 08:39:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 18 Aug 2018 08:39:57 +0000 (UTC) for IP:'74.125.82.53' DOMAIN:'mail-wm0-f53.google.com' HELO:'mail-wm0-f53.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.53 mail-wm0-f53.google.com 74.125.82.53 mail-wm0-f53.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 9/9] rest: add ability to look up projects by name X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 18 Aug 2018 08:42:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Compared to Shubham's patch, this uses a redirect instead of a GET argument on the collection. This approach could be extended in the future to request methods other than GET. Signed-off-by: Paolo Bonzini --- api/rest.py | 12 +++++++++++- api/urls.py | 1 + tests/test_rest.py | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index 4132e38..bf45125 100644 --- a/api/rest.py +++ b/api/rest.py @@ -10,7 +10,7 @@ =20 from collections import OrderedDict from django.contrib.auth.models import User -from django.http import Http404 +from django.http import Http404, HttpResponseRedirect from django.template import loader =20 from mod import dispatch_module_hook @@ -206,6 +206,16 @@ class ProjectsViewSet(viewsets.ModelViewSet): project.project_head =3D request.data['new_head'] return Response({"new_head": project.project_head, "count": ret}) =20 +class ProjectsByNameViewSet(viewsets.GenericViewSet): + queryset =3D Project.objects.all().order_by('id') + permission_classes =3D (PatchewPermission,) + lookup_field =3D 'name' + + def retrieve(self, request, *args, **kwargs): + instance =3D self.get_object() + url =3D reverse_detail(instance, request) + return HttpResponseRedirect(url, status=3Dstatus.HTTP_307_TEMPORAR= Y_REDIRECT) + # Common classes for series and messages =20 class HyperlinkedMessageField(HyperlinkedIdentityField): diff --git a/api/urls.py b/api/urls.py index 2fd4e0f..2d95328 100644 --- a/api/urls.py +++ b/api/urls.py @@ -30,6 +30,7 @@ router =3D DefaultRouter(trailing_slash=3DTrue) router.include_format_suffixes =3D False router.register('users', rest.UsersViewSet) router.register('projects', rest.ProjectsViewSet) +router.register('projects/by-name', rest.ProjectsByNameViewSet) router.register('series', rest.SeriesViewSet, base_name=3D'series') router.register('messages', rest.MessagesViewSet) =20 diff --git a/tests/test_rest.py b/tests/test_rest.py index 7b035bc..8c86d9d 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -86,6 +86,14 @@ class RestTest(PatchewTestCase): self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.or= g") self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE) =20 + def test_project_by_name(self): + resp =3D self.api_client.get(self.REST_BASE + 'projects/by-name/QE= MU/') + self.assertEquals(resp.status_code, 307) + resp =3D self.api_client.get(resp['Location']) + self.assertEquals(resp.data['resource_uri'], self.PROJECT_BASE) + self.assertEquals(resp.data['name'], "QEMU") + self.assertEquals(resp.data['mailing_list'], "qemu-devel@nongnu.or= g") + def test_update_project_head(self): resp =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', self.p.id, '20160628014747.20971-1-= famz@redhat.com') --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel