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


Python toolbar.ToolbarMiddleware类代码示例

本文整理汇总了Python中cms.middleware.toolbar.ToolbarMiddleware的典型用法代码示例。如果您正苦于以下问题:Python ToolbarMiddleware类的具体用法?Python ToolbarMiddleware怎么用?Python ToolbarMiddleware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: _prepare_request

 def _prepare_request(self, request, page, user, lang, use_middlewares, use_toolbar=False):
     request.current_page = SimpleLazyObject(lambda: page)
     if not user:
         if self._login_context:
             user = self._login_context.user
         else:
             user = AnonymousUser()
     request.user = user
     request.session = {}
     request.cookies = SimpleCookie()
     request.errors = StringIO()
     request.LANGUAGE_CODE = lang
     # Let's use middleware in case requested, otherwise just use CMS toolbar if needed
     if use_middlewares:
         handler = BaseHandler()
         handler.load_middleware()
         for middleware_method in handler._request_middleware:
             if middleware_method(request):
                 raise Exception(u'Couldn\'t create request mock object -'
                                 u'request middleware returned a response')
     elif use_toolbar:
         from cms.middleware.toolbar import ToolbarMiddleware
         mid = ToolbarMiddleware()
         mid.process_request(request)
     return request
开发者ID:cyberstar,项目名称:djangocms-helper,代码行数:25,代码来源:base_test.py

示例2: get_page_request

    def get_page_request(self, page, user, path=None, edit=False, lang='en'):
        """
        Createds a GET request for the given page suitable for use the
        django CMS toolbar

        :param page: current page object
        :param user: current user
        :param path: path (if different from the current page path)
        :param edit: editing mode
        :param lang: request language
        :return: request
        """
        from cms.middleware.toolbar import ToolbarMiddleware
        path = path or page and page.get_absolute_url()
        if edit:
            path += '?edit'
        request = RequestFactory().get(path)
        request.session = {}
        request.user = user
        request.LANGUAGE_CODE = lang
        if edit:
            request.GET = {'edit': None}
        else:
            request.GET = {'edit_off': None}
        request.current_page = page
        mid = ToolbarMiddleware()
        mid.process_request(request)
        return request
开发者ID:thoreg,项目名称:djangocms-helper,代码行数:28,代码来源:base_test.py

示例3: test_get_page_by_pk_arg_edit_mode

 def test_get_page_by_pk_arg_edit_mode(self):
     control = self._getfirst()
     request = self.get_request('/')
     request.GET = {"edit": ''}
     user = self._create_user("admin", True, True)
     request.current_page = control
     request.user = user
     middleware = ToolbarMiddleware()
     middleware.process_request(request)
     page = _get_page_by_untyped_arg(control.pk, request, 1)
     self.assertEqual(page, control.publisher_draft)
开发者ID:1oscar,项目名称:django-cms,代码行数:11,代码来源:templatetags.py

示例4: test_get_page_by_pk_arg_edit_mode

 def test_get_page_by_pk_arg_edit_mode(self):
     control = self._getfirst()
     request = self.get_request('/')
     request.GET = {"edit": ''}
     user = User(username="admin", password="admin", is_superuser=True, is_staff=True, is_active=True)
     user.save()
     request.current_page = control
     request.user = user
     middleware = ToolbarMiddleware()
     middleware.process_request(request)
     page = _get_page_by_untyped_arg(control.pk, request, 1)
     self.assertEqual(page, control.publisher_draft)
开发者ID:conrado,项目名称:django-cms,代码行数:12,代码来源:templatetags.py

示例5: get_page_request

 def get_page_request(self, page, user, path=None, edit=False, lang_code="en"):
     path = path or page and page.get_absolute_url()
     if edit:
         path += "?edit"
     request = RequestFactory().get(path)
     request.session = {}
     request.user = user
     request.LANGUAGE_CODE = lang_code
     if edit:
         request.GET = {"edit": None}
     else:
         request.GET = {"edit_off": None}
     request.current_page = page
     mid = ToolbarMiddleware()
     mid.process_request(request)
     return request
开发者ID:conrado,项目名称:django-cms,代码行数:16,代码来源:toolbar.py

示例6: get_page_request

def get_page_request(page, user=None, path=None, edit=False, language='en'):
    path = path or page and page.get_absolute_url()
    if edit:
        path += '?edit'
    request = RequestFactory().get(path)
    request.session = {}
    request.user = user or AnonymousUser()
    request.LANGUAGE_CODE = language
    if edit:
        request.GET = {'edit': None}
    else:
        request.GET = {'edit_off': None}
    request.current_page = page
    mid = ToolbarMiddleware()
    mid.process_request(request)
    return request
开发者ID:victorevector,项目名称:aldryn-events,代码行数:16,代码来源:base.py

示例7: get_page_request

 def get_page_request(self, page, user, path=None, edit=False, lang_code='en'):
     from cms.middleware.toolbar import ToolbarMiddleware
     path = path or page and page.get_absolute_url(lang_code)
     if edit:
         path += '?edit'
     request = RequestFactory().get(path)
     request.session = {}
     request.user = user
     request.LANGUAGE_CODE = lang_code
     if edit:
         request.GET = {'edit': None}
     else:
         request.GET = {'edit_off': None}
     request.current_page = page
     mid = ToolbarMiddleware()
     mid.process_request(request)
     return request
开发者ID:CptLemming,项目名称:djangocms-page-meta,代码行数:17,代码来源:__init__.py

示例8: get_page_request

 def get_page_request(self, page, user, path=None, edit=False, lang_code='en', disable=False):
     path = path or page and page.get_absolute_url()
     if edit:
         path += '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
     request = RequestFactory().get(path)
     request.session = {}
     request.user = user
     request.LANGUAGE_CODE = lang_code
     if edit:
         request.GET = {'edit': None}
     else:
         request.GET = {'edit_off': None}
     if disable:
         request.GET[get_cms_setting('CMS_TOOLBAR_URL__DISABLE')] = None
     request.current_page = page
     mid = ToolbarMiddleware()
     mid.process_request(request)
     if hasattr(request, 'toolbar'):
         request.toolbar.populate()
     return request
开发者ID:AaronJaramillo,项目名称:shopDPM,代码行数:20,代码来源:test_no_i18n.py

示例9: _prepare_request

    def _prepare_request(self, request, page, user, lang, use_middlewares, use_toolbar=False,
                         secure=False):
        from django.contrib.auth.models import AnonymousUser
        from importlib import import_module

        engine = import_module(settings.SESSION_ENGINE)

        request.current_page = SimpleLazyObject(lambda: page)
        if not user:
            if self._login_context:
                user = self._login_context.user
            else:
                user = AnonymousUser()
        if callable(user.is_authenticated):
            authenticated = user.is_authenticated()
        else:
            authenticated = user.is_authenticated
        if authenticated:
            session_key = user._meta.pk.value_to_string(user)
        else:
            session_key = 'session_key'

        request.user = user
        request._cached_user = user
        request.session = engine.SessionStore(session_key)
        if secure:
            request.environ['SERVER_PORT'] = str('443')
            request.environ['wsgi.url_scheme'] = str('https')
        request.cookies = SimpleCookie()
        request.errors = StringIO()
        request.LANGUAGE_CODE = lang
        if request.method == 'POST':
            request._dont_enforce_csrf_checks = True
        # Let's use middleware in case requested, otherwise just use CMS toolbar if needed
        if use_middlewares:
            self._apply_middlewares(request)
        elif use_toolbar:
            from cms.middleware.toolbar import ToolbarMiddleware
            mid = ToolbarMiddleware()
            mid.process_request(request)
        return request
开发者ID:nephila,项目名称:djangocms-helper,代码行数:41,代码来源:base_test.py

示例10: test_02_toolbar_middleware_show_toolbar

 def test_02_toolbar_middleware_show_toolbar(self):
     class Mock:
         pass
     
     middle = ToolbarMiddleware()
     
     request = Mock()
     response = Mock()
     
     # if request.is_ajax(): 
     setattr(request,'is_ajax', lambda : True)
     result = middle.show_toolbar(request, response)
     self.assertEqual(result, False)
     
     #if response.status_code != 200: 
     setattr(request,'is_ajax', lambda : False)
     setattr(response, 'status_code', 201)
     result = middle.show_toolbar(request, response)
     self.assertEqual(result, False)
     setattr(response, 'status_code', 200)
     
     #if not response['Content-Type'].split(';')[0] in HTML_TYPES:
     setattr(response, '__getitem__', lambda _: 'Whatever')
     result = middle.show_toolbar(request, response)
     self.assertEqual(result, False)
     setattr(response, '__getitem__', lambda _: 'text/html')
     
     #if is_media_request(request):
     setattr(request, 'path', '/media/')
     result = middle.show_toolbar(request, response)
     self.assertEqual(result, False)
     
     setattr(request, 'path', '')
     
     #if "edit" in request.GET: 
     setattr(request, 'GET', ["edit"])
     result = middle.show_toolbar(request, response)
     self.assertEqual(result, True)
     setattr(request, 'GET', [])
     
     #if not hasattr(request, "user"):
     result = middle.show_toolbar(request, response)
     self.assertEqual(result, False)
     setattr(request, 'user', 'test-user')
开发者ID:42,项目名称:django-cms,代码行数:44,代码来源:middleware.py


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