From patchwork Tue May 10 22:39:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Doan X-Patchwork-Id: 620857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r4DlD4dyTz9s2G for ; Wed, 11 May 2016 08:42:00 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=Bpmc/ets; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3r4DlD3WfQzDqDV for ; Wed, 11 May 2016 08:42:00 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=Bpmc/ets; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mail-oi0-x232.google.com (mail-oi0-x232.google.com [IPv6:2607:f8b0:4003:c06::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3r4Dhp153yzDqG1 for ; Wed, 11 May 2016 08:39:54 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=Bpmc/ets; dkim-atps=neutral Received: by mail-oi0-x232.google.com with SMTP id k142so40198498oib.1 for ; Tue, 10 May 2016 15:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/xNcPbw6Shtl/SqJCT46fm0yyHIhTxnuqDwctdggL1g=; b=Bpmc/etsF9/64IHK2D9IbGTU2h8ZU45y0c5RWOhr9Sa8R0CcpWB5RA4bbuyX7w88cj qbd9MUumc6UDdu5ytZP4Uwh/u3NZXgZ2kBHbDSgodWT3vfekKGH0UTY431QX3UEIkWTl xl1P0fb2jVsZFPiXx2KoHQB5cA0ZPy/BwxSg4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/xNcPbw6Shtl/SqJCT46fm0yyHIhTxnuqDwctdggL1g=; b=esdYNj6/WQRIx8lb6oLSps65J/YhklhjO2bh5iVBm+Li8pJj0JDXtJ9GiGRnWeuCiz niSLL345SvjuPlR1zalvZEdlTPMyJDOTx66XDgURH7Sz/N86h/Wc/JUfVSdedCcfNoaF PY9W7TBa+UW9kPrRE8G3aI+hKq/VBpfih6uQx++PGbA32Oxh0fH5VKrfTi3uhIs9JWNL GIrL88jk8JmFVF7OHBVMca3AC5X+PTJfsCxEF5nPgtaxcU+gLH0ly3POX/S4I8XX7Fij eI5U5ddGyoW0mdWcyTI1UCSG3quqGDZQjipxi/6nD8m/aY740VdLKUtsoPwtmJ5T4eKl cJuA== X-Gm-Message-State: AOPr4FVRUm0OggkdlYhsa36J0YZ8wO2rDjJh4EKYwPPxj7lNs3zQ54gIx4Ukpvy10kkIr02g X-Received: by 10.202.78.210 with SMTP id c201mr2729oib.87.1462919992203; Tue, 10 May 2016 15:39:52 -0700 (PDT) Received: from doanac-xps.local (cpe-70-117-126-139.austin.res.rr.com. [70.117.126.139]) by smtp.gmail.com with ESMTPSA id sl9sm1223255oeb.10.2016.05.10.15.39.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 May 2016 15:39:51 -0700 (PDT) From: Andy Doan To: patchwork@lists.ozlabs.org Subject: [PATCHv2 10/10] REST: Allow projects to be retrieved by linkname Date: Tue, 10 May 2016 17:39:27 -0500 Message-Id: <1462919967-26088-11-git-send-email-andy.doan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1462919967-26088-1-git-send-email-andy.doan@linaro.org> References: <1462919967-26088-1-git-send-email-andy.doan@linaro.org> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Building a user-friendly CLI becomes difficult when project-ids are required. It also makes it almost impossible to work with the current format of the .pwclientrc file. Signed-off-by: Andy Doan Reviewed-by: Stephen Finucane --- patchwork/tests/test_rest_api.py | 5 +++++ patchwork/views/rest_api.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py index 6f1a375..0b180e6 100644 --- a/patchwork/tests/test_rest_api.py +++ b/patchwork/tests/test_rest_api.py @@ -59,6 +59,11 @@ class TestProjectAPI(APITestCase): self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertEqual(defaults.project.name, resp.data['name']) + # make sure we can look up by linkname + resp = self.client.get(self.api_url(resp.data['linkname'])) + self.assertEqual(status.HTTP_200_OK, resp.status_code) + self.assertEqual(defaults.project.name, resp.data['name']) + def test_anonymous_writes(self): """Ensure anonymous "write" operations are rejected.""" defaults.project.save() diff --git a/patchwork/views/rest_api.py b/patchwork/views/rest_api.py index e5a642a..e125bc1 100644 --- a/patchwork/views/rest_api.py +++ b/patchwork/views/rest_api.py @@ -113,6 +113,22 @@ class ProjectViewSet(PatchworkViewSet): permission_classes = (PatchworkPermission,) serializer_class = ProjectSerializer + def retrieve(self, request, pk=None): + try: + int(pk) + except ValueError: + self.kwargs = {'linkname': pk} # try and lookup by linkname + self.lookup_field = 'linkname' + return super(ProjectViewSet, self).retrieve(request, pk) + + def partial_update(self, request, pk=None): + try: + int(pk) + except ValueError: + self.kwargs = {'linkname': pk} # try and lookup by linkname + self.lookup_field = 'linkname' + return super(ProjectViewSet, self).partial_update(request, pk) + class ChecksViewSet(PatchworkViewSet): serializer_class = ChecksSerializer