50 def collect_controller(self, controller): |
50 def collect_controller(self, controller): |
51 self.data["controller"] = controller |
51 self.data["controller"] = controller |
52 |
52 |
53 def process_response(self, response): |
53 def process_response(self, response): |
54 unsubscribe_to_debug_channel("controller", self.collect_controller) |
54 unsubscribe_to_debug_channel("controller", self.collect_controller) |
|
55 |
|
56 |
|
57 class RegistryDecisionsDebugPanel(DebugPanel): |
|
58 """ |
|
59 CubicWeb registry decisions debug panel |
|
60 """ |
|
61 |
|
62 name = 'RegistryDecisions' |
|
63 title = 'Registry Decisions' |
|
64 nav_title = 'Registry Decisions' |
|
65 |
|
66 has_content = True |
|
67 template = 'cubicweb.pyramid:debug_toolbar_templates/registry_decisions.dbtmako' |
|
68 |
|
69 def __init__(self, request): |
|
70 # clear on every new response |
|
71 self.data = { |
|
72 'registry_decisions': [], |
|
73 'vreg': None, |
|
74 'highlight': highlight_html, |
|
75 'generate_css': generate_css, |
|
76 } |
|
77 |
|
78 subscribe_to_debug_channel("vreg", self.collect_vreg) |
|
79 subscribe_to_debug_channel("registry_decisions", self.collect_registry_decisions) |
|
80 |
|
81 def collect_vreg(self, message): |
|
82 self.data["vreg"] = message["vreg"] |
|
83 |
|
84 def collect_registry_decisions(self, decision): |
|
85 # decision = { |
|
86 # "all_objects": [], |
|
87 # "end_score": int, |
|
88 # "winners": [], |
|
89 # "registry": obj, |
|
90 # "args": args, |
|
91 # "kwargs": kwargs, |
|
92 # } |
|
93 decision["key"] = None |
|
94 self.data["registry_decisions"].append(decision) |
|
95 |
|
96 def link_registry_to_their_key(self): |
|
97 if self.data["vreg"]: |
|
98 # use "id" here to be hashable |
|
99 registry_to_key = {id(registry): key for key, registry in self.data["vreg"].items()} |
|
100 for decision in self.data["registry_decisions"]: |
|
101 decision["key"] = registry_to_key.get(id(decision["self"])) |
|
102 |
|
103 def process_response(self, response): |
|
104 unsubscribe_to_debug_channel("registry_decisions", self.collect_registry_decisions) |
|
105 unsubscribe_to_debug_channel("vreg", self.collect_vreg) |
|
106 |
|
107 self.link_registry_to_their_key() |
55 |
108 |
56 |
109 |
57 class RegistryDebugPanel(DebugPanel): |
110 class RegistryDebugPanel(DebugPanel): |
58 """ |
111 """ |
59 CubicWeb registry content and decisions debug panel |
112 CubicWeb registry content and decisions debug panel |
188 unsubscribe_to_debug_channel("sql", self.collect_sql_queries) |
241 unsubscribe_to_debug_channel("sql", self.collect_sql_queries) |
189 |
242 |
190 |
243 |
191 def includeme(config): |
244 def includeme(config): |
192 config.add_debugtoolbar_panel(CubicWebDebugPanel) |
245 config.add_debugtoolbar_panel(CubicWebDebugPanel) |
|
246 config.add_debugtoolbar_panel(RegistryDecisionsDebugPanel) |
193 config.add_debugtoolbar_panel(RegistryDebugPanel) |
247 config.add_debugtoolbar_panel(RegistryDebugPanel) |
194 config.add_debugtoolbar_panel(RQLDebugPanel) |
248 config.add_debugtoolbar_panel(RQLDebugPanel) |
195 config.add_debugtoolbar_panel(SQLDebugPanel) |
249 config.add_debugtoolbar_panel(SQLDebugPanel) |