Ejemplo n.º 1
0
def add_request_attributes(event):
    """
        Add usefull tools to the request object
        that may be used inside the views
    """
    request = event.request
    request.translate = translate
    request.actionmenu = ActionMenu()
    request.popups = {}
Ejemplo n.º 2
0
    def func(
        params=None,
        cookies=None,
        post=None,
        current_route_name=None,
        current_route_path=None,
        context=None,
    ):
        post = post or {}
        if params is not None:
            params.update(post)
        else:
            params = post
        cookies = cookies or {}
        def_csrf = 'default_csrf'
        if u'csrf_token' not in post.keys():
            post.update({'csrf_token': def_csrf})
        pyramid_request.params = params
        pyramid_request.POST = post
        pyramid_request.json_body = post
        pyramid_request.cookies = cookies
        pyramid_request.session = BeakerSessionFactoryConfig()(pyramid_request)
        pyramid_request.config = {}
        pyramid_request.registry = config.registry
        csrf_token = Mock()
        csrf_token.return_value = def_csrf
        pyramid_request.session.get_csrf_token = csrf_token
        pyramid_request.actionmenu = ActionMenu()
        pyramid_request.navigation = Navigation()
        pyramid_request.is_popup = False

        if current_route_path:
            if not current_route_name:
                current_route_name = current_route_path

            route = DummyRoute(name=current_route_name,
                               result=current_route_path)
            mapper = DummyRouteContext(route=route)
            pyramid_request.matched_dict = {}
            pyramid_request.matched_route = route
            pyramid_request.registry.registerUtility(mapper, IRoutesMapper)

        if context:
            from pyramid_layout.layout import LayoutManager
            pyramid_request.context = context
            pyramid_request.layout_manager = LayoutManager(
                context, pyramid_request)

        return pyramid_request
Ejemplo n.º 3
0
def add_request_attributes(event):
    """
        Add usefull tools to the request object
        that may be used inside the views
    """
    request = event.request
    request.translate = translate
    # Old stuff will be deprecated with the time
    request.actionmenu = ActionMenu()
    # Use this one instead
    request.navigation = Navigation()
    request.popups = {}
    if request.params.get('popup', "") != "":
        logger.info("Relative window is a popup")
        request.is_popup = True
    else:
        request.is_popup = False
Ejemplo n.º 4
0
 def func(params=None, cookies=None, post=None):
     params = params or {}
     post = post or {}
     params.update(post)
     cookies = cookies or {}
     def_csrf = 'default_csrf'
     if not  u'csrf_token' in post.keys():
         post.update({'csrf_token': def_csrf})
     pyramid_request.params = params
     pyramid_request.POST = post
     pyramid_request.cookies = cookies
     pyramid_request.session = BeakerSessionFactoryConfig()(pyramid_request)
     pyramid_request.config = {}
     csrf_token = Mock()
     csrf_token.return_value = def_csrf
     pyramid_request.session.get_csrf_token = csrf_token
     pyramid_request.actionmenu = ActionMenu()
     return pyramid_request