示例#1
0
    def test_layout_chain_same_layer_id_on_different_levels(self):
        class View(view.View):
            def render(self):
                return 'View: test'

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

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

        view.registerLayout('', klass=Layout1, context=Context, parent='.')
        view.registerLayout('', klass=Layout2, context=Root, parent=None)
        self._init_memphis()

        root = Root()
        context1 = Context2(root)
        context2 = Context(context1)

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

        self.assertTrue('<html><div>View: test</div></html>' in res.body)
示例#2
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))
示例#3
0
    def test_layout_chain_parent_notfound(self):
        class View(view.View):
            def __call__(self):
                return 'View: test'

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

        view.registerLayout('', klass=Layout, context=Context, parent='page')
        self._init_memphis()

        root = Root()
        context = Context(root)

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

        self.assertTrue('<div>View: test</div>' in res.body)
示例#4
0
    def test_layout_simple_view_with_template(self):
        class View(view.View):
            def __call__(self):
                return 'View: test'

        fn = os.path.join(self.dir, 'test.pt')
        tmpl = open(fn, 'wb')
        tmpl.write('<html>${content}</html>')
        tmpl.close()

        view.registerLayout('test', template = view.template(fn))
        self._init_memphis()

        renderer = SimpleRenderer(layout='test')

        context = Context()
        res = renderer(context, self.request, viewMapper(View))

        self.assertTrue('<html>View: test</html>' in res.body)
示例#5
0
    def test_layout_simple_chain_one_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, parent=None)
        view.registerLayout('test', klass=LayoutTest, parent='.')
        self._init_memphis()

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

        self.assertTrue('<html><div>View: test</div></html>' in res.body)
示例#6
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)