From patchwork Mon Sep 10 20:45:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 968239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 428KpK6Kyzz9s3l for ; Tue, 11 Sep 2018 06:46:33 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="L5emNEzJ"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 428KpK4cjwzF39C for ; Tue, 11 Sep 2018 06:46:33 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="L5emNEzJ"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.6; helo=relay-direct6.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="L5emNEzJ"; dkim-atps=neutral Received: from relay-direct6.mxroute.com (relay-direct6.mxroute.com [185.234.75.6]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 428Kp82v3XzF39K for ; Tue, 11 Sep 2018 06:46:24 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay-direct6.mxroute.com (Postfix) with ESMTP id 1141C3F8F1 for ; Mon, 10 Sep 2018 20:45:52 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id DFFB83F546 for ; Mon, 10 Sep 2018 20:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=nVcJ4+IKZEzUA1LojHDWVSToYoc54OIn7KpmtWRpWLs=; b=L5emNEzJs5q9FRpZHCH6DVr1p5 m+2BezNtb19algbNz3DPcw6QnPChkpGb5LXv7NancIDaylprwwyI7uM2c0ePuHAuvrLEPzTVLmFsi GcU5AeuQ2oNKHg5+EuQyaNmoM/OTJm3AhfVnn+AYs6GuxCUVJfkGJ1dnrZVGrWEos5NwzOyaCu7tR 1emc1f4yQjb2l1S7zOEl+s3LiVQtJb9kBkVIUl6nitxoR0ruQF1ieR7BdSKCLKyh3xHuEn4ynsYMv RBwIMzkJbREvMvZsxq17V02cLml5G1uG2KFqZYfq7ygljiQk1UWI4NhwOkTNrD3c0InCrfEw/43xY wV+Q2tvA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH] models: Remove 'latest_series' Date: Mon, 10 Sep 2018 14:45:42 -0600 Message-Id: <20180910204542.28715-1-stephen@that.guru> X-Mailer: git-send-email 2.17.1 X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.27 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" This is only used in a single view (where it probably shouldn't be used) and some tests. It's an anti-pattern that makes it too easy to shoot yourself in the foot. Remove it. Signed-off-by: Stephen Finucane --- patchwork/models.py | 23 ++---------------- .../templates/patchwork/download_buttons.html | 10 ++++---- patchwork/tests/test_series.py | 24 +++++++++---------- patchwork/views/utils.py | 2 +- 4 files changed, 21 insertions(+), 38 deletions(-) diff --git a/patchwork/models.py b/patchwork/models.py index d2d8f343..8731bb2f 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -393,26 +393,7 @@ class Submission(FilenameMixin, EmailMixin, models.Model): ] -class SeriesMixin(object): - - @property - def latest_series(self): - """Get the latest series this is a member of. - - Return the last series that (ordered by date) that this - submission is a member of. - - .. warning:: - Be judicious in your use of this. For example, do not use it - in list templates as doing so will result in a new query for - each item in the list. - """ - # NOTE(stephenfin): We don't use 'latest()' here, as this can raise an - # exception if no series exist - return self.series.order_by('-date').first() - - -class CoverLetter(SeriesMixin, Submission): +class CoverLetter(Submission): def get_absolute_url(self): return reverse('cover-detail', kwargs={'cover_id': self.id}) @@ -422,7 +403,7 @@ class CoverLetter(SeriesMixin, Submission): @python_2_unicode_compatible -class Patch(SeriesMixin, Submission): +class Patch(Submission): # patch metadata diff = models.TextField(null=True, blank=True) diff --git a/patchwork/templates/patchwork/download_buttons.html b/patchwork/templates/patchwork/download_buttons.html index 4809db54..32acf26b 100644 --- a/patchwork/templates/patchwork/download_buttons.html +++ b/patchwork/templates/patchwork/download_buttons.html @@ -15,17 +15,19 @@ class="btn btn-default" role="button" title="Download cover mbox" >mbox {% endif %} - {% if submission.series.all|length == 1 %} - series - {% elif submission.series.all|length > 1 %} + {% endwith %} + {% elif all_series|length > 1 %}