当前位置: 首页>>代码示例>>Python>>正文


Python DebugToolbarMiddleware.get_current方法代码示例

本文整理汇总了Python中debug_toolbar.middleware.DebugToolbarMiddleware.get_current方法的典型用法代码示例。如果您正苦于以下问题:Python DebugToolbarMiddleware.get_current方法的具体用法?Python DebugToolbarMiddleware.get_current怎么用?Python DebugToolbarMiddleware.get_current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在debug_toolbar.middleware.DebugToolbarMiddleware的用法示例。


在下文中一共展示了DebugToolbarMiddleware.get_current方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: record_stats

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
 def record_stats(self, stats):
     toolbar = DebugToolbarMiddleware.get_current()
     panel_stats = toolbar.stats.get(self.slug)
     if panel_stats:
         panel_stats.update(stats)
     else:
         toolbar.stats[self.slug] = stats
开发者ID:2flcastro,项目名称:ka-lite,代码行数:9,代码来源:__init__.py

示例2: execute_command

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
def execute_command(func,self,*args,**options):

    command = args[0]
    start = datetime.now()
    result = func(self,*args,**options)

    stop = datetime.now()
    duration = ms_from_timedelta(stop - start)

    #TODO find more better way to get the calling func info
    calframe = _get_func_info()

    params = {
        'func':calframe[4][3],
        'func_path':"{}:{}".format(calframe[4][1],calframe[4][2]),
        'command':command,
        'result':result,
        'start_time':start,
        'stop_time':stop,
        'duration':duration,
        'is_slow':None,

    }

    #TODO more better way to loggging?
    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return result
    logger = djdt.get_panel(RedisDebugPanel)
    logger.record(**params)

    return result
开发者ID:shootstar,项目名称:redis_logger,代码行数:34,代码来源:redis_logger.py

示例3: cursor

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
def cursor(func, self):
    result = func(self)

    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return result

    return CursorWrapper(result, self, logger=_logger())
开发者ID:originell,项目名称:django-debug-toolbar-template-timings,代码行数:10,代码来源:TemplateTimings.py

示例4: cursor

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
def cursor(func, self):
    result = func(self)

    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return result
    logger = djdt.get_panel(SQLDebugPanel)
    
    return CursorWrapper(result, self, logger=logger)
开发者ID:Sylvestre67,项目名称:django-debug-toolbar,代码行数:11,代码来源:sql.py

示例5: record_stats

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
 def record_stats(self, stats):
     # import locally to work around recursive imports
     from debug_toolbar.middleware import DebugToolbarMiddleware
     toolbar = DebugToolbarMiddleware.get_current()
     panel_stats = toolbar.stats.get(self.slug)
     if panel_stats:
         panel_stats.update(stats)
     else:
         toolbar.stats[self.slug] = stats
开发者ID:tschellenbach,项目名称:django-debug-toolbar,代码行数:11,代码来源:__init__.py

示例6: record

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
def record(func, *args, **kwargs):
    djdt = DebugToolbarMiddleware.get_current()
    if not djdt:
        return func(*args, **kwargs)

    panel = djdt.get_panel(BasePanel)

    # Get stacktrace
    if ENABLE_STACKTRACES:
        stacktrace = tidy_stacktrace(reversed(get_stack()))
    else:
        stacktrace = []

    # Get template info
    template_info = None
    cur_frame = sys._getframe().f_back
    try:
        while cur_frame is not None:
            if cur_frame.f_code.co_name == 'render':
                node = cur_frame.f_locals['self']
                if isinstance(node, Node):
                    template_info = get_template_info(node.source)
                    break
            cur_frame = cur_frame.f_back
    except:
        pass
    del cur_frame

    # Find args
    cache_args = None
    # first arg is self, do we have another
    if len(args) > 1:
        cache_args = args[1]
        # is it a dictionary (most likely multi)
        if isinstance(cache_args, dict):
            # just use it's keys
            cache_args = cache_args.keys()

    # the clock starts now
    start = datetime.now()
    try:
        return func(*args, **kwargs)
    finally:
        # the clock stops now
        duration = ms_from_timedelta(datetime.now() - start)
        call = {
            'function': func.__name__,
            'args': cache_args,
            'duration': duration,
            'stacktrace': stacktrace,
            'template_info': template_info,
        }
        panel.record(**call)
开发者ID:Gagnavarslan,项目名称:django-debug-panel-memcache,代码行数:55,代码来源:__init__.py

示例7: get_stats

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
 def get_stats(self):
     # import locally to work around recursive imports
     from debug_toolbar.middleware import DebugToolbarMiddleware
     toolbar = DebugToolbarMiddleware.get_current()
     return toolbar.stats.get(self.slug, {})
开发者ID:tschellenbach,项目名称:django-debug-toolbar,代码行数:7,代码来源:__init__.py

示例8: get_stats

# 需要导入模块: from debug_toolbar.middleware import DebugToolbarMiddleware [as 别名]
# 或者: from debug_toolbar.middleware.DebugToolbarMiddleware import get_current [as 别名]
 def get_stats(self):
     toolbar = DebugToolbarMiddleware.get_current()
     return toolbar.stats.get(self.slug, {})
开发者ID:2flcastro,项目名称:ka-lite,代码行数:5,代码来源:__init__.py


注:本文中的debug_toolbar.middleware.DebugToolbarMiddleware.get_current方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。