comparison libervia/server/server.py @ 1127:9234f29053b0

server, pages: update to handle multi sites themes, first draft: This first part of update handle changes in backend for multi-sites templates. Templates are now available in _t resource, followed by site name (default one is in "sat").
author Goffi <goffi@goffi.org>
date Sun, 09 Sep 2018 21:12:22 +0200
parents 7cd89277a129
children 6414fd795df4
comparison
equal deleted inserted replaced
1126:7cd89277a129 1127:9234f29053b0
1641 def _namespacesGetCb(self, ns_map): 1641 def _namespacesGetCb(self, ns_map):
1642 self.ns_map = ns_map 1642 self.ns_map = ns_map
1643 1643
1644 def _namespacesGetEb(self, failure_): 1644 def _namespacesGetEb(self, failure_):
1645 log.error(_(u"Can't get namespaces map: {msg}").format(msg=failure_)) 1645 log.error(_(u"Can't get namespaces map: {msg}").format(msg=failure_))
1646
1647 def _front_url_filter(self, ctx, relative_url):
1648 template_data = ctx[u'template_data']
1649 return os.path.join(u'/', C.TPL_RESOURCE, template_data.site or u'sat',
1650 C.TEMPLATE_TPL_DIR, template_data.theme, relative_url)
1646 1651
1647 def backendReady(self, dummy): 1652 def backendReady(self, dummy):
1648 self.root = root = LiberviaRootResource(self.html_dir) 1653 self.root = root = LiberviaRootResource(self.html_dir)
1649 _register = Register(self) 1654 _register = Register(self)
1650 _upload_radiocol = UploadManagerRadioCol(self) 1655 _upload_radiocol = UploadManagerRadioCol(self)
1766 wrapped = web_resource.EncodingResourceWrapper( 1771 wrapped = web_resource.EncodingResourceWrapper(
1767 root, [server.GzipEncoderFactory()] 1772 root, [server.GzipEncoderFactory()]
1768 ) 1773 )
1769 self.site = server.Site(wrapped) 1774 self.site = server.Site(wrapped)
1770 self.site.sessionFactory = LiberviaSession 1775 self.site.sessionFactory = LiberviaSession
1771 self.renderer = template.Renderer(self) 1776 self.renderer = template.Renderer(self, self._front_url_filter)
1772 self.putChild("templates", ProtectedFile(self.renderer.base_dir)) 1777 templates_res = web_resource.Resource()
1778 self.putChild(C.TPL_RESOURCE, templates_res)
1779 for site_name, site_path in self.renderer.sites_paths.iteritems():
1780 templates_res.putChild(site_name or u'sat', ProtectedFile(site_path))
1773 1781
1774 def initEb(self, failure): 1782 def initEb(self, failure):
1775 log.error(_(u"Init error: {msg}").format(msg=failure)) 1783 log.error(_(u"Init error: {msg}").format(msg=failure))
1776 reactor.stop() 1784 reactor.stop()
1777 return failure 1785 return failure