コード例 #1
0
    def _url(self, path, preview=False, relative=False, host=None):
        plugin = self.request.get_plugin(IVirtualHosting)
        if not IForestHosting.providedBy(plugin):
            return super(ContentURL, self)._url(path, preview, relative, host)

        virtual_host = plugin.host
        if host is not None:
            virtual_host = plugin.service.query(url2tuple(host))
        if virtual_host is None:
            return super(ContentURL, self)._url(path, preview, relative, host)

        rule, index = virtual_host.by_path.get(path[1:], fallback=True)
        if rule is None:
            raise BadRequest(
                u"No virtual host is defined for %s" % self.context)
        path = list(path[index + 1:])

        if preview is True:
            preview_position = max(
                len(self.context.get_root().getPhysicalPath()) - (index + 1), 0)
            path.insert(preview_position, '++preview++')

        if relative:
            return '/' + '/'.join(rule.server_script + path)
        return '/'.join([rule.url,] + path)
コード例 #2
0
ファイル: site.py プロジェクト: silvacms/silva.app.forest
 def get_top_level_path(self):
     plugin = self.request.get_plugin(IVirtualHosting)
     if IForestHosting.providedBy(plugin) and plugin.host is not None:
         top_levels = plugin.host.by_url.top()
         if len(top_levels) == 1:
             return '/' + '/'.join(top_levels[0].server_script)
     return super(ForestVirtualSite, self).get_top_level_path()
コード例 #3
0
    def _url(self, path, preview=False, relative=False, host=None):
        plugin = self.request.get_plugin(IVirtualHosting)
        if not IForestHosting.providedBy(plugin):
            return super(SimpleURL, self)._url(path, preview, relative, host)

        virtual_host = plugin.host
        if host is not None:
            virtual_host = plugin.service.query(url2tuple(host))
        if virtual_host is None:
            return super(SimpleURL, self)._url(path, preview, relative, host)

        rule, index = virtual_host.by_path.get(path[1:], fallback=True)
        if rule is None:
            logger.error(
                u"No virtual host defined to compute URL for path %s.",
                '/'.join(path))
            # Broken fallback that will generate a relative URL to
            # prevent breaking the ZMI.
            return '/'.join(path)

        path = list(path[index + 1:])
        if relative:
            return '/' + '/'.join(rule.server_script + path)
        return '/'.join([rule.url,] + path)