[debug-toolbar] add registry panel

Closes #17219866

authorLaurent Peuch <cortex@worlddomination.be>
changeset682d0790997f
branchdefault
phasepublic
hiddenno
parent revision#771c99f16780 [debug-toolbar] add sql panel
child revision#d50661367401 Increase needed version of logilab-common to >= 1.5.0
files modified by this revision
cubicweb/debug.py
cubicweb/pyramid/bwcompat.py
cubicweb/pyramid/debug_toolbar_templates/registry.dbtmako
cubicweb/pyramid/debugtoolbar_panels.py
# HG changeset patch
# User Laurent Peuch <cortex@worlddomination.be>
# Date 1573742435 -3600
# Thu Nov 14 15:40:35 2019 +0100
# Node ID 682d0790997f8edf609b3a95d78b9945595c237c
# Parent 771c99f16780cf3820ca87db74e5d3b776ac3b58
[debug-toolbar] add registry panel

Closes #17219866

diff --git a/cubicweb/debug.py b/cubicweb/debug.py
@@ -23,10 +23,11 @@
1 
2  SUBSCRIBERS = {
3      "controller": [],
4      "rql": [],
5      "sql": [],
6 +    "vreg": [],
7  }
8 
9 
10  def subscribe_to_debug_channel(channel, subscriber):
11      if channel not in SUBSCRIBERS.keys():
diff --git a/cubicweb/pyramid/bwcompat.py b/cubicweb/pyramid/bwcompat.py
@@ -91,10 +91,13 @@
12                              ctrlid, req, appli=self.appli)
13                          log.info("REQUEST [%s] '%s' selected controller %s at %s:%s",
14                                   ctrlid, req.path, controller,
15                                   inspect.getsourcefile(controller.__class__),
16                                   inspect.getsourcelines(controller.__class__)[1])
17 +                        emit_to_debug_channel("vreg", {
18 +                            "vreg": vreg,
19 +                        })
20                          emit_to_debug_channel("controller", {
21                              "kind": ctrlid,
22                              "request": req,
23                              "path": req.path,
24                              "controller": controller,
diff --git a/cubicweb/pyramid/debug_toolbar_templates/registry.dbtmako b/cubicweb/pyramid/debug_toolbar_templates/registry.dbtmako
@@ -0,0 +1,93 @@
25 +% if vreg:
26 +
27 +<div id="registry-store">
28 +    <div class="row">
29 +        <div class="col-md-3">
30 +            <nav id="registry-store-categories">
31 +                <ul class="nav nav-pills nav-stacked">
32 +                    % for category in sorted(vreg.keys()):
33 +                    <li role="presentation"><a href="#detail-${category}">${category}</a></li>
34 +                    % endfor
35 +                </ul>
36 +            </nav>
37 +        </div>
38 +
39 +        <div class="col-md-9">
40 +            % for category, data in sorted(vreg.items(), key=lambda x: x[0]):
41 +            <div class="anchor">
42 +                <a class="anchor" id="detail-${category}"></a>
43 +                <h4>${category.title()}</h4>
44 +                <table class="table table-bordered table-striped">
45 +                    % for key, values in sorted(data.items(), key=lambda x: x[0]):
46 +                    <tr>
47 +                        <th>${key}</th>
48 +                        <td>
49 +                            <ul>
50 +                                % for value in values:
51 +                                <li>
52 +                                    % if isinstance(value, type):
53 +                                    ${value.__module__}.${value.__name__}
54 +                                    % else:
55 +                                    ${value}
56 +                                    % endif
57 +
58 +                                    <ul>
59 +                                        % if hasattr(value, "cw_etype"):
60 +                                        <li>regid: '${value.cw_etype}'</li>
61 +                                        % elif hasattr(value, "__regid__"):
62 +                                        <li>regid: '${value.__regid__}'</li>
63 +                                        % endif
64 +
65 +                                        % if hasattr(value, "__select__"):
66 +                                            <li>select: '${value.__select__}'</li>
67 +                                            % if hasattr(value.__select__, "func_name"):
68 +                                            <li>select name: '${value.__select__.func_name}'</li>
69 +                                            % endif
70 +                                            % if hasattr(value.__select__, "score"):
71 +                                            <li>select score: '${value.__select__.score}'</li>
72 +                                            % endif
73 +                                        % endif
74 +
75 +                                        <li>registries: ${value.__registries__}</li>
76 +
77 +                                        % if hasattr(value, "rest_attr"):
78 +                                        <li>rest_attr: '${value.rest_attr}'</li>
79 +                                        % endif
80 +
81 +                                        % if hasattr(value, "fetch_attrs"):
82 +                                        <li>fetch_attrs: '${value.fetch_attrs}'</li>
83 +                                        % endif
84 +
85 +                                        % if hasattr(value, "cw_skip_copy_for"):
86 +                                        <li>cw_skip_copy_for: '${value.cw_skip_copy_for}'</li>
87 +                                        % endif
88 +
89 +                                        % if hasattr(value, "e_schema"):
90 +                                        <li>e_schema: '${value.e_schema}'</li>
91 +                                        % endif
92 +                                    </ul>
93 +                                </li>
94 +                                % endfor
95 +                            </ul>
96 +                        </td>
97 +                    </tr>
98 +                    % endfor
99 +                </table>
100 +            </div>
101 +            % endfor
102 +        </div>
103 +    </div>
104 +</div>
105 +
106 +% else:
107 +<p>No registry store got collected, is it a bug?</p>
108 +% endif
109 +
110 +<style>
111 +a.anchor {
112 +    display: block;
113 +    position: relative;
114 +    top: -150px;
115 +    visibility: hidden;
116 +}
117 +</style>
diff --git a/cubicweb/pyramid/debugtoolbar_panels.py b/cubicweb/pyramid/debugtoolbar_panels.py
@@ -52,10 +52,33 @@
118 
119      def process_response(self, response):
120          unsubscribe_to_debug_channel("controller", self.collect_controller)
121 
122 
123 +class RegistryDebugPanel(DebugPanel):
124 +    """
125 +    CubicWeb registry content and decisions debug panel
126 +    """
127 +
128 +    name = 'Registry'
129 +    title = 'Registry Store'
130 +    nav_title = 'Registry Store'
131 +
132 +    has_content = True
133 +    template = 'cubicweb.pyramid:debug_toolbar_templates/registry.dbtmako'
134 +
135 +    def __init__(self, request):
136 +        self.data = {'vreg': None}
137 +        subscribe_to_debug_channel("vreg", self.collect_vreg)
138 +
139 +    def collect_vreg(self, message):
140 +        self.data["vreg"] = message["vreg"]
141 +
142 +    def process_response(self, response):
143 +        unsubscribe_to_debug_channel("vreg", self.collect_vreg)
144 +
145 +
146  class RQLDebugPanel(DebugPanel):
147      """
148      CubicWeb RQL debug panel
149      """
150 
@@ -165,7 +188,8 @@
151          unsubscribe_to_debug_channel("sql", self.collect_sql_queries)
152 
153 
154  def includeme(config):
155      config.add_debugtoolbar_panel(CubicWebDebugPanel)
156 +    config.add_debugtoolbar_panel(RegistryDebugPanel)
157      config.add_debugtoolbar_panel(RQLDebugPanel)
158      config.add_debugtoolbar_panel(SQLDebugPanel)