本文整理汇总了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
示例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
示例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())
示例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)
示例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
示例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)
示例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, {})
示例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, {})