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