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)
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)
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')
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)
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)
def fileupload(model, request): """Fileupload as traversable view. """ return render_main_template(model, request, 'fileupload')
def edit(model, request): return render_main_template(model, request, contenttilename='edit')
def listing(model, request): """Listing view """ return render_main_template(model, request, 'listing')
def add(model, request): return render_main_template(model, request, contenttilename='add')
def content_view(model, request): return render_main_template(model, request, contenttile=self.name)
def sharing(model, request): """Sharing view """ return render_main_template(model, request, 'sharing')
def not_found_view(request): """Not Found view. """ model = request.context return render_main_template(model, request, contenttile='not_found')
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))
def sharing(model, request): """Sharing view """ return render_main_template(model, request, "sharing")
def login_view(model, request): return render_main_template(model, request, contenttile='loginform')