rollbar/contrib/pyramid/__init__.py
def patch_debugtoolbar(settings):
    """
    Patches the pyramid_debugtoolbar (if installed) to display a link to the related rollbar item.
    """
    try:
        from pyramid_debugtoolbar import tbtools
    except ImportError:
        return

    rollbar_web_base = settings.get('rollbar.web_base', DEFAULT_WEB_BASE)
    if rollbar_web_base.endswith('/'):
        rollbar_web_base = rollbar_web_base[:-1]

    def insert_rollbar_console(request, html):
        # insert after the closing </h1>
        item_uuid = request.environ.get('rollbar.uuid')
        if not item_uuid:
            return html

        url = '%s/item/uuid/?uuid=%s' % (rollbar_web_base, item_uuid)
        link = '<a style="color:white;" href="%s">View in Rollbar</a>' % url
        new_data = "<h2>Rollbar: %s</h2>" % link
        insertion_marker = "</h1>"
        replacement = insertion_marker + new_data
        return html.replace(insertion_marker, replacement, 1)

    # patch tbtools.Traceback.render_full
    old_render_full = tbtools.Traceback.render_full

    def new_render_full(self, request, *args, **kw):
        html = old_render_full(self, request, *args, **kw)
        return insert_rollbar_console(request, html)

    tbtools.Traceback.render_full = new_render_full
def patch_debugtoolbar(settings):
    """
    Patches the pyramid_debugtoolbar (if installed) to display a link to the related rollbar item.
    """
    try:
        from pyramid_debugtoolbar import tbtools
    except ImportError:
        return

    rollbar_web_base = settings.get('rollbar.web_base', DEFAULT_WEB_BASE)
    if rollbar_web_base.endswith('/'):
        rollbar_web_base = rollbar_web_base[:-1]

    def insert_rollbar_console(request, html):
        # insert after the closing </h1>
        item_uuid = request.environ.get('rollbar.uuid')
        if not item_uuid:
            return html

        url = '%s/item/uuid/?uuid=%s' % (rollbar_web_base, item_uuid)
        link = '<a style="color:white;" href="%s">View in Rollbar</a>' % url
        new_data = "<h2>Rollbar: %s</h2>" % link
        insertion_marker = "</h1>"
        replacement = insertion_marker + new_data
        return html.replace(insertion_marker, replacement, 1)

    # patch tbtools.Traceback.render_full
    old_render_full = tbtools.Traceback.render_full

    def new_render_full(self, request, *args, **kw):
        html = old_render_full(self, request, *args, **kw)
        return insert_rollbar_console(request, html)

    tbtools.Traceback.render_full = new_render_full
def patch_debugtoolbar ( settings ) : try : from pyramid_debugtoolbar import tbtools except ImportError : return rollbar_web_base = settings . get ( 'rollbar.web_base' , DEFAULT_WEB_BASE ) if rollbar_web_base . endswith ( '/' ) : rollbar_web_base = rollbar_web_base [ : - 1 ] def insert_rollbar_console ( request , html ) : # insert after the closing </h1> item_uuid = request . environ . get ( 'rollbar.uuid' ) if not item_uuid : return html url = '%s/item/uuid/?uuid=%s' % ( rollbar_web_base , item_uuid ) link = '<a style="color:white;" href="%s">View in Rollbar</a>' % url new_data = "<h2>Rollbar: %s</h2>" % link insertion_marker = "</h1>" replacement = insertion_marker + new_data return html . replace ( insertion_marker , replacement , 1 ) # patch tbtools.Traceback.render_full old_render_full = tbtools . Traceback . render_full def new_render_full ( self , request , * args , * * kw ) : html = old_render_full ( self , request , * args , * * kw ) return insert_rollbar_console ( request , html ) tbtools . Traceback . render_full = new_render_full
Patches the pyramid_debugtoolbar (if installed) to display a link to the related rollbar item.
Patches the pyramid_debugtoolbar ( if installed ) to display a link to the related rollbar item .