Пример #1
0
    def test_render_main_template(self):
        # To change the default layout, change the main template
        self.checkOutput('...', cone.app.cfg.main_template)

        main = 'cone.app.testing:dummy_main.pt'
        cone.app.cfg.main_template = main

        # An unprotected tile named 'content' registered for all sorts of node
        with self.layer.hook_tile_reg():

            @tile(name='content', permission='login')
            class ContentTile(Tile):
                def render(self):
                    return '<div>Content</div>'

        model = BaseNode()
        request = self.layer.new_request()

        # Render main template. The function accepts an optional ``contenttile``
        # argument. if omitted, reserved name 'content' is used
        res = render_main_template(model, request)
        self.checkOutput(
            """
        <!DOCTYPE html...<div>Content</div>...</html>
        """, res.text)

        with self.layer.hook_tile_reg():

            @tile(name='othername', permission='login')
            class OtherContentTile(ContentTile):
                def render(self):
                    return '<div>Content</div>'

        res = render_main_template(model, request, contenttile='othername')
        self.checkOutput(
            """
        <!DOCTYPE html...<div>Content</div>...</html>
        """, res.text)

        # Switch back to default main template
        main = 'cone.app.browser:templates/main.pt'
        cone.app.cfg.main_template = main

        # Non authenticated users only gets unprotected content tile, no
        # controls like navtree, mainmenu, etc
        res = render_main_template(model, request, contenttile='othername')
        self.assertFalse(res.text.find('id="mainmenu"') > -1)
        self.assertFalse(res.text.find('id="navtree"') > -1)
        self.assertFalse(res.text.find('id="personaltools"') > -1)
        self.assertTrue(res.text.find('<div>Content</div>') > -1)

        # Authenticate non privileged
        with self.layer.authenticated('max'):
            res = render_main_template(model, request, contenttile='othername')

        # All tiles protected by 'view' permission are now available to the user
        self.assertTrue(res.text.find('id="mainmenu"') > -1)
        self.assertTrue(res.text.find('id="navtree"') > -1)
        self.assertTrue(res.text.find('id="personaltools"') > -1)
Пример #2
0
    def test_render_main_template(self):
        # To change the default layout, change the main template
        self.checkOutput('...', cone.app.cfg.main_template)

        main = 'cone.app.testing:dummy_main.pt'
        cone.app.cfg.main_template = main

        # An unprotected tile named 'content' registered for all sorts of node
        with self.layer.hook_tile_reg():
            @tile(name='content', permission='login')
            class ContentTile(Tile):
                def render(self):
                    return '<div>Content</div>'

        model = BaseNode()
        request = self.layer.new_request()

        # Render main template. The function accepts an optional ``contenttile``
        # argument. if omitted, reserved name 'content' is used
        res = render_main_template(model, request)
        self.checkOutput("""
        <!DOCTYPE html...<div>Content</div>...</html>
        """, res.text)

        with self.layer.hook_tile_reg():
            @tile(name='othername', permission='login')
            class OtherContentTile(ContentTile):
                def render(self):
                    return '<div>Content</div>'

        res = render_main_template(model, request, contenttile='othername')
        self.checkOutput("""
        <!DOCTYPE html...<div>Content</div>...</html>
        """, res.text)

        # Switch back to default main template
        main = 'cone.app.browser:templates/main.pt'
        cone.app.cfg.main_template = main

        # Non authenticated users only gets unprotected content tile, no
        # controls like navtree, mainmenu, etc
        res = render_main_template(model, request, contenttile='othername')
        self.assertFalse(res.text.find('id="mainmenu"') > -1)
        self.assertFalse(res.text.find('id="navtree"') > -1)
        self.assertFalse(res.text.find('id="personaltools"') > -1)
        self.assertTrue(res.text.find('<div>Content</div>') > -1)

        # Authenticate non privileged
        with self.layer.authenticated('max'):
            res = render_main_template(model, request, contenttile='othername')

        # All tiles protected by 'view' permission are now available to the user
        self.assertTrue(res.text.find('id="mainmenu"') > -1)
        self.assertTrue(res.text.find('id="navtree"') > -1)
        self.assertTrue(res.text.find('id="personaltools"') > -1)
Пример #3
0
def forbidden_view(request):
    """Unauthorized view.
    """
    model = request.context
    if not request.authenticated_userid:
        return login_view(model, request)
    return render_main_template(model, request, contenttile='unauthorized')
Пример #4
0
def forbidden_view(request):
    """Unauthorized view.
    """
    model = request.context
    if not request.authenticated_userid:
        return login_view(model, request)
    return render_main_template(model, request, contenttile='unauthorized')
Пример #5
0
def render_form(model, request, tilename):
    """If form is invoked without hidden ajax field, the main template is
    rendered with tile ``tilename`` as content tile, otherwise
    ``render_ajax_form`` is called, which renders the tile wrapped by some
    javascript calls into a script tag. The ajax response will be rendered into
    the hidden iframe on client side, where ajax continuation is processed.
    
    XXX: move to cone.app.browser.form 
    """
    if is_ajax(request):
        return render_ajax_form(model, request, tilename)
    return render_main_template(model, request, contenttilename=tilename)
Пример #6
0
def render_form(model, request, tilename):
    """If form is invoked without hidden ajax field, the main template is
    rendered with tile ``tilename`` as content tile, otherwise
    ``render_ajax_form`` is called, which renders the tile wrapped by some
    javascript calls into a script tag. The ajax response will be rendered into
    the hidden iframe on client side, where ajax continuation is processed.

    XXX: move to cone.app.browser.form
    """
    if is_ajax(request):
        ActionContext(model, request, tilename)
        return render_ajax_form(model, request, tilename)
    return render_main_template(model, request, contenttile=tilename)
Пример #7
0
def fileupload(model, request):
    """Fileupload as traversable view.
    """
    return render_main_template(model, request, 'fileupload')
Пример #8
0
def edit(model, request):
    return render_main_template(model, request, contenttilename='edit')
Пример #9
0
def listing(model, request):
    """Listing view
    """
    return render_main_template(model, request, 'listing')
Пример #10
0
def fileupload(model, request):
    """Fileupload as traversable view.
    """
    return render_main_template(model, request, 'fileupload')
Пример #11
0
def add(model, request):
    return render_main_template(model, request, contenttilename='add')
Пример #12
0
 def content_view(model, request):
     return render_main_template(model, request, contenttile=self.name)
Пример #13
0
def sharing(model, request):
    """Sharing view
    """
    return render_main_template(model, request, 'sharing')
Пример #14
0
def not_found_view(request):
    """Not Found view.
    """
    model = request.context
    return render_main_template(model, request, contenttile='not_found')
Пример #15
0
def not_found_view(request):
    """Not Found view.
    """
    model = request.context
    return render_main_template(model, request, contenttile='not_found')
Пример #16
0
 def test_render_main_template(self):
     root = get_root()
     request = self.layer.new_request()
     response = render_main_template(root, request)
     self.assertTrue(isinstance(response, Response))
Пример #17
0
def sharing(model, request):
    """Sharing view
    """
    return render_main_template(model, request, "sharing")
Пример #18
0
def login_view(model, request):
    return render_main_template(model, request, contenttile='loginform')
Пример #19
0
def login_view(model, request):
    return render_main_template(model, request, contenttile='loginform')
Пример #20
0
def listing(model, request):
    """Listing view
    """
    return render_main_template(model, request, 'listing')