Beispiel #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)
Beispiel #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))
Beispiel #3
0
    def test_layout_register_custom_class(self):
        class MyLayout(view.Layout):
            pass

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

        layout = config.registry.getMultiAdapter(
            (object(), self.request), view.ILayout, 'test')

        self.assertTrue(isinstance(layout, MyLayout))
Beispiel #4
0
    def test_layout_register_custom_class_reuse(self):
        # can't reuse same class
        class MyLayout(view.Layout):
            pass

        view.registerLayout('test1', klass=MyLayout)
        view.registerLayout('test2', klass=MyLayout)

        self.assertRaises(
            ValueError,
            self._init_memphis)
Beispiel #5
0
    def test_layout_register_simple(self):
        view.registerLayout('test')
        self._init_memphis()

        layout = config.registry.getMultiAdapter(
            (object(), self.request), view.ILayout, 'test')

        self.assertEqual(layout.name, 'test')
        self.assertEqual(layout.__name__, 'test')
        self.assertTrue(isinstance(layout, Layout))
        self.assertTrue(issubclass(layout.__class__, Layout))
        self.assertTrue(layout.__class__ is not Layout)
Beispiel #6
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()))
Beispiel #7
0
    def test_view_register_view_layout(self):
        class MyLayout(view.Layout):
            def render(self, rendered):
                return '<html>%s</html>'%rendered

        class MyView(view.View):
            def render(self):
                return 'test'

        view.registerView('index.html', MyView, Context)
        view.registerLayout('', Context, klass=MyLayout)
        self._init_memphis()

        context = Context()
        res = view.renderView('index.html', context, self.request)
        self.assertTrue('<html>test</html>' in res.body)
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
0
    def test_view_register_view_disable_layout1(self):
        class MyLayout(view.Layout):
            def render(self, rendered):
                return '<html>%s</html>'%rendered

        class MyView(view.View):
            def render(self):
                return 'test'

        view.registerView('index.html', MyView, Context, layout=None)
        view.registerLayout('', Context, klass=MyLayout)
        self._init_memphis()

        context = Context()
        res = view.renderView('index.html', context, self.request)
        self.assertEqual(res.body, 'test')

        v = MyView(None, self.request)
        self.assertEqual(MyLayout(v, self.request).render(
                v.render()), '<html>test</html>')
Beispiel #11
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>')
Beispiel #12
0
    def test_renderer_simple_with_layout(self):
        class Layout(view.Layout):
            def render(self, content):
                return "<html>%s</html>" % content

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

        def viewFactory(context, request):
            return None, "test"

        # renderer layout is different
        r = SimpleRenderer("")
        res = r(Context(), self.request, viewFactory)
        self.assertEqual(res.body, "test")

        # layout is 'test'
        r = SimpleRenderer("test")
        res = r(Context(), self.request, viewFactory)
        self.assertEqual(res.body, "<html>test</html>")
Beispiel #13
0
    def test_renderer_tmpl_with_layout(self):
        class Layout(view.Layout):
            def render(self, content):
                return "<html>%s</html>" % content

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

        def viewFactory(context, request):
            return None, {}

        # renderer layout is different
        r = Renderer(view.template("templates/test.pt"), "")
        res = r(Context(), self.request, viewFactory)
        self.assertEqual(res.body, "<div>My pagelet</div>\n")

        # layout is 'test'
        config.cleanUp()
        r = Renderer(view.template("templates/test.pt"), "test")
        res = r(Context(), self.request, viewFactory)
        self.assertEqual(res.body, "<html><div>My pagelet</div>\n</html>")
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
0
# devapp

import ptah_app
import ptah_app.views

from memphis import view


view.registerLayout('page', ptah_app.IPtahAppRoot, layer='devapp',
                    template = view.template('templates/layoutpage.pt'))

view.registerLayout('page', view.INavigationRoot, layer='devapp',
                    template = view.template('templates/layoutpage.pt'))


view.static('socketio', 'devsocket:socketio/')
view.library(
    'socket.io',
    path="socket.io.js",
    resource="socketio",
    type="js",
    require='jquery',
)
view.library(
    'sticky.min.css',
    path="sticky.min.css",
    resource="socketio",
    type="css",
)
view.library(
    'sticky.min.js',
Beispiel #17
0
from zope.location.interfaces import LocationError
from zope.traversing.interfaces import ITraversable
from zope.publisher.interfaces.browser import IDefaultBrowserLayer

from Acquisition import Implicit
from AccessControl import Unauthorized, getSecurityManager
from Products.CMFCore.interfaces import ISiteRoot
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

from memphis import config, view, form
from memphis.controlpanel.interfaces import IConfiglet


view.registerLayout(
    '', IConfiglet,
    klass = view.ZopeLayout,
    template = ViewPageTemplateFile(
        view.path('memphis.controlpanel:templates/layout-prefs.pt'))
)


def CheckPermission(factory):
    def callView(context, request):
        if getSecurityManager().checkPermission(context.permission, context):
            return factory(context, request)

        raise Unauthorized()

    return callView


class LocationProxy(LocationProxy, Implicit):
Beispiel #18
0
""" 

$Id:  2007-12-12 12:27:02Z fafhrd $
"""
from memphis import view, content
from Products.CMFCore.interfaces import ISiteRoot, ITypeInformation
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile


view.registerLayout(
    '', ISiteRoot,
    klass = view.ZopeLayout,
    template = ViewPageTemplateFile(
        view.path('memphis.content:templates/layout-contentcore.pt'))
)


view.registerLayout(
    '', ITypeInformation,
    klass = view.ZopeLayout,
    template = ViewPageTemplateFile(
        view.path('memphis.content:templates/layout-content.pt'))
)


view.registerLayout(
    'body', content.IContent,
    klass = view.ZopeLayout,
    template = ViewPageTemplateFile(
        view.path('memphis.content:templates/layout-body.pt'))
)