From patchwork Fri May 20 19:17:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Doan X-Patchwork-Id: 624609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rBHmt6qwpz9t7q for ; Sat, 21 May 2016 05:19:26 +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=FagAxgot; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rBHmt5FkKzDqHq for ; Sat, 21 May 2016 05:19:26 +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=FagAxgot; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mail-oi0-x230.google.com (mail-oi0-x230.google.com [IPv6:2607:f8b0:4003:c06::230]) (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 3rBHkc0WPNzDqDJ for ; Sat, 21 May 2016 05:17:28 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=FagAxgot; dkim-atps=neutral Received: by mail-oi0-x230.google.com with SMTP id b65so49877747oia.1 for ; Fri, 20 May 2016 12:17:27 -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=wesCTX733Eprh045nXb81l2rd6t5eTqMMD+GTUThPi0=; b=FagAxgot2GvY1FwzEoVKoQR1hAJO0sgSSArV1LSsU7zOtJvHHu+sGaSznWdIylVGdO fu+d2l8mLH4XIInYhdZye0/cWVS65cDjdAX5rHb4zTSEei4K8RZT6h0v5duUUkqmshac Mr1MJEJWGa0/7h/1IYlV2tmbjWg5PlEspQCv4= 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=wesCTX733Eprh045nXb81l2rd6t5eTqMMD+GTUThPi0=; b=JCbnv4tLGC2v8oaLG9j0JxCYjIQYRjDbPaoK501A427KNZ77dC0qVe3+AYPa1INMTm fjUB8jDYUugV+AkCP0MyVW9wuc4iVViIIi6/RSd2rWPv9oV+pN6djF4OD4OFQMyJykfs YO2lRQo6GHJEaurtLi7AGQgQ8YoEmzokWZ+A57kNHud48g1Js2G3oU/ElBYNGNMIeTI/ Gu1hGPxwbGudYUx9mtaOer2EeiVLi1kVJd3U96BzT1OjoE+nTde7hXFhA0FR+8h4d7qc 8nHOhkpgTlq74Vo5gddXLdmqEG75+ZsdrwYWuX5K6Oa+PAF2NGEmNqh7zAMmMhbEXfHZ 534A== X-Gm-Message-State: AOPr4FXI5Lf14SUrkYPAzqOXHAlECYlkBDqcmFXekjlA6idKLs61D5XAFY6yOgBegiPEa4bJ X-Received: by 10.157.1.140 with SMTP id e12mr3111449ote.180.1463771846055; Fri, 20 May 2016 12:17:26 -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 l65sm5731844otc.28.2016.05.20.12.17.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 May 2016 12:17:25 -0700 (PDT) From: Andy Doan To: patchwork@lists.ozlabs.org Subject: [PATCH v4 08/10] REST: Add Patch.mbox_url Date: Fri, 20 May 2016 14:17:10 -0500 Message-Id: <1463771832-23025-9-git-send-email-andy.doan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1463771832-23025-1-git-send-email-andy.doan@linaro.org> References: <1463771832-23025-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" Provide a URL to the raw patch. Signed-off-by: Andy Doan Reviewed-by: Stephen Finucane --- patchwork/models.py | 4 ++++ patchwork/rest_serializers.py | 5 +++++ patchwork/tests/test_rest_api.py | 1 + 3 files changed, 10 insertions(+) diff --git a/patchwork/models.py b/patchwork/models.py index 6324273..6209527 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -458,6 +458,10 @@ class Patch(Submission): def get_absolute_url(self): return ('patch-detail', (), {'patch_id': self.id}) + @models.permalink + def get_mbox_url(self): + return ('patch-mbox', (), {'patch_id': self.id}) + def __str__(self): return self.name diff --git a/patchwork/rest_serializers.py b/patchwork/rest_serializers.py index 94ac469..4fcd392 100644 --- a/patchwork/rest_serializers.py +++ b/patchwork/rest_serializers.py @@ -66,11 +66,16 @@ class PatchSerializer(HyperlinkedModelSerializer): list_serializer_class = PatchListSerializer read_only_fields = ('project', 'name', 'date', 'submitter', 'diff', 'content', 'hash', 'msgid') + mbox_url = SerializerMethodField() state = SerializerMethodField() def get_state(self, obj): return obj.state.name + def get_mbox_url(self, patch): + request = self.context.get('request', None) + return request.build_absolute_uri(patch.get_mbox_url()) + def to_representation(self, instance): data = super(PatchSerializer, self).to_representation(instance) data['checks'] = data['url'] + 'checks/' diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py index 2be3ed5..44be7d1 100644 --- a/patchwork/tests/test_rest_api.py +++ b/patchwork/tests/test_rest_api.py @@ -260,6 +260,7 @@ class TestPatchAPI(APITestCase): self.assertIn(TestPersonAPI.api_url(patches[0].submitter.id), resp.data['submitter']) self.assertEqual(patches[0].state.name, resp.data['state']) + self.assertIn(patches[0].get_mbox_url(), resp.data['mbox_url']) def test_anonymous_writes(self): """Ensure anonymous "write" operations are rejected."""