def can_write_to_bundle(self): """ Check if we can find (or create) any bundle to write templates. """ site = self.getSite() if fsbundles.get_writable_bundle(site) is not None: return True elif fsbundles.get_filesystem_bundle_factory(site) is not None: return True else: return False
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())