From nobody Wed Apr 24 01:01:39 2024 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 1538146736523597.7646481345986; Fri, 28 Sep 2018 07:58:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22C3B305B877; Fri, 28 Sep 2018 14:58:55 +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 147A4106A79E; Fri, 28 Sep 2018 14:58:55 +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 02B4C18005CD; Fri, 28 Sep 2018 14:58:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEwr14026127 for ; Fri, 28 Sep 2018 10:58:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id EBDD861B67; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E25085E1C8 for ; Fri, 28 Sep 2018 14:58:51 +0000 (UTC) Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 4E325A6E01 for ; Fri, 28 Sep 2018 14:58:50 +0000 (UTC) Received: by mail-wr1-f44.google.com with SMTP id u12-v6so6727446wrr.4 for ; Fri, 28 Sep 2018 07:58:50 -0700 (PDT) Received: from donizetti.par1.mozilla.com ([2a00:8c40:243:232:de:fba5:535e:2dc2]) by smtp.gmail.com with ESMTPSA id h73-v6sm5278053wma.11.2018.09.28.07.58.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:58:48 -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=agkjsZMy+TAy+Qz9HWtHRKDDkeiVudUMMZ2YSTIDKy8=; b=pCoMn2ZRnM5mFyX5tbkU1TkpkdLIfMEswubir5rzel1/L3YTgtlM8Ze6aSdq9yPyKC 0WTvMUt68PujTPmr1v8Jb1RVW7FwNJ8hq6F8oeZPH710qVgLFsOqwTNhpRSPnypUNFMN Vf4nC+P+i2wohsdB9Emo006xUkiZVCNjJG+q8hdR+lpZclUntLDqVhR4yux4jg2fPJDH yI0sXIZdKY/IkdLUWf8DvM76emA0BUgdKytZuMXh3UbC84uT4UeHkPZQXs+0sJRQwSUa SjE4vHWCGU9A66ffLMIcQ79nySpWbF5BB5Mi9IU07kCy1HMkuyM98JvYEGOek7MKw0Q/ DXWg== 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=agkjsZMy+TAy+Qz9HWtHRKDDkeiVudUMMZ2YSTIDKy8=; b=qspOTMZBYBcKlUWQa5gPMRAI7WYzdG89hDMI3XpPYRAd40Ut8v8YsKQ/kDaDkoTmg3 WedzIpUOvqn/nZCjeD8GxtHoPAHPBwAvZWDAxzoploFGa60W81r800nLE/Du6YDkxKmt alNw601F+oVE3ncU70tkaRCae3FvJvog8MQG0VbuVmOmMF14A9WU/SBFsaV8a0ihw6ZD sZC5MsPA6e9Ond4wq2iLcV4jo10q7PHGsMuQPS0tPWSpHdSXZ730UGUa8I6jjCikDrNe VyD7K10+tpktSanNyisYRsmFSPse/u795KB8Bi0jEKSbdYS3EbuHMay3Vl46K1jk0Gs7 BF2w== X-Gm-Message-State: ABuFfoh1RBwHXeBziz/3vy1vP5Qtn1fJfP3WgKByJDp+LVx2uM6ZaDsj nnCGtZbz2+2KRatsSiOteYTcWuboRw4= X-Google-Smtp-Source: ACcGV61wLzXp9wi4N3v+H4gwwOx7IqRHpgkFjjQ+tcIvda1EohJCeyAQkce51A6k3m8Qz2o1BSsh3Q== X-Received: by 2002:adf:dcc1:: with SMTP id x1-v6mr436294wrm.21.1538146728594; Fri, 28 Sep 2018 07:58:48 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:58:42 +0200 Message-Id: <20180928145845.20473-2-pbonzini@redhat.com> In-Reply-To: <20180928145845.20473-1-pbonzini@redhat.com> References: <20180928145845.20473-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 28 Sep 2018 14:58:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 28 Sep 2018 14:58:50 +0000 (UTC) for IP:'209.85.221.44' DOMAIN:'mail-wr1-f44.google.com' HELO:'mail-wr1-f44.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.488 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.221.44 mail-wr1-f44.google.com 209.85.221.44 mail-wr1-f44.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 1/4] views: make download link only retrieve patches 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 28 Sep 2018 14:58:55 +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" This is almost always what you really want. The download link now appears only on complete series and also on message pages, where it will download a single patch. Signed-off-by: Paolo Bonzini --- api/models.py | 17 ++++++++++++----- www/templates/series-detail.html | 6 ++---- www/urls.py | 2 +- www/views.py | 24 +++++++++++++++++++----- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/api/models.py b/api/models.py index e4737cb..a6639b7 100644 --- a/api/models.py +++ b/api/models.py @@ -317,21 +317,28 @@ class MessageManager(models.Manager): class DuplicateMessageError(Exception): pass =20 - def series_heads(self, project=3DNone): - q =3D super(MessageManager, self).get_queryset()\ - .filter(is_series_head=3DTrue).prefetch_related('propertie= s', 'project') + def project_messages(self, project): + q =3D super(MessageManager, self).get_queryset() if isinstance(project, str): po =3D Project.objects.get(name=3Dproject) elif isinstance(project, int): po =3D Project.objects.get(id=3Dproject) - else: - return q q =3D q.filter(project=3Dpo) | q.filter(project__parent_project=3D= po) return q =20 + def series_heads(self, project=3DNone): + if project: + q =3D self.project_messages(project) + else: + q =3D super(MessageManager, self).get_queryset() + return q.filter(is_series_head=3DTrue).prefetch_related('propertie= s', 'project') + def find_series(self, message_id, project_name=3DNone): return self.series_heads(project_name).filter(message_id=3Dmessage= _id).first() =20 + def find_message(self, message_id, project_name): + return self.project_messages(project_name).filter(message_id=3Dmes= sage_id).first() + def patches(self): return super(MessageManager, self).get_queryset().\ filter(is_patch=3DTrue) diff --git a/www/templates/series-detail.html b/www/templates/series-detail= .html index cb5d611..02ce72c 100644 --- a/www/templates/series-detail.html +++ b/www/templates/series-detail.html @@ -24,17 +24,15 @@ patch{% if series.total_patches !=3D 1 %}es{% endif %} {{ series.age }} ago + {% if series.extra_links %} + {% endif %} =20 {% if series.extra_ops %} diff --git a/www/urls.py b/www/urls.py index 1659ff2..5787cbd 100644 --- a/www/urls.py +++ b/www/urls.py @@ -34,6 +34,6 @@ urlpatterns +=3D [ url(r"^(?P[^/]*)/info$", views.view_project_detail, name= =3D"project_detail"), url(r"^(?P[^/]*)/(?P[^/]*)/$", views.view_ser= ies_detail, name=3D"series_detail"), url(r"^(?P[^/]*)/(?P[^/]*)/(?P[^/]= *)/$", views.view_series_message, name=3D"series_message"), - url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view= _series_mbox), + url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view= _series_mbox, name=3D"mbox"), url(r"^$", views.view_project_list, name=3D"project_list"), ] diff --git a/www/views.py b/www/views.py index dd910b1..11043a1 100644 --- a/www/views.py +++ b/www/views.py @@ -13,6 +13,7 @@ from django.shortcuts import render from django.http import HttpResponse, Http404 from django.db.models import Exists, OuterRef from django.urls import reverse +from django.utils.html import format_html from django.conf import settings import api from mod import dispatch_module_hook @@ -39,6 +40,8 @@ def prepare_message(request, project, m, detailed): m.age =3D m.get_age() m.url =3D reverse("series_detail", kwargs=3D{"project": project.name, = "message_id": m.message_id}) m.status_tags =3D [] + m.extra_links =3D [] + mbox_url =3D reverse("mbox", kwargs=3D{"project": project.name, "messa= ge_id": m.message_id}) if m.is_series_head: m.num_patches =3D m.get_num_patches() m.total_patches =3D m.get_total_patches() @@ -50,11 +53,17 @@ def prepare_message(request, project, m, detailed): "type": "warning", "char": "?", }) + else: + m.extra_links.append({'html': format_html('Down= load patches mbox', mbox_url), + 'icon': 'download'}) + else: + m.extra_links.append({'html': format_html('Download= mbox', mbox_url), + 'icon': 'download'}) + # hook points for plugins m.has_other_revisions =3D False m.extra_status =3D [] m.extra_ops =3D [] - m.extra_links =3D [] dispatch_module_hook("prepare_message_hook", request=3Drequest, messag= e=3Dm, detailed=3Ddetailed) if m.is_merged: @@ -237,13 +246,18 @@ def view_series_list(request, project): query =3D api.models.Message.objects.series_heads(prj.id) return render_series_list_page(request, query, project=3Dproject) =20 -def view_series_mbox(request, project, message_id): - s =3D api.models.Message.objects.find_series(message_id, project) +def view_mbox(request, project, message_id): + s =3D api.models.Message.objects.find_message(project, message_id) if not s: raise Http404("Series not found") - r =3D prepare_series(request, s) + if s.is_cover_letter: + if not s.is_complete: + raise Http404("Series not complete") + messages =3D s.get_patches() + else: + messages =3D [s] mbox =3D "\n".join(["From %s %s\n" % (x.get_sender_addr(), x.get_ascti= me()) + \ - x.get_mbox() for x in r]) + x.get_mbox(x) for x in messages]) return HttpResponse(mbox, content_type=3D"text/plain") =20 def view_series_detail(request, project, message_id): --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Wed Apr 24 01:01:39 2024 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 1538146736190403.26745306311363; Fri, 28 Sep 2018 07:58:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A6D93001244; Fri, 28 Sep 2018 14:58:55 +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 EEF835D776; Fri, 28 Sep 2018 14:58:54 +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 E20A3181A12F; Fri, 28 Sep 2018 14:58:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEwr6O026118 for ; Fri, 28 Sep 2018 10:58:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B60D18669; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 607EB5D9C6 for ; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 94AAE356CD for ; Fri, 28 Sep 2018 14:58:51 +0000 (UTC) Received: by mail-wr1-f49.google.com with SMTP id z14-v6so6711328wrs.10 for ; Fri, 28 Sep 2018 07:58:51 -0700 (PDT) Received: from donizetti.par1.mozilla.com ([2a00:8c40:243:232:de:fba5:535e:2dc2]) by smtp.gmail.com with ESMTPSA id h73-v6sm5278053wma.11.2018.09.28.07.58.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:58:48 -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=mUNU+2nbgN5239z8lBrEKm/icbEDQ5Fh3p1RPW9wJTU=; b=Q+jklbq0EhNRn4POt7xOMq0dgd9P5xOTVO3a2m7SNCRj1Jo2v51rA79sEpSK4MuL2o A8DD9h26MckIyGVYMyqD2jXRJvZeWL7+gWynWnG/5DWgyc5piVTe/VI7y4inZLR3u/4o /u+H1hMxTflwx1gHB9p9iGcUzincY5gsT4xerryhdedMcD4jXZfD8QdWsn0c7fpYZqzN McKngZi1uvFVWG/xUz6vQw2HZs0Nwx4cQdPTGaj2xvMK9xqwAle+2XdsWcZnHM4l4cx7 wuFDZwcaO1Y+mhp+nnAU0A+M/1GW+JsLQMKRNQDhwdz/hy3obWfc7/P3DPFaD4wOePjP Tt3Q== 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=mUNU+2nbgN5239z8lBrEKm/icbEDQ5Fh3p1RPW9wJTU=; b=h8U8juE87r3m2D1lLgnrl9YeHWmuRSVUROhNIFiqS4AF5OhBMtFoaTa1ogT2HslPQP eB4zLgKQPznHMZjytbk6GbBq/uunW6IG6btpwiu1iU23eXrm9MFC3vaILQCmVkK4vKrJ WG1pU5RPoB1n2H2GQJravEBIl2D8LREHDnOrUunwHFRXzphv2dEk+pXc3r2Q7Q9+9yOh Ex9BGZoEeoC7NYRtwL7NzmPE8925czCMTze3MPzJ7QyzBxWTquxSC/tGXpFtr46angsi i8WW9pBKsXKTWiRRuslKq1lE+Rm9ut6XyQNpVfSISkdtDJ6dXKXVCVhwhTiOdlsDHtvu 6IXg== X-Gm-Message-State: ABuFfogZihmA8N9VlzUfuxhZL9WQ31AofD41qw+PNQazYhabSg4fiQw+ 0b72n8ShMfPXjNMYEr5gH6tKXO/Qzj8= X-Google-Smtp-Source: ACcGV62zgK3eyjrmZo2cpMF60SqgWcAhYe/AG7r9tWbtZtvwm1MhgwIMUUUr/fv39lRb9GeG6NeXjA== X-Received: by 2002:a05:6000:1187:: with SMTP id g7mr12735435wrx.173.1538146729721; Fri, 28 Sep 2018 07:58:49 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:58:43 +0200 Message-Id: <20180928145845.20473-3-pbonzini@redhat.com> In-Reply-To: <20180928145845.20473-1-pbonzini@redhat.com> References: <20180928145845.20473-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 28 Sep 2018 14:58:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 28 Sep 2018 14:58:52 +0000 (UTC) for IP:'209.85.221.49' DOMAIN:'mail-wr1-f49.google.com' HELO:'mail-wr1-f49.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.489 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.221.49 mail-wr1-f49.google.com 209.85.221.49 mail-wr1-f49.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 2/4] models: convert tags from property to field 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 28 Sep 2018 14:58:55 +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" Signed-off-by: Paolo Bonzini --- api/migrations/0035_message_tags.py | 22 ++++++++++ api/migrations/0036_populate_message_tags.py | 43 ++++++++++++++++++++ api/models.py | 1 + api/rest.py | 5 ++- api/views.py | 13 +++++- mods/git.py | 5 ++- mods/tags.py | 13 ++---- patchew-cli | 5 ++- www/urls.py | 2 +- 9 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 api/migrations/0035_message_tags.py create mode 100644 api/migrations/0036_populate_message_tags.py diff --git a/api/migrations/0035_message_tags.py b/api/migrations/0035_mess= age_tags.py new file mode 100644 index 0000000..4354bba --- /dev/null +++ b/api/migrations/0035_message_tags.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.13 on 2018-09-27 10:09 +from __future__ import unicode_literals + +from django.db import migrations +import jsonfield.encoder +import jsonfield.fields + + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0034_auto_20180822_1106'), + ] + + operations =3D [ + migrations.AddField( + model_name=3D'message', + name=3D'tags', + field=3Djsonfield.fields.JSONField(default=3D[], dump_kwargs= =3D{'cls': jsonfield.encoder.JSONEncoder, 'separators': (',', ':')}, load_k= wargs=3D{}), + ), + ] diff --git a/api/migrations/0036_populate_message_tags.py b/api/migrations/= 0036_populate_message_tags.py new file mode 100644 index 0000000..e9f2a70 --- /dev/null +++ b/api/migrations/0036_populate_message_tags.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations +from django.db.models import Count +import json + + +def tags_from_property(apps, schema_editor): + # We can't import the models directly as they may be a newer + # version than this migration expects. We use the historical version. + Message =3D apps.get_model('api', 'Message') + MessageProperty =3D apps.get_model('api', 'MessageProperty') + messages =3D Message.objects.filter(properties__name=3D'tags') + for m in messages: + mp =3D m.properties.filter(name=3D'tags')[0] + m.tags =3D mp.value + m.save() + MessageProperty.objects.filter(name=3D'tags').delete() + +def tags_to_property(apps, schema_editor): + # We can't import the models directly as they may be a newer + # version than this migration expects. We use the historical version. + Message =3D apps.get_model('api', 'Message') + MessageProperty =3D apps.get_model('api', 'MessageProperty') + messages =3D Message.objects.exclude(tags=3D[]) + for m in messages: + mp =3D MessageProperty(message=3Dm, + name=3D'tags', + value=3Dm.tags, + blob=3DFalse) + mp.save() + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0035_message_tags'), + ] + + operations =3D [ + migrations.RunPython(tags_from_property, + reverse_code=3Dtags_to_property), + ] diff --git a/api/models.py b/api/models.py index a6639b7..ab0bd06 100644 --- a/api/models.py +++ b/api/models.py @@ -460,6 +460,7 @@ class Message(models.Model): version =3D models.PositiveSmallIntegerField(default=3D0) sender =3D jsonfield.JSONCharField(max_length=3D4096, db_index=3DTrue) recipients =3D jsonfield.JSONField() + tags =3D jsonfield.JSONField(default=3D[]) prefixes =3D jsonfield.JSONField(blank=3DTrue) is_series_head =3D models.BooleanField() is_complete =3D models.BooleanField(default=3DFalse) diff --git a/api/rest.py b/api/rest.py index 8789e25..61df8cd 100644 --- a/api/rest.py +++ b/api/rest.py @@ -19,7 +19,7 @@ from .search import SearchEngine from rest_framework import (permissions, serializers, viewsets, filters, mixins, generics, renderers, status) from rest_framework.decorators import detail_route, action -from rest_framework.fields import SerializerMethodField, CharField, JSONFi= eld, EmailField +from rest_framework.fields import SerializerMethodField, CharField, JSONFi= eld, EmailField, ListField from rest_framework.relations import HyperlinkedIdentityField from rest_framework.response import Response import rest_framework @@ -238,11 +238,12 @@ class AddressSerializer(serializers.Serializer): class BaseMessageSerializer(serializers.ModelSerializer): class Meta: model =3D Message - fields =3D ('resource_uri', 'message_id', 'subject', 'date', 'send= er', 'recipients') + fields =3D ('resource_uri', 'message_id', 'subject', 'date', 'send= er', 'recipients', 'tags') =20 resource_uri =3D HyperlinkedMessageField(view_name=3D'messages-detail') recipients =3D AddressSerializer(many=3DTrue) sender =3D AddressSerializer() + tags =3D ListField(child=3DCharField(), required=3DFalse) =20 def create(self, validated_data): validated_data['recipients'] =3D self.fields['recipients'].create(= validated_data['recipients']) diff --git a/api/views.py b/api/views.py index 32bceab..f224a63 100644 --- a/api/views.py +++ b/api/views.py @@ -151,11 +151,18 @@ class SetProjectPropertiesView(APILoginRequiredView): for k, v in properties.items(): po.set_property(k, v) =20 +def get_properties(m): + r =3D m.get_properties() + # for compatibility with patchew-cli's applier mode + if m.tags: + r['tags'] =3D m.tags + return r + def prepare_patch(p): r =3D {"subject": p.subject, "message-id": p.message_id, "mbox": p.get_mbox(), - "properties": p.get_properties(), + "properties": get_properties(p) } return r =20 @@ -173,7 +180,9 @@ def prepare_series(request, s, fields=3DNone): if want_field("patches"): r["patches"] =3D [prepare_patch(x) for x in s.get_patches()] if want_field("properties"): - r["properties"] =3D s.get_properties() + r["properties"] =3D get_properties(s) + if want_field("tags"): + r["tags"] =3D s.tags if want_field("is_complete"): r["is_complete"] =3D s.is_complete if fields: diff --git a/mods/git.py b/mods/git.py index a985ba4..58e4bd2 100644 --- a/mods/git.py +++ b/mods/git.py @@ -228,7 +228,7 @@ class GitModule(PatchewModule): = project)}) =20 def get_base(self, series): - for tag in series.get_property("tags", []): + for tag in series.tags: if not tag.startswith("Based-on:"): continue base_id =3D tag[len("Based-on:"):].strip() @@ -279,7 +279,8 @@ class ApplierGetView(APILoginRequiredView): if not m: return None =20 - response =3D prepare_series(request, m, fields=3D["project", "mess= age-id", "patches", "properties"]) + response =3D prepare_series(request, m, fields=3D["project", "mess= age-id", "patches", + "properties", "tags"= ]) =20 po =3D m.project for prop in ["git.push_to", "git.public_repo", "git.url_template"]: diff --git a/mods/tags.py b/mods/tags.py index 5ec5bc2..1ac27a7 100644 --- a/mods/tags.py +++ b/mods/tags.py @@ -56,10 +56,11 @@ series cover letter, patch mail body and their replies. return set([x.strip() for x in tagsconfig.split(",") if x.strip()]= + BUILT_IN_TAGS) =20 def update_tags(self, s): - old =3D s.get_property("tags", []) + old =3D s.tags new =3D self.look_for_tags(s) if set(old) !=3D set(new): - s.set_property("tags", list(set(new))) + s.tags =3D list(set(new)) + s.save() return True =20 def on_message_added(self, event, message): @@ -84,7 +85,7 @@ series cover letter, patch mail body and their replies. num_reviewed =3D 0 def _find_reviewers(what): ret =3D set() - for rev_tag in [x for x in what.get_property("tags", []) if x.= lower().startswith(REV_BY_PREFIX.lower())]: + for rev_tag in [x for x in what.tags if x.lower().startswith(R= EV_BY_PREFIX.lower())]: ret.add(parse_address(rev_tag[len(REV_BY_PREFIX):])) return ret for p in series.get_patches(): @@ -120,12 +121,6 @@ series cover letter, patch mail body and their replies. r +=3D self.look_for_tags(x) return r =20 - def get_tags(self, m, request, format): - return m.get_property("tags", []) - - def rest_message_fields_hook(self, request, fields): - fields['tags'] =3D PluginMethodField(obj=3Dself) - def prepare_message_hook(self, request, message, detailed): if not message.is_series_head: return diff --git a/patchew-cli b/patchew-cli index c67abd5..b5d6ecb 100755 --- a/patchew-cli +++ b/patchew-cli @@ -693,8 +693,9 @@ class ApplyCommand(SubCommand): subprocess.check_output(["git", "log", "-n", "1", "--format=3D%b"], cwd=3Drepo)= \ .decode('utf-8').splitlines() - for t in set(p["properties"].get("tags", []) + \ - s["properties"].get("tags", [])): + # old servers do not have "tags" directly in the response + for t in set(p["properties"].get("tags", []) + p.get("tags", [= ]) + \ + s["properties"].get("tags", []) + s.get("tags", [= ])): if t in commit_message_lines: continue filter_cmd +=3D "echo '%s';" % t diff --git a/www/urls.py b/www/urls.py index 5787cbd..21b945c 100644 --- a/www/urls.py +++ b/www/urls.py @@ -34,6 +34,6 @@ urlpatterns +=3D [ url(r"^(?P[^/]*)/info$", views.view_project_detail, name= =3D"project_detail"), url(r"^(?P[^/]*)/(?P[^/]*)/$", views.view_ser= ies_detail, name=3D"series_detail"), url(r"^(?P[^/]*)/(?P[^/]*)/(?P[^/]= *)/$", views.view_series_message, name=3D"series_message"), - url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view= _series_mbox, name=3D"mbox"), + url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view= _mbox, name=3D"mbox"), url(r"^$", views.view_project_list, name=3D"project_list"), ] --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Wed Apr 24 01:01:39 2024 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 1538146736538933.0679927585197; Fri, 28 Sep 2018 07:58:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AC3430001E0; Fri, 28 Sep 2018 14:58:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2568665940; Fri, 28 Sep 2018 14:58:55 +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 164764BB74; Fri, 28 Sep 2018 14:58:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEwrdF026126 for ; Fri, 28 Sep 2018 10:58:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC0C765940; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E24665C1B5 for ; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 2D5A730820D0 for ; Fri, 28 Sep 2018 14:58:52 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id j15-v6so6716195wrt.8 for ; Fri, 28 Sep 2018 07:58:52 -0700 (PDT) Received: from donizetti.par1.mozilla.com ([2a00:8c40:243:232:de:fba5:535e:2dc2]) by smtp.gmail.com with ESMTPSA id h73-v6sm5278053wma.11.2018.09.28.07.58.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:58:49 -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=5/YUTceqDjvKsvQEj+/RhzvjaRPZOb6L7mtHA6UKHmc=; b=gHkBrzUHwG5H6XK2MK7p3sxWNLwCS7UxmggWQ/s0EEbGbjjOTGcPOa3fmynra9Y+TS I7TMmz/GJ2Y/2xtdp6/vozSTYZZBSnGfdJfWq9Harj5mZkXkqBoKoHpJh34mg7v4JnfD qtUn8pVC2mOQ3CizpQYlP5bsEOEfUAZ4GKF6Tvh1wfavl0Ha9y5UjQilcuNl3PC3zFtJ KkFKzWTldkpHgT1nO3cEZGNq82KFYCoTVOV06hYtxDhg85pJ/9pCa5/3qZEumJO4/Qsk z7yVuUqtuwE1PM9LA75oQ/SZPhwK6PKQ+ZGqVOoGUsUNJD3Go91k80lLodID58jWvIzE eMSA== 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=5/YUTceqDjvKsvQEj+/RhzvjaRPZOb6L7mtHA6UKHmc=; b=pPK82cy0Llrm05bJm5SSBNrokoPzn0OlbAWwT0S972d9KB+tONVUYwt1PFZsNQo2pd WPWbxCYswkgYo9jM5ciOHof37BVC7xTKOA0knupPPmhf2RUPo0dF1vnz6O8ZSNmr58Gw NOGYwx46cXBcheBd/yIpI5qhVmXRfg3ef1yL0t2E9EmBIKQ4jb7pQGr8lERQVYkbT2hZ iEZWDTxzCUUmPcP99VYjHji8tJJK7sozu4+UqF8oLmNs8asPhlz8ysR2XClB7E6lgVcn zOZ/GgzW3Fw2VTLGL+pOLH+n3ZHCm5OyZuRxbMczfo6K1bWYWzq9tPy/1hahWB50A1Yi 34Hw== X-Gm-Message-State: ABuFfojSwR38uscSkm64ANPtz8idkQ08IkB11yh0kOwPS0eXkAixhQLL N3exlNEZxl57uR7UlgwFnc6IsY6js4Q= X-Google-Smtp-Source: ACcGV62q3kUaevK/E2QteU5L0d9hx6PN2/ArTsWwiSXjY629bI1EhVGlw24D9jI4mJYcvMVelvLjTA== X-Received: by 2002:a5d:47c1:: with SMTP id l1-v6mr12807232wrs.188.1538146730488; Fri, 28 Sep 2018 07:58:50 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:58:44 +0200 Message-Id: <20180928145845.20473-4-pbonzini@redhat.com> In-Reply-To: <20180928145845.20473-1-pbonzini@redhat.com> References: <20180928145845.20473-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 28 Sep 2018 14:58:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 28 Sep 2018 14:58:52 +0000 (UTC) for IP:'209.85.221.48' DOMAIN:'mail-wr1-f48.google.com' HELO:'mail-wr1-f48.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.489 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.221.48 mail-wr1-f48.google.com 209.85.221.48 mail-wr1-f48.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 3/4] mbox: extract decode_payload and simplify get_body 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 28 Sep 2018 14:58:55 +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" We will have to extract the body of the message and process it, so we need = to do the same processing as get_body(). Extract it into a separate function. Signed-off-by: Paolo Bonzini --- mbox.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mbox.py b/mbox.py index 35b2270..47a770f 100644 --- a/mbox.py +++ b/mbox.py @@ -41,6 +41,18 @@ def addr_db_to_rest(obj): else: return {"address": obj[1]} =20 +def decode_payload(m): + payload =3D m.get_payload(decode=3DTrue) + charset =3D m.get_content_charset() + try: + return payload.decode(charset or 'utf-8', errors=3D'replace') + except: + if charset !=3D 'utf-8': + # Still fall back from non-utf-8 to utf-8 + return payload.decode('utf-8') + else: + raise + class MboxMessage(object): """ Helper class to process mbox """ def __init__(self, m): @@ -161,21 +173,11 @@ class MboxMessage(object): return s.intersection(self.get_prefixes(upper=3DTrue)) =20 def get_body(self): - def decode_payload(payload, charset): - try: - return payload.decode(charset or 'utf-8', errors=3D'replac= e') - except: - if charset !=3D 'utf-8': - # Still fall back from non-utf-8 to utf-8 - return payload.decode('utf-8') - else: - raise def _get_message_text(m): payload =3D m.get_payload(decode=3Dnot self._m.is_multipart()) body =3D '' if m.get_content_type() =3D=3D "text/plain": - body =3D decode_payload(m.get_payload(decode=3DTrue), - self._m.get_content_charset()) + body =3D decode_payload(m) elif isinstance(payload, list): for p in payload: body +=3D _get_message_text(p) --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Wed Apr 24 01:01:39 2024 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 1538146738975455.7217647301088; Fri, 28 Sep 2018 07:58:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C62D530832DC; Fri, 28 Sep 2018 14:58:57 +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 B52AB60920; Fri, 28 Sep 2018 14:58:57 +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 A64B1181A12F; Fri, 28 Sep 2018 14:58:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEwuel026153 for ; Fri, 28 Sep 2018 10:58:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB8816252C; Fri, 28 Sep 2018 14:58:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3D5467149 for ; Fri, 28 Sep 2018 14:58:54 +0000 (UTC) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 358D04B6E8 for ; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: by mail-wr1-f42.google.com with SMTP id u12-v6so6727620wrr.4 for ; Fri, 28 Sep 2018 07:58:53 -0700 (PDT) Received: from donizetti.par1.mozilla.com ([2a00:8c40:243:232:de:fba5:535e:2dc2]) by smtp.gmail.com with ESMTPSA id h73-v6sm5278053wma.11.2018.09.28.07.58.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:58:50 -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=pUiZ/xedC87XsStU+ks/MstZT0tGVUwiUpkP0qiF8GU=; b=Tyob1YO/evjHTbdSUmSFvbCkj0mPbineB50TFA9g2JCXHe0XD3MV3lntBVyVz4kzhH 9yzFcRc8MfHC6euRmC8iMwRPlDlcw3Vn2cPB2KmmNWsM8tOp2AKghIEvqTPI1SOikqUY 36Ji5Uza9zUX0JqtwfZy3kZ24QWLe1EzDhfvAy1fsnKOs+tctk7xbAY8RJxOH7gcRumO 9J/jXyzRiv2dSpJfkTr4KkI/IvobZMySrSK/+JOBdTCAneapnhuDupDWfNJmfDtJ8995 oZKi5fJtxtvFdBiBO30bz9hFUOWALeaIszVlRglQnOlpKaNC2FUrrhZ/7R5dAkPB0S8K FaBw== 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=pUiZ/xedC87XsStU+ks/MstZT0tGVUwiUpkP0qiF8GU=; b=pxr8BbrdZWrPta+KMVZPggF/abmrJdlvevy9SNmdC/OaRIWr+/xQEZrS2E9UG62ian sFnDph7rNyDs7Vf+PEDpDVU0fz3ow7aC3lwhiXBuacYZQLMSl8FR+WGcrbxCt58vO4Rv H0qr8+2gLgCRD1fX/bcGOI9Ff/977H2X+PGd9eNscyLvhUqxgygZOrf1REUU7DMlRecZ tOw++egWC6kzvPhFhVMAXec+A/1JsuU6Wk4Vw9BbBN9JnXp2XATVnnzyJxekvafNxZ4v TlBZrl/ugkTiN90n5kNTlYofNNx7Zk3ZtwfD0aFzZ00mKGGIEBIJ7o9NdXf1QKcWe91f 6QKA== X-Gm-Message-State: ABuFfogSfyjximS24yLZqondB5to80fXros7kw1vnI5a7IXEVNT04gnS z3/S2A3XbLXLi5K9nVtVXnsA4pQZTvU= X-Google-Smtp-Source: ACcGV61C35QPPiIMp3sPwwuzuj4pj7RWe4oE9bhLwgfvhya5MEkMlLMOobsRAnOx6dRV0qhgKErY1w== X-Received: by 2002:a5d:6748:: with SMTP id l8-v6mr6714870wrw.197.1538146731560; Fri, 28 Sep 2018 07:58:51 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:58:45 +0200 Message-Id: <20180928145845.20473-5-pbonzini@redhat.com> In-Reply-To: <20180928145845.20473-1-pbonzini@redhat.com> References: <20180928145845.20473-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 28 Sep 2018 14:58:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 28 Sep 2018 14:58:53 +0000 (UTC) for IP:'209.85.221.42' DOMAIN:'mail-wr1-f42.google.com' HELO:'mail-wr1-f42.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.489 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.221.42 mail-wr1-f42.google.com 209.85.221.42 mail-wr1-f42.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 4/4] views: include tags in download link 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 28 Sep 2018 14:58:57 +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" Retrieve the tags that have been collected by the tags module, and place th= em in the mbox before the --- line. Signed-off-by: Paolo Bonzini --- api/models.py | 2 +- www/views.py | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/api/models.py b/api/models.py index ab0bd06..a688c77 100644 --- a/api/models.py +++ b/api/models.py @@ -336,7 +336,7 @@ class MessageManager(models.Manager): def find_series(self, message_id, project_name=3DNone): return self.series_heads(project_name).filter(message_id=3Dmessage= _id).first() =20 - def find_message(self, message_id, project_name): + def find_message(self, message_id, project_name=3DNone): return self.project_messages(project_name).filter(message_id=3Dmes= sage_id).first() =20 def patches(self): diff --git a/www/views.py b/www/views.py index 11043a1..daa2362 100644 --- a/www/views.py +++ b/www/views.py @@ -16,7 +16,11 @@ from django.urls import reverse from django.utils.html import format_html from django.conf import settings import api +import email +from mbox import decode_payload +import re from mod import dispatch_module_hook +from patchew.tags import lines_iter import subprocess =20 PAGE_SIZE =3D 50 @@ -247,17 +251,54 @@ def view_series_list(request, project): return render_series_list_page(request, query, project=3Dproject) =20 def view_mbox(request, project, message_id): - s =3D api.models.Message.objects.find_message(project, message_id) + # FIXME: what happens with base64 messages? + def mbox_with_tags_iter(mbox, tags): + regex =3D "^[-A-Za-z]*:" + old_tags =3D set() + lines =3D lines_iter(mbox) + need_minusminusminus =3D False + for line in lines: + if line.startswith('---'): + need_minusminusminus =3D True + break + yield line + if re.match(regex, line): + old_tags.add(line) + + # If no --- line, tags go at the end as there's no better place + for tag in tags: + if not tag in old_tags: + yield tag + if need_minusminusminus: + yield line + yield from lines + + def get_mbox_with_tags(m): + mbox =3D m.get_mbox() + try: + msg =3D email.message_from_string(mbox) + except: + return mbox + container =3D msg.get_payload(0) if msg.is_multipart() else msg + if container.get_content_type() !=3D "text/plain": + return mbox + + payload =3D decode_payload(container) + container.set_payload('\n'.join(mbox_with_tags_iter(payload, m.tag= s))) + return msg.as_string() + + s =3D api.models.Message.objects.find_message(message_id, project_name= =3Dproject) + global _instance if not s: raise Http404("Series not found") - if s.is_cover_letter: + if not s.is_patch: if not s.is_complete: raise Http404("Series not complete") messages =3D s.get_patches() else: messages =3D [s] mbox =3D "\n".join(["From %s %s\n" % (x.get_sender_addr(), x.get_ascti= me()) + \ - x.get_mbox(x) for x in messages]) + get_mbox_with_tags(x) for x in messages]) return HttpResponse(mbox, content_type=3D"text/plain") =20 def view_series_detail(request, project, message_id): --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel