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


Python deprecation.MiddlewareMixin方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django.utils import deprecation [as 别名]
# 或者: from django.utils.deprecation import MiddlewareMixin [as 别名]
def __init__(self, *args, **kwargs):
        # Call super first, so the MiddlewareMixin's __init__ does its thing.
        super(QueryCountMiddleware, self).__init__(*args, **kwargs)

        if settings.DEBUG:
            self.request_path = None
            self.stats = {"request": {}, "response": {}}
            self.dbs = [c.alias for c in connections.all()]
            self.queries = Counter()
            self._reset_stats()

            self._start_time = None
            self._end_time = None
            self.host = None  # The HTTP_HOST pulled from the request

            # colorizing methods
            self.white = termcolors.make_style(opts=('bold',), fg='white')
            self.red = termcolors.make_style(opts=('bold',), fg='red')
            self.yellow = termcolors.make_style(opts=('bold',), fg='yellow')
            self.green = termcolors.make_style(fg='green')

            # query type detection regex
            # TODO: make stats classification regex more robust
            self.threshold = QC_SETTINGS['THRESHOLDS'] 
开发者ID:bradmontgomery,项目名称:django-querycount,代码行数:26,代码来源:middleware.py

示例2: test_request_summary_failed_request

# 需要导入模块: from django.utils import deprecation [as 别名]
# 或者: from django.utils.deprecation import MiddlewareMixin [as 别名]
def test_request_summary_failed_request(
    admin_user, caplog, dockerflow_middleware, dockerflow_request
):
    class HostileMiddleware(MiddlewareMixin):
        def process_request(self, request):
            # simulating resetting request changes
            delattr(request, "_id")
            delattr(request, "_start_timestamp")

        def process_response(self, request, response):
            return response

    hostile_middleware = HostileMiddleware()
    response = dockerflow_middleware.process_request(dockerflow_request)
    response = hostile_middleware.process_request(dockerflow_request)
    response = hostile_middleware.process_response(dockerflow_request, response)
    dockerflow_middleware.process_response(dockerflow_request, response)
    assert len(caplog.records) == 1
    record = caplog.records[0]
    assert getattr(record, "rid", None) is None
    assert getattr(record, "t", None) is None 
开发者ID:mozilla-services,项目名称:python-dockerflow,代码行数:23,代码来源:test_django.py

示例3: process_view

# 需要导入模块: from django.utils import deprecation [as 别名]
# 或者: from django.utils.deprecation import MiddlewareMixin [as 别名]
def process_view(self, request, view_func, args, kwargs):
        assert hasattr(request, 'user')
        if not request.user.is_authenticated:
            path = request.path_info.lstrip('/')
            if not any(m.match(path) for m in EXEMPT_URLS):
                return redirect(settings.LOGIN_URL)


# class AutoLoginMiddleware(MiddlewareMixin):
#     """
#     Auto login test user.
#     Create test user if needed.
#     settings should have AUTOLOGIN_TEST_USER_FORBIDDEN_URLS
#     and AUTOLOGIN_ALWAYS_OPEN_URLS
#     MIDDLEWARE_CLASSES should have 'django.contrib.auth.middleware.AuthenticationMiddleware'.
#     TEMPLATE_CONTEXT_PROCESSORS setting should include 'django.core.context_processors.auth'.
#
#     # settings for AutoLoginMiddleware
#     # urls available for unauthorized users,
#     # otherwise login as "test_user"
#     AUTOLOGIN_ALWAYS_OPEN_URLS = [
#         reverse_lazy('account_login'),
#     ]
#     # forbidden urls for "test user" (all account/* except login/logout)
#     AUTOLOGIN_TEST_USER_FORBIDDEN_URLS = [
#         'accounts/(?!login|logout)',
#     ]
#
#     """
#     TEST_USER_FORBIDDEN_URLS = [
#         re.compile(str(expr)) for expr in settings.AUTOLOGIN_TEST_USER_FORBIDDEN_URLS]
#
#     def process_view(self, request, view_func, args, kwargs):
#
#         if config.auto_login:
#
#             path = request.path_info
#             if path in settings.AUTOLOGIN_ALWAYS_OPEN_URLS:
#                 return
#
#             if not request.user.is_authenticated:
#                 get_test_user()
#                 user = authenticate(username='test_user', password='test_user')
#                 request.user = user
#                 login(request, user)
#
#             if request.user.username == 'test_user':
#                 if any(m.search(path) for m in self.TEST_USER_FORBIDDEN_URLS):
#                     return redirect(reverse_lazy('home')) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:51,代码来源:middleware.py


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