Example #1
0
    def test_layout_simple_chain_multi_level(self):
        class View(view.View):
            def render(self):
                return 'View: test'

        class LayoutTest(view.Layout):
            def render(self, content):
                return '<div>%s</div>'%content

        class LayoutPage(view.Layout):
            def render(self, content):
                return '<html>%s</html>'%content

        view.registerLayout('', klass=LayoutPage, context=Root, parent=None)
        view.registerLayout('test', klass=LayoutTest, parent='.')
        self._init_memphis()

        root = Root()
        context = Context(root)
        v = View(context, self.request)

        renderer = SimpleRenderer('test')
        res = renderer(context, self.request, viewMapper(View,'render'))

        self.assertTrue('<html><div>View: test</div></html>' in res.body)

        layout = queryLayout(self.request, v.context, 'test')
        self.assertTrue(isinstance(layout, LayoutTest))

        rootlayout = queryLayout(self.request, context, '')
        self.assertTrue(isinstance(rootlayout, LayoutPage))

        rootlayout = queryLayout(self.request, root, '')
        self.assertTrue(isinstance(rootlayout, LayoutPage))
Example #2
0
    def __call__(self, context, request, factory=None):
        response = request.response
        response.content_type = self.content_type

        if not factory:
            factory = self.factory

        view, params = factory(context, request)

        kwargs = {'view': view,
                  'context': context,
                  'request': request,
                  'format': format}
        if type(params) is dict:
            kwargs.update(params)

        result = self.template(**kwargs)

        if self.layout is not None:
            layout = queryLayout(request, context, self.layout)
            if layout is not None:
                result = layout(result, view=view)

        if type(result) is unicode:
            response.unicode_body = result
        else:
            response.body = result

        return response
Example #3
0
    def test_layout_simple_view_without_template(self):
        class View(view.View):
            def render(self):
                return 'test'

        view.registerLayout('test')
        self._init_memphis()

        v = View(Context(), self.request)

        layout = queryLayout(self.request, v.context, 'test')
        layout.update()
        self.assertTrue('test' == layout.render(v.render()))
Example #4
0
    def test_layout_simple_view(self):
        class View(view.View):
            def __call__(self):
                return 'View: test'
        class Layout(view.Layout):
            def render(self, rendered):
                return '<html>%s</html>'%rendered

        view.registerLayout('test', klass=Layout)
        self._init_memphis()

        v = View(Context(), self.request)

        # find layout for view
        layout = queryLayout(self.request, v.context, 'test')
        self.assertTrue(isinstance(layout, Layout))

        layout.update()
        self.assertEqual(layout.render(v()),
                         '<html>View: test</html>')
Example #5
0
    def test_layout_simple_declarative(self):
        global Layout

        class View(view.View):
            def __call__(self):
                return 'View: test'
        class Layout(view.Layout):
            view.layout('test', context=Context)
            def render(self, rendered):
                return '<html>%s</html>'%rendered

        self._init_memphis()

        v = View(Context(), self.request)

        layout = queryLayout(self.request, v.context, 'test')
        self.assertTrue(isinstance(layout, Layout))

        layout.update()
        self.assertEqual(layout.render(v()),
                         '<html>View: test</html>')
Example #6
0
    def __call__(self, context, request, factory=None):
        response = request.response
        response.content_type = self.content_type

        if not factory:
            factory = self.factory

        view, result = factory(context, request)
        if result is response:
            return response

        if self.layout is not None:
            layout = queryLayout(request, context, self.layout)
            if layout is not None:
                result = layout(result, view=view)

        if type(result) is unicode:
            response.unicode_body = result
        else:
            response.body = result

        return response
Example #7
0
    def test_layout_simple_multilevel(self):
        class View(view.View):
            def __call__(self):
                return 'View: test'
        class Layout(view.Layout):
            def render(self, content):
                return '<html>%s</html>'%content

        view.registerLayout('', klass=Layout, context=Root)
        self._init_memphis()

        root = Root()
        context = Context(root)
        v = View(context, self.request)

        # find layout for view
        layout = queryLayout(self.request, context, '')
        self.assertTrue(isinstance(layout, Layout))

        renderer = SimpleRenderer(layout='')
        res = renderer(context, self.request, viewMapper(View))

        self.assertTrue('<html>View: test</html>' in res.body)
Example #8
0
 def test_layout_simple_notfound(self):
     v = view.View(Context(Context()), self.request)
     layout = queryLayout(self.request, v.context, 'test')
     self.assertTrue(layout is None)