[debug-toolbar] add cw general panel with controller

Closes #17219897

authorLaurent Peuch <cortex@worlddomination.be>
changesetfb97669efcaa
branchdefault
phasepublic
hiddenno
parent revision#5c609202eb61 [debug-toolbar] make linter happy
child revision#771c99f16780 [debug-toolbar] add sql panel, #7ed4eb55ad08 Fix ModuleNotFoundError No module named 'statsd_logger'
files modified by this revision
cubicweb/debug.py
cubicweb/pyramid/bwcompat.py
cubicweb/pyramid/debug_toolbar_templates/cw.dbtmako
cubicweb/pyramid/debugtoolbar_panels.py
# HG changeset patch
# User Laurent Peuch <cortex@worlddomination.be>
# Date 1570569079 -7200
# Tue Oct 08 23:11:19 2019 +0200
# Node ID fb97669efcaa01d1fe749901c5dd69b30c80c121
# Parent 5c609202eb6121222f620af1e2ee17374ebbc638
[debug-toolbar] add cw general panel with controller

Closes #17219897

diff --git a/cubicweb/debug.py b/cubicweb/debug.py
@@ -20,10 +20,11 @@
1 
2  logger = getLogger('cubicweb')
3 
4 
5  SUBSCRIBERS = {
6 +    "controller": [],
7      "rql": [],
8      "sql": [],
9  }
10 
11 
diff --git a/cubicweb/pyramid/bwcompat.py b/cubicweb/pyramid/bwcompat.py
@@ -32,11 +32,11 @@
12 
13  import cubicweb
14  import cubicweb.web
15 
16  from cubicweb.web.application import CubicWebPublisher
17 -
18 +from cubicweb.debug import emit_to_debug_channel
19  from cubicweb.web import LogOut, PublishException
20 
21  from cubicweb.pyramid.core import cw_to_pyramid
22 
23 
@@ -91,10 +91,17 @@
24                              ctrlid, req, appli=self.appli)
25                          log.info("REQUEST [%s] '%s' selected controller %s at %s:%s",
26                                   ctrlid, req.path, controller,
27                                   inspect.getsourcefile(controller.__class__),
28                                   inspect.getsourcelines(controller.__class__)[1])
29 +                        emit_to_debug_channel("controller", {
30 +                            "kind": ctrlid,
31 +                            "request": req,
32 +                            "path": req.path,
33 +                            "controller": controller,
34 +                            "config": self.appli.repo.config,
35 +                        })
36                      except cubicweb.NoSelectableObject:
37                          log.warn("WARNING '%s' unauthorized request", req.path)
38                          raise httpexceptions.HTTPUnauthorized(
39                              req._('not authorized'))
40 
diff --git a/cubicweb/pyramid/debug_toolbar_templates/cw.dbtmako b/cubicweb/pyramid/debug_toolbar_templates/cw.dbtmako
@@ -0,0 +1,63 @@
41 +<h3>Controller</h3>
42 +
43 +<table class="table table-striped table-condensed">
44 +    <thead>
45 +        <tr>
46 +            <th>Kind</th>
47 +            <th>Request</th>
48 +            <th>Path</th>
49 +            <th>Controller</th>
50 +        </tr>
51 +    </thead>
52 +    <tbody>
53 +        <tr>
54 +            <td>${controller["kind"]}</td>
55 +            <td>${controller["request"]}</td>
56 +            <td>${controller["path"]}</td>
57 +            <td>${controller["controller"]}</td>
58 +        </tr>
59 +    </tbody>
60 +</table>
61 +
62 +<h3>Configuration</h3>
63 +
64 +<table class="table table-striped table-condensed">
65 +    <thead>
66 +        <tr>
67 +            <th>Key</th>
68 +            <th>Value</th>
69 +            <th>Default</th>
70 +            <th>Help</th>
71 +        </tr>
72 +    </thead>
73 +    <tbody>
74 +        % for key, metadata in sorted(controller["config"].options, key=lambda x: x[0]):
75 +            % if hasattr(controller["config"].config, key.replace("-", "_")):
76 +            <% value = getattr(controller["config"].config, key.replace("-", "_")) %>
77 +            <tr>
78 +                <td>${key}</td>
79 +                % if value != metadata["default"]:
80 +                <td><b>${value}</b></td>
81 +                % else:
82 +                <td>${value}</td>
83 +                % endif
84 +                <td>${metadata["default"]}</td>
85 +                <td>${metadata["help"]}</td>
86 +            </tr>
87 +            % endif
88 +        % endfor
89 +    </tbody>
90 +</table>
91 +
92 +
93 +
94 +<h3>Useful links</h3>
95 +
96 +<!-- link on the default home as an admin -->
97 +<ul>
98 +    <li><a href="/siteconfig">site configuration</a></li>
99 +    <li><a href="/schema">data model schema</a></li>
100 +    <li><a href="/cwuser">users and groups</a></li>
101 +    <li><a href="/cwsource">data sources</a></li>
102 +    <li><a href="/siteinfo">Site information</a></li>
103 +</ul>
diff --git a/cubicweb/pyramid/debugtoolbar_panels.py b/cubicweb/pyramid/debugtoolbar_panels.py
@@ -19,10 +19,43 @@
104  from pyramid_debugtoolbar.panels import DebugPanel
105  from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel
106  from cubicweb.misc.source_highlight import highlight_html, generate_css
107 
108 
109 +class CubicWebDebugPanel(DebugPanel):
110 +    """
111 +    CubicWeb general debug panel
112 +    """
113 +
114 +    """
115 +    Excepted formats:
116 +    Controller: {
117 +        "kind": ctrlid,
118 +        "request": req,
119 +        "path": req.path,
120 +        "controller": controller,
121 +    }
122 +    """
123 +
124 +    name = 'CubicWeb'
125 +    nav_title = 'CubicWeb'
126 +    title = 'CubicWeb general panel'
127 +
128 +    has_content = True
129 +    template = 'cubicweb.pyramid:debug_toolbar_templates/cw.dbtmako'
130 +
131 +    def __init__(self, request):
132 +        self.data = {'controller': None}
133 +        subscribe_to_debug_channel("controller", self.collect_controller)
134 +
135 +    def collect_controller(self, controller):
136 +        self.data["controller"] = controller
137 +
138 +    def process_response(self, response):
139 +        unsubscribe_to_debug_channel("controller", self.collect_controller)
140 +
141 +
142  class RQLDebugPanel(DebugPanel):
143      """
144      CubicWeb RQL debug panel
145      """
146 
@@ -76,6 +109,7 @@
147          unsubscribe_to_debug_channel("rql", self.collect_rql_queries)
148          unsubscribe_to_debug_channel("sql", self.collect_sql_queries)
149 
150 
151  def includeme(config):
152 +    config.add_debugtoolbar_panel(CubicWebDebugPanel)
153      config.add_debugtoolbar_panel(RQLDebugPanel)