def manage_create_custom_template(self, REQUEST=None): """ """ from Products.NaayaCore.LayoutTool.Template import manage_addTemplate parent_path, name = self.custom_template.rsplit('/', 1) parent = self.getSite().unrestrictedTraverse(parent_path) manage_addTemplate(parent, name) ob = parent[name] ob.pt_edit(get_template_source(self.template), 'text/html') if REQUEST is not None: REQUEST.RESPONSE.redirect(ob.absolute_url() + '/manage_workspace')
def test_manageAddTemplate(self): """Test that we can successfully add a template using manageAddTemplate""" formstool_ob = self.portal.getFormsTool() layouttool_ob = self.portal.getLayoutTool() self.assertNotEqual(formstool_ob, None) self.assertNotEqual(layouttool_ob, None) id = 'test_id' manage_addTemplate(formstool_ob, id, 'test title', 'file_dummy_content', None) form_ob = formstool_ob._getOb(id, None) self.failIfEqual(form_ob, None, 'Form was not added into FormsTool') self.assert_(hasattr(form_ob, 'path'), 'Form has no attribute "path"') self.assert_(hasattr(form_ob, 'customized'), 'Form has no attribute "customized"')
def _set_custom_tmpl(self): url_schema = self.portal['portal_schemas']['NyURL'] title_widget = url_schema['title-property'] title_widget.custom_template = 'portal_forms/widget_tempate_for_test' portal_forms = self.portal['portal_forms'] manage_addTemplate(portal_forms, 'widget_tempate_for_test') tmpl = portal_forms['widget_tempate_for_test'] custom_tmpl = ('<tal:block content="string:[[[[' 'path ${here/getPhysicalPath},' 'ctxpath ${options/context/getPhysicalPath},' 'value ${options/value|nothing},' 'errors ${options/errors},' 'prop_id ${here/prop_name},' ']]]]" />') tmpl.pt_edit(custom_tmpl, 'text/html')
def test_manageAddTemplateFromFile(self): import os file_c = os.path.join(os.path.dirname(__file__), 'testform.zpt') formstool_ob = self.portal.getFormsTool() layouttool_ob = self.portal.getLayoutTool() self.assertNotEqual(formstool_ob, None) self.assertNotEqual(layouttool_ob, None) id = 'test_id' manage_addTemplate(formstool_ob, id, 'title', file_c, None) form_ob = formstool_ob._getOb(id, None) self.failIfEqual(form_ob, None, 'Form was not added into FormsTool') self.assert_(hasattr(form_ob, 'path'), 'Form has no attribute "path"') self.assert_(hasattr(form_ob, 'customized'), 'Form has no attribute "customized"') self.assertEqual(form_ob.getText(), 'insidefile')