def manage_customize_index(self, REQUEST): """ create a custom map_index """ if "map_index" in self.objectIds(): raise ValueError("map_index already customized") else: text = get_template_source(self._index_template()) manage_addPageTemplate(self, id="map_index", title="", text=text) REQUEST.RESPONSE.redirect("%s/manage_workspace" % self.map_index.absolute_url())
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 manage_edit(self, text=None, REQUEST=None): """ change the contents """ if text is not None: self._text = text self._cook() # force re-compilation of template if REQUEST is not None: text = get_template_source(self) return self._manage_edit_html(REQUEST, text=text)
def show_diff(self, REQUEST): """ show the differences between the default and customized form """ name = REQUEST.get('name', '') bundle_template = self.bundle_template(name) bundle_content = get_template_source(bundle_template) customized_content = self.template_content(name) diff = html_diff(bundle_content, customized_content) return self._diff(diff=diff)
def move_to_bundle(self, REQUEST=None): """ Move templates to a writable bundle. """ site = self.getSite() user = site.getAuthenticationTool().get_current_userid() bundle = fsbundles.get_writable_bundle(site) if bundle is None: factory = fsbundles.get_filesystem_bundle_factory(site) assert factory is not None, "No writable bundle found!" bundle = factory() if REQUEST is not None: msg = ("IMPORTANT: new bundle %r created. If multiple Zope " "instances are sharing the same ZEO database, make " "sure they all load the new bundle." % bundle) self.setSessionInfo([msg]) bundle_name = bundle.__name__ gsm = getGlobalSiteManager() writer = gsm.queryUtility(IFilesystemTemplateWriter, name=bundle_name) template_names = [] for template in self.objectValues(): content = get_template_source(template) name = template.getId() writer.write_zpt(name, content) self._delObject(template.getId()) log.info("Template %r moved to bundle %r by %r", name, bundle_name, user) template_names.append(name) # TODO reload the bundle in all zope instances # TODO in case of failure, print what has been written to disk if REQUEST is not None: self.setSessionInfo([ "Moved templates bundle %r: %r" % (bundle_name, template_names) ]) return REQUEST.RESPONSE.redirect('%s/manage_overview' % self.absolute_url())
def move_to_bundle(self, REQUEST=None): """ Move templates to a writable bundle. """ site = self.getSite() user = site.getAuthenticationTool().get_current_userid() bundle = fsbundles.get_writable_bundle(site) if bundle is None: factory = fsbundles.get_filesystem_bundle_factory(site) assert factory is not None, "No writable bundle found!" bundle = factory() if REQUEST is not None: msg = ("IMPORTANT: new bundle %r created. If multiple Zope " "instances are sharing the same ZEO database, make " "sure they all load the new bundle." % bundle) self.setSessionInfo([msg]) bundle_name = bundle.__name__ gsm = getGlobalSiteManager() writer = gsm.queryUtility(IFilesystemTemplateWriter, name=bundle_name) template_names = [] for template in self.objectValues(): content = get_template_source(template) name = template.getId() writer.write_zpt(name, content) self._delObject(template.getId()) log.info("Template %r moved to bundle %r by %r", name, bundle_name, user) template_names.append(name) # TODO reload the bundle in all zope instances # TODO in case of failure, print what has been written to disk if REQUEST is not None: self.setSessionInfo(["Moved templates bundle %r: %r" % (bundle_name, template_names)]) return REQUEST.RESPONSE.redirect('%s/manage_overview' % self.absolute_url())
def source(self): return get_template_source(self)
def template_content(self, name): """ Get template content """ template = self.get_template(name) return get_template_source(template)
def __call__(self): return get_template_source(self.template)