cubicweb/pyramid/debugtoolbar_panels.py
author Laurent Peuch <cortex@worlddomination.be>
Thu, 12 Sep 2019 05:59:10 +0200
changeset 12768 7d2c61d40fe9
parent 12766 682d0790997f
child 12776 3cbcbaead477
permissions -rw-r--r--
[debug-toolbar] add registry decisions debug panel Closes #17219866
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
12764
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    24
class CubicWebDebugPanel(DebugPanel):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    25
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    26
    CubicWeb general debug panel
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    27
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    28
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    29
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    30
    Excepted formats:
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    31
    Controller: {
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    32
        "kind": ctrlid,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    33
        "request": req,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    34
        "path": req.path,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    35
        "controller": controller,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    36
    }
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    37
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    38
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    39
    name = 'CubicWeb'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    40
    nav_title = 'CubicWeb'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    41
    title = 'CubicWeb general panel'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    42
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    43
    has_content = True
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    44
    template = 'cubicweb.pyramid:debug_toolbar_templates/cw.dbtmako'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    45
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    46
    def __init__(self, request):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    47
        self.data = {'controller': None}
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    48
        subscribe_to_debug_channel("controller", self.collect_controller)
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    49
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    50
    def collect_controller(self, controller):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    51
        self.data["controller"] = controller
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    52
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    53
    def process_response(self, response):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    54
        unsubscribe_to_debug_channel("controller", self.collect_controller)
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    55
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    56
12768
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    57
class RegistryDecisionsDebugPanel(DebugPanel):
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    58
    """
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    59
    CubicWeb registry decisions debug panel
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    60
    """
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    61
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    62
    name = 'RegistryDecisions'
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    63
    title = 'Registry Decisions'
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    64
    nav_title = 'Registry Decisions'
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    65
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    66
    has_content = True
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    67
    template = 'cubicweb.pyramid:debug_toolbar_templates/registry_decisions.dbtmako'
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    68
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    69
    def __init__(self, request):
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    70
        # clear on every new response
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    71
        self.data = {
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    72
            'registry_decisions': [],
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    73
            'vreg': None,
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    74
            'highlight': highlight_html,
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    75
            'generate_css': generate_css,
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    76
        }
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    77
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    78
        subscribe_to_debug_channel("vreg", self.collect_vreg)
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    79
        subscribe_to_debug_channel("registry_decisions", self.collect_registry_decisions)
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    80
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    81
    def collect_vreg(self, message):
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    82
        self.data["vreg"] = message["vreg"]
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    83
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    84
    def collect_registry_decisions(self, decision):
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    85
        # decision = {
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    86
        #     "all_objects": [],
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    87
        #     "end_score": int,
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    88
        #     "winners": [],
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    89
        #     "registry": obj,
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    90
        #     "args": args,
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    91
        #     "kwargs": kwargs,
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    92
        # }
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    93
        decision["key"] = None
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    94
        self.data["registry_decisions"].append(decision)
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    95
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    96
    def link_registry_to_their_key(self):
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    97
        if self.data["vreg"]:
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    98
            # use "id" here to be hashable
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
    99
            registry_to_key = {id(registry): key for key, registry in self.data["vreg"].items()}
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   100
            for decision in self.data["registry_decisions"]:
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   101
                decision["key"] = registry_to_key.get(id(decision["self"]))
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   102
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   103
    def process_response(self, response):
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   104
        unsubscribe_to_debug_channel("registry_decisions", self.collect_registry_decisions)
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   105
        unsubscribe_to_debug_channel("vreg", self.collect_vreg)
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   106
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   107
        self.link_registry_to_their_key()
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   108
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   109
12766
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   110
class RegistryDebugPanel(DebugPanel):
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   111
    """
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   112
    CubicWeb registry content and decisions debug panel
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   113
    """
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   114
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   115
    name = 'Registry'
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   116
    title = 'Registry Store'
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   117
    nav_title = 'Registry Store'
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   118
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   119
    has_content = True
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   120
    template = 'cubicweb.pyramid:debug_toolbar_templates/registry.dbtmako'
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   121
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   122
    def __init__(self, request):
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   123
        self.data = {'vreg': None}
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   124
        subscribe_to_debug_channel("vreg", self.collect_vreg)
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   125
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   126
    def collect_vreg(self, message):
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   127
        self.data["vreg"] = message["vreg"]
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   128
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   129
    def process_response(self, response):
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   130
        unsubscribe_to_debug_channel("vreg", self.collect_vreg)
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   131
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   132
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   133
class RQLDebugPanel(DebugPanel):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   134
    """
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   135
    CubicWeb RQL debug panel
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   136
    """
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   137
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   138
    """
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   139
    Excepted formats:
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   140
    SQL: {
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   141
        'rql_query_tracing_token': 'some_token',
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   142
        'args': {dict with some args},
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   143
        'rollback': False|True,
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   144
        'time': time_in_float,
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   145
        'sql':_sql_query_as_a_string,
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   146
    }
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   147
    """
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   148
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   149
    name = 'RQL'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   150
    title = 'RQL queries'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   151
    nav_title = 'RQL'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   152
    nav_subtitle_style = 'progress-bar-info'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   153
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   154
    has_content = True
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   155
    template = 'cubicweb.pyramid:debug_toolbar_templates/rql.dbtmako'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   156
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   157
    def __init__(self, request):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   158
        self.data = {
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   159
            'rql_queries': [],
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   160
            'sql_queries': [],
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   161
            'highlight': highlight_html,
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   162
            'generate_css': generate_css,
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   163
        }
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   164
        subscribe_to_debug_channel("rql", self.collect_rql_queries)
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   165
        subscribe_to_debug_channel("sql", self.collect_sql_queries)
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   166
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   167
    @property
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   168
    def nav_subtitle(self):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   169
        return '%d' % len(self.data['rql_queries'])
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   170
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   171
    def collect_rql_queries(self, rql_query):
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   172
        rql_query["generated_sql_queries"] = []
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   173
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   174
        # link sql queries to rql's one
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   175
        for sql_query in self.data["sql_queries"]:
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   176
            if sql_query["rql_query_tracing_token"] == rql_query["rql_query_tracing_token"]:
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   177
                rql_query["generated_sql_queries"].append(sql_query)
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   178
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   179
        self.data["rql_queries"].append(rql_query)
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   180
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   181
    def collect_sql_queries(self, sql_query):
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   182
        self.data["sql_queries"].append(sql_query)
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   183
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   184
    def process_response(self, response):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   185
        unsubscribe_to_debug_channel("rql", self.collect_rql_queries)
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   186
        unsubscribe_to_debug_channel("sql", self.collect_sql_queries)
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   187
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   188
12765
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   189
class SQLDebugPanel(DebugPanel):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   190
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   191
    CubicWeb SQL debug panel
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   192
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   193
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   194
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   195
    Excepted formats:
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   196
    SQL: {
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   197
        'rql_query_tracing_token': 'some_token',
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   198
        'args': {dict with some args},
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   199
        'rollback': False|True,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   200
        'time': time_in_float,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   201
        'sql':_sql_query_as_a_string,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   202
    }
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   203
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   204
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   205
    name = 'SQL'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   206
    title = 'SQL queries'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   207
    nav_title = 'SQL'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   208
    nav_subtitle_style = 'progress-bar-info'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   209
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   210
    has_content = True
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   211
    template = 'cubicweb.pyramid:debug_toolbar_templates/sql.dbtmako'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   212
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   213
    def __init__(self, request):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   214
        self.data = {
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   215
            'rql_queries': [],
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   216
            'sql_queries': [],
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   217
            'highlight': highlight_html,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   218
            'generate_css': generate_css,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   219
        }
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   220
        subscribe_to_debug_channel("rql", self.collect_rql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   221
        subscribe_to_debug_channel("sql", self.collect_sql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   222
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   223
    @property
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   224
    def nav_subtitle(self):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   225
        return len(self.data['sql_queries'])
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   226
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   227
    def collect_rql_queries(self, rql_query):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   228
        self.data["rql_queries"].append(rql_query)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   229
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   230
        # link sql queries to rql's one
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   231
        for sql_query in self.data["sql_queries"]:
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   232
            if sql_query["rql_query_tracing_token"] == rql_query["rql_query_tracing_token"]:
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   233
                sql_query["from_rql_query"] = rql_query
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   234
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   235
    def collect_sql_queries(self, sql_query):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   236
        sql_query["from_rql_query"] = None
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   237
        self.data["sql_queries"].append(sql_query)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   238
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   239
    def process_response(self, response):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   240
        unsubscribe_to_debug_channel("rql", self.collect_rql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   241
        unsubscribe_to_debug_channel("sql", self.collect_sql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   242
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   243
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   244
def includeme(config):
12764
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
   245
    config.add_debugtoolbar_panel(CubicWebDebugPanel)
12768
7d2c61d40fe9 [debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12766
diff changeset
   246
    config.add_debugtoolbar_panel(RegistryDecisionsDebugPanel)
12766
682d0790997f [debug-toolbar] add registry panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12765
diff changeset
   247
    config.add_debugtoolbar_panel(RegistryDebugPanel)
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   248
    config.add_debugtoolbar_panel(RQLDebugPanel)
12765
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   249
    config.add_debugtoolbar_panel(SQLDebugPanel)