|
1 # copyright 2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 |
|
19 from pyramid_debugtoolbar.panels import DebugPanel |
|
20 from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel |
|
21 from cubicweb.misc.source_highlight import highlight_html, generate_css |
|
22 |
|
23 |
|
24 class RQLDebugPanel(DebugPanel): |
|
25 """ |
|
26 CubicWeb RQL debug panel |
|
27 """ |
|
28 name = 'RQL' |
|
29 title = 'RQL queries' |
|
30 nav_title = 'RQL' |
|
31 nav_subtitle_style = 'progress-bar-info' |
|
32 |
|
33 has_content = True |
|
34 template = 'cubicweb.pyramid:debug_toolbar_templates/rql.dbtmako' |
|
35 |
|
36 def __init__(self, request): |
|
37 self.data = { |
|
38 'rql_queries': [], |
|
39 'highlight': highlight_html, |
|
40 'generate_css': generate_css, |
|
41 } |
|
42 subscribe_to_debug_channel("rql", self.collect_rql_queries) |
|
43 |
|
44 @property |
|
45 def nav_subtitle(self): |
|
46 return '%d' % len(self.data['rql_queries']) |
|
47 |
|
48 def collect_rql_queries(self, rql_query): |
|
49 self.data["rql_queries"].append(rql_query) |
|
50 |
|
51 def process_response(self, response): |
|
52 unsubscribe_to_debug_channel("rql", self.collect_rql_queries) |
|
53 |
|
54 |
|
55 def includeme(config): |
|
56 config.add_debugtoolbar_panel(RQLDebugPanel) |