Exemple #1
0
    def render(self, value, system_values, request=None):
        renderer = self.renderer
        if system_values is None:
            system_values = {
                "view": None,
                "renderer_name": self.name,  # b/c
                "renderer_info": self,
                "context": getattr(request, "context", None),
                "request": request,
                "req": request,
            }

        system_values = BeforeRender(system_values, value)

        registry = self.registry
        globals_factory = registry.queryUtility(IRendererGlobalsFactory)

        if globals_factory is not None:
            renderer_globals = globals_factory(system_values)
            if renderer_globals:
                system_values.update(renderer_globals)

        registry.notify(system_values)

        result = renderer(value, system_values)
        return result
Exemple #2
0
    def render(self, value, system_values, request=None):
        renderer = self.renderer
        if system_values is None:
            system_values = {
                'view':None,
                'renderer_name':self.name, # b/c
                'renderer_info':self,
                'context':getattr(request, 'context', None),
                'request':request,
                'req':request,
                }

        system_values = BeforeRender(system_values, value)

        registry = self.registry
        globals_factory = registry.queryUtility(IRendererGlobalsFactory)

        if globals_factory is not None:
            renderer_globals = globals_factory(system_values)
            if renderer_globals:
                system_values.update(renderer_globals)

        registry.notify(system_values)

        result = renderer(value, system_values)
        return result
Exemple #3
0
    def render(self, value, system_values, request=None):
        renderer = self.renderer
        if system_values is None:
            system_values = {
                'view': None,
                'renderer_name': self.name,  # b/c
                'renderer_info': self,
                'context': getattr(request, 'context', None),
                'request': request,
                'req': request,
            }

        system_values = BeforeRender(system_values, value)

        registry = self.registry
        globals_factory = registry.queryUtility(IRendererGlobalsFactory)

        if globals_factory is not None:
            renderer_globals = globals_factory(system_values)
            if renderer_globals:
                system_values.update(renderer_globals)

        registry.notify(system_values)

        result = renderer(value, system_values)
        return result
 def _generate_event(rendering_val=None, registry=None):
     if rendering_val is None:
         rendering_val = {}
     event = BeforeRender({}, rendering_val=rendering_val)
     event.rendering_val = rendering_val
     event['request'] = testing.DummyRequest()
     if registry is None:
         registry = Mock()
         registry.settings = {}
     event['request'].registry = registry
     return event
def test_i18n_before_render_and_request(request_i18n):
    """Test if appropriate methods are being added to both context and request."""
    request_i18n.registry.notify(NewRequest(request_i18n))
    before_render_event = BeforeRender({'request': request_i18n}, {})
    request_i18n.registry.notify(before_render_event)
    assert 'localizer' in before_render_event
    assert '_' in before_render_event
def on_before_render_event(config_fixture):
    app = config_fixture.make_wsgi_app()
    environ = {}
    ctx = app.request_context(environ)
    request = ctx.begin()
    event = MagicMock(wraps=BeforeRender(request), name='before_render_event')
    # type-wide property mock, okay for request of course
    type(event).request = PropertyMock(return_value=request)
    return event
Exemple #7
0
    def test_prerender(self):
        from pyramid.events import BeforeRender

        self.config.testing_add_subscriber(BeforeRender)
        self.attach_analytics()
        e = BeforeRender({'request': self.request})
        self.request.registry.notify(e)

        self.assertItemsEqual(['api_token', 'tracking', 'tracking_json'],
                              e['analytics'].keys())
Exemple #8
0
    def render(self, value, system_values, request=None):
        renderer = self.renderer
        if system_values is None:
            system_values = {
                'view':None,
                'renderer_name':self.name, # b/c
                'renderer_info':self,
                'context':getattr(request, 'context', None),
                'request':request,
                'req':request,
                }

        system_values = BeforeRender(system_values, value)

        registry = self.registry
        registry.notify(system_values)

        result = renderer(value, system_values)
        return result
Exemple #9
0
 def _makeOne(self, system):
     from pyramid.events import BeforeRender
     return BeforeRender(system)
def test_fake_before_render_norequest(request_fake):
    """Test if appropriate methods are being added to render context."""
    before_render_event = BeforeRender({'request': request_fake}, {})
    request_fake.registry.notify(before_render_event)
    assert '_' in before_render_event
def test_fake_before_render(request_fake):
    """Test if appropriate methods are being added to both context and request."""
    request_fake.registry.notify(NewRequest(request_fake))
    before_render_event = BeforeRender({"request": request_fake}, {})
    request_fake.registry.notify(before_render_event)
    assert "_" in before_render_event
def test_i18n_before_render(request_i18n):
    """Test if appropriate methods are being added to render context."""
    before_render_event = BeforeRender({"request": request_i18n}, {})
    request_i18n.registry.notify(before_render_event)
    assert "localizer" in before_render_event
    assert "_" in before_render_event