From nobody Tue May 13 12:57:21 2025 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; 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 1524485671188486.29002542166256; Mon, 23 Apr 2018 05:14:31 -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 312D031500BE; Mon, 23 Apr 2018 12:14:30 +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 21D535E1A0; Mon, 23 Apr 2018 12:14:30 +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 0FDEE4CA9E; Mon, 23 Apr 2018 12:14:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3NCESRP004174 for ; Mon, 23 Apr 2018 08:14:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A65010FFE6F; Mon, 23 Apr 2018 12:14:28 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-110.ams2.redhat.com [10.36.116.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7552510FFE6D for ; Mon, 23 Apr 2018 12:14:27 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Mon, 23 Apr 2018 14:14:20 +0200 Message-Id: <20180423121423.21500-2-pbonzini@redhat.com> In-Reply-To: <20180423121423.21500-1-pbonzini@redhat.com> References: <20180423121423.21500-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/4] add result renderer infrastructure 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.41]); Mon, 23 Apr 2018 12:14:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Plugins can prepare the "status" section of the series/message detail pages from the same Result objects used by the REST API. Record in the Result the object that created it, so that it can prepare an HTML rendering of the Result. Signed-off-by: Paolo Bonzini --- api/models.py | 11 ++++++++--- static/css/base.css | 6 ++++-- www/templates/project-detail.html | 9 +++++++++ www/templates/series-detail.html | 9 +++++++++ www/views.py | 18 ++++++++++++++++++ 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/api/models.py b/api/models.py index 9aa1196..501070c 100644 --- a/api/models.py +++ b/api/models.py @@ -601,13 +601,18 @@ class Module(models.Model): def __str__(self): return self.name =20 -class Result(namedtuple("Result", "name status log log_url obj data")): +class Result(namedtuple("Result", "name status log log_url obj data render= er")): __slots__ =3D () =20 - def __new__(cls, name, status, obj, log=3DNone, log_url=3DNone, data= =3DNone, request=3DNone): + def __new__(cls, name, status, obj, log=3DNone, log_url=3DNone, data= =3DNone, request=3DNone, renderer=3DNone): if log_url is not None and request is not None: log_url =3D request.build_absolute_uri(log_url) if status not in ('pending', 'success', 'failure'): raise ValueError("invalid value '%s' for status field" % statu= s) return super(cls, Result).__new__(cls, status=3Dstatus, log=3Dlog,= log_url=3Dlog_url, - obj=3Dobj, data=3Ddata, name=3Dn= ame) + obj=3Dobj, data=3Ddata, name=3Dn= ame, renderer=3Drenderer) + + def render(self): + if self.renderer is None: + return None + return self.renderer.render_result(self) diff --git a/static/css/base.css b/static/css/base.css index 82995f5..35fba6e 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -137,10 +137,12 @@ h1, h2, h3, .h1, .h2, .h3 { .status-content > .fa { color: #337ab7; } -.status-content.status-alert > .fa { +.status-content.status-alert > .fa, +.status-content.status-failure > .fa { color: #CC0000; } -.status-content.status-good > .fa { +.status-content.status-good > .fa, +.status-content.status-success > .fa { color: #009900; } .status-content > div { diff --git a/www/templates/project-detail.html b/www/templates/project-deta= il.html index 80fce3b..aaccdc0 100644 --- a/www/templates/project-detail.html +++ b/www/templates/project-detail.html @@ -41,6 +41,15 @@ {% endif %} +{% for result in results %} +
+ {% if result.status =3D=3D "pending" %} + {% elif result.status =3D=3D "running" %} + {% elif result.status =3D=3D "failure" %} + {% elif result.status =3D=3D "success" %} {% endif %} +
{{ result.html }}
+
+{% endfor %} {% for status in project.extra_status %}
{% if status.icon %} diff --git a/www/templates/series-detail.html b/www/templates/series-detail= .html index 434bc35..9b2db1c 100644 --- a/www/templates/series-detail.html +++ b/www/templates/series-detail.html @@ -56,6 +56,15 @@
Only {{ series.num_patches }} patches received!
{% endif %} +{% for result in results %} +
+ {% if result.status =3D=3D "pending" %} + {% elif result.status =3D=3D "running" %} + {% elif result.status =3D=3D "failure" %} + {% elif result.status =3D=3D "success" %} {% endif %} +
{{ result.html }}
+
+{% endfor %} {% for status in series.extra_status %}
{% if status.icon %} diff --git a/www/views.py b/www/views.py index 8965ebf..b0ccf48 100644 --- a/www/views.py +++ b/www/views.py @@ -91,6 +91,21 @@ def prepare_series(request, s, skip_patches=3DFalse): add_msg_recurse(s, skip_patches) return r =20 +def prepare_results(request, obj): + results =3D [] + dispatch_module_hook("rest_results_hook", request=3Drequest, + obj=3Dobj, results=3Dresults, detailed=3DFalse) + + results_dicts =3D [] + for result in results: + html =3D result.render() + if html is None: + continue + d =3D result._asdict() + d['html'] =3D html + results_dicts.append(d) + return results_dicts + def prepare_series_list(request, sl): return [prepare_message(request, s, False) for s in sl] =20 @@ -204,6 +219,7 @@ def view_project_detail(request, project): po.extra_ops =3D [] dispatch_module_hook("prepare_project_hook", request=3Drequest, projec= t=3Dpo) return render_page(request, "project-detail.html", + results=3Dprepare_results(request, po), project=3Dpo, navigate_links=3Dnav_path, search=3D"") @@ -255,6 +271,7 @@ def view_series_detail(request, project, message_id): project=3Dproject, navigate_links=3Dnav_path, search=3Dsearch, + results=3Dprepare_results(request, s), patches=3Dprepare_patches(request, s), messages=3Dprepare_series(request, s, is_cover_lett= er)) =20 @@ -280,5 +297,6 @@ def view_series_message(request, project, thread_id, me= ssage_id): project=3Dproject, navigate_links=3Dnav_path, search=3Dsearch, + results=3D[], patches=3Dprepare_patches(request, s), messages=3Dprepare_series(request, m)) --=20 2.17.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel