Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 7
0
def fileupload(model, request):
    """Fileupload as traversable view.
    """
    return render_main_template(model, request, 'fileupload')
Exemplo n.º 8
0
def edit(model, request):
    return render_main_template(model, request, contenttilename='edit')
Exemplo n.º 9
0
def listing(model, request):
    """Listing view
    """
    return render_main_template(model, request, 'listing')
Exemplo n.º 10
0
def fileupload(model, request):
    """Fileupload as traversable view.
    """
    return render_main_template(model, request, 'fileupload')
Exemplo n.º 11
0
def add(model, request):
    return render_main_template(model, request, contenttilename='add')
Exemplo n.º 12
0
 def content_view(model, request):
     return render_main_template(model, request, contenttile=self.name)
Exemplo n.º 13
0
def sharing(model, request):
    """Sharing view
    """
    return render_main_template(model, request, 'sharing')
Exemplo n.º 14
0
def not_found_view(request):
    """Not Found view.
    """
    model = request.context
    return render_main_template(model, request, contenttile='not_found')
Exemplo n.º 15
0
def not_found_view(request):
    """Not Found view.
    """
    model = request.context
    return render_main_template(model, request, contenttile='not_found')
Exemplo n.º 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))
Exemplo n.º 17
0
def sharing(model, request):
    """Sharing view
    """
    return render_main_template(model, request, "sharing")
Exemplo n.º 18
0
def login_view(model, request):
    return render_main_template(model, request, contenttile='loginform')
Exemplo n.º 19
0
def login_view(model, request):
    return render_main_template(model, request, contenttile='loginform')
Exemplo n.º 20
0
def listing(model, request):
    """Listing view
    """
    return render_main_template(model, request, 'listing')