From patchwork Sat Nov 8 19:08:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Lespiau X-Patchwork-Id: 408459 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 1F7AA140082 for ; Sun, 9 Nov 2014 06:12:33 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id F1F021A2804 for ; Sun, 9 Nov 2014 06:12:32 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lists.ozlabs.org (Postfix) with ESMTP id 85E891A17A6 for ; Sun, 9 Nov 2014 06:09:53 +1100 (AEDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 08 Nov 2014 11:09:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,341,1413270000"; d="scan'208";a="628923924" Received: from plane-mobl1.ger.corp.intel.com (HELO strange.ger.corp.intel.com) ([10.252.3.12]) by fmsmga002.fm.intel.com with ESMTP; 08 Nov 2014 11:09:51 -0800 From: Damien Lespiau To: patchwork@lists.ozlabs.org Subject: [PATCH 40/46] patch: Single out the commit message Date: Sat, 8 Nov 2014 19:08:58 +0000 Message-Id: <1415473744-31531-41-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1415473744-31531-1-git-send-email-damien.lespiau@intel.com> References: <1415473744-31531-1-git-send-email-damien.lespiau@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.18 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" All 'Comments' are stored the same way in the db, but I believe it's worth making the distinction between introducing what the patch does and eventual review comments. Signed-off-by: Damien Lespiau --- apps/patchwork/models.py | 11 ++++++++++- templates/patchwork/patch.html | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 4bed9b8..b9c7794 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -188,7 +188,16 @@ class Patch(models.Model): return self.name def comments(self): - return Comment.objects.filter(patch = self) + comments = Comment.objects.filter(patch = self) + # len() will trigger a queryset evaluation. That's what we want as + # we need the full list of comments. That the list is then sliced into + # (commit message, list of followup comments) won't hit the db twice. + n_comments = len(comments) + if n_comments > 2: + return (comments[0], comments[1:]) + if n_comments == 1: + return (comments[0], ()) + return (None, ()) def save(self): try: diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html index 6540060..618f08e 100644 --- a/templates/patchwork/patch.html +++ b/templates/patchwork/patch.html @@ -177,8 +177,22 @@ function toggle_headers(link_id, headers_id) >{{ patch.pull_url }} {% endif %} +{% for item in patch.comments %} + +{% if forloop.first %} +{% if item %} +

Commit Message

+
+
{{ item.submitter|personify }} - {{item.date}}
+
+{{ item|commentsyntax }}
+
+
+{% endif %} +{% elif item %}

Comments

-{% for comment in patch.comments %} + +{% for comment in item %}
{{ comment.submitter|personify }} - {{comment.date}}
@@ -186,6 +200,8 @@ function toggle_headers(link_id, headers_id)
 
{% endfor %} +{% endif %} +{% endfor %} {% if patch.content %}

Patch