[debug-toolbar] add cw general panel with controller
authorLaurent Peuch <cortex@worlddomination.be>
Tue, 08 Oct 2019 23:11:19 +0200
changeset 12764 fb97669efcaa
parent 12763 5c609202eb61
child 12765 771c99f16780
[debug-toolbar] add cw general panel with controller Closes #17219897
cubicweb/debug.py
cubicweb/pyramid/bwcompat.py
cubicweb/pyramid/debug_toolbar_templates/cw.dbtmako
cubicweb/pyramid/debugtoolbar_panels.py
--- a/cubicweb/debug.py	Mon Nov 18 12:41:44 2019 +0100
+++ b/cubicweb/debug.py	Tue Oct 08 23:11:19 2019 +0200
@@ -22,6 +22,7 @@
 
 
 SUBSCRIBERS = {
+    "controller": [],
     "rql": [],
     "sql": [],
 }
--- a/cubicweb/pyramid/bwcompat.py	Mon Nov 18 12:41:44 2019 +0100
+++ b/cubicweb/pyramid/bwcompat.py	Tue Oct 08 23:11:19 2019 +0200
@@ -34,7 +34,7 @@
 import cubicweb.web
 
 from cubicweb.web.application import CubicWebPublisher
-
+from cubicweb.debug import emit_to_debug_channel
 from cubicweb.web import LogOut, PublishException
 
 from cubicweb.pyramid.core import cw_to_pyramid
@@ -93,6 +93,13 @@
                                  ctrlid, req.path, controller,
                                  inspect.getsourcefile(controller.__class__),
                                  inspect.getsourcelines(controller.__class__)[1])
+                        emit_to_debug_channel("controller", {
+                            "kind": ctrlid,
+                            "request": req,
+                            "path": req.path,
+                            "controller": controller,
+                            "config": self.appli.repo.config,
+                        })
                     except cubicweb.NoSelectableObject:
                         log.warn("WARNING '%s' unauthorized request", req.path)
                         raise httpexceptions.HTTPUnauthorized(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/pyramid/debug_toolbar_templates/cw.dbtmako	Tue Oct 08 23:11:19 2019 +0200
@@ -0,0 +1,63 @@
+<h3>Controller</h3>
+
+<table class="table table-striped table-condensed">
+    <thead>
+        <tr>
+            <th>Kind</th>
+            <th>Request</th>
+            <th>Path</th>
+            <th>Controller</th>
+        </tr>
+    </thead>
+    <tbody>
+        <tr>
+            <td>${controller["kind"]}</td>
+            <td>${controller["request"]}</td>
+            <td>${controller["path"]}</td>
+            <td>${controller["controller"]}</td>
+        </tr>
+    </tbody>
+</table>
+
+<h3>Configuration</h3>
+
+<table class="table table-striped table-condensed">
+    <thead>
+        <tr>
+            <th>Key</th>
+            <th>Value</th>
+            <th>Default</th>
+            <th>Help</th>
+        </tr>
+    </thead>
+    <tbody>
+        % for key, metadata in sorted(controller["config"].options, key=lambda x: x[0]):
+            % if hasattr(controller["config"].config, key.replace("-", "_")):
+            <% value = getattr(controller["config"].config, key.replace("-", "_")) %>
+            <tr>
+                <td>${key}</td>
+                % if value != metadata["default"]:
+                <td><b>${value}</b></td>
+                % else:
+                <td>${value}</td>
+                % endif
+                <td>${metadata["default"]}</td>
+                <td>${metadata["help"]}</td>
+            </tr>
+            % endif
+        % endfor
+    </tbody>
+</table>
+
+
+
+<h3>Useful links</h3>
+
+<!-- link on the default home as an admin -->
+<ul>
+    <li><a href="/siteconfig">site configuration</a></li>
+    <li><a href="/schema">data model schema</a></li>
+    <li><a href="/cwuser">users and groups</a></li>
+    <li><a href="/cwsource">data sources</a></li>
+    <li><a href="/siteinfo">Site information</a></li>
+</ul>
--- a/cubicweb/pyramid/debugtoolbar_panels.py	Mon Nov 18 12:41:44 2019 +0100
+++ b/cubicweb/pyramid/debugtoolbar_panels.py	Tue Oct 08 23:11:19 2019 +0200
@@ -21,6 +21,39 @@
 from cubicweb.misc.source_highlight import highlight_html, generate_css
 
 
+class CubicWebDebugPanel(DebugPanel):
+    """
+    CubicWeb general debug panel
+    """
+
+    """
+    Excepted formats:
+    Controller: {
+        "kind": ctrlid,
+        "request": req,
+        "path": req.path,
+        "controller": controller,
+    }
+    """
+
+    name = 'CubicWeb'
+    nav_title = 'CubicWeb'
+    title = 'CubicWeb general panel'
+
+    has_content = True
+    template = 'cubicweb.pyramid:debug_toolbar_templates/cw.dbtmako'
+
+    def __init__(self, request):
+        self.data = {'controller': None}
+        subscribe_to_debug_channel("controller", self.collect_controller)
+
+    def collect_controller(self, controller):
+        self.data["controller"] = controller
+
+    def process_response(self, response):
+        unsubscribe_to_debug_channel("controller", self.collect_controller)
+
+
 class RQLDebugPanel(DebugPanel):
     """
     CubicWeb RQL debug panel
@@ -78,4 +111,5 @@
 
 
 def includeme(config):
+    config.add_debugtoolbar_panel(CubicWebDebugPanel)
     config.add_debugtoolbar_panel(RQLDebugPanel)