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