示例#1
0
    def GET(self, name='default'):
        service = getUtility(ICKEditorService)

        url_base = IVirtualSite(self.request).get_root_path()
        if not url_base.endswith('/'):
            url_base = url_base + '/'

        # Insert url_base where ever it is needed.
        plugins_url = {name: url_base + path for name, path in
                       service.get_custom_plugins().items()}

        configuration = service.get_configuration(name)
        skin = configuration.skin
        if ',' in skin:
            skin = skin.replace(',', ',' + url_base)

        return self.json_response(
            {'toolbars': configuration.get_toolbars_configuration(),
             'paths': plugins_url,
             'contents_css': configuration.contents_css,
             'formats': configuration.get_formats_configuration(),
             'table_styles': configuration.get_table_styles_configuration(),
             'plugins': list(plugins_url.keys()),
             'disable_colors': configuration.disable_colors,
             'startup_show_borders': configuration.startup_show_borders,
             'editor_body_class': configuration.editor_body_class,
             'skin': skin})
    def test_virtual_site_top_level_is_not_unique(self):
        """Test cases where the Silva root is the highest URL you can
        get.
        """
        # Sub case 1
        request = TestRequest(
            application=self.root,
            url='https://complicated/admin/edit',
            headers=[('X-VHM-Url', 'https://complicated')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'https://complicated/admin')
        self.assertEqual(site.get_root_path(), '/admin')
        self.assertEqual(site.get_top_level_url(), 'https://complicated/admin')
        self.assertEqual(site.get_top_level_path(), '/admin')

        # Sub case 2
        request = TestRequest(
            application=self.root,
            url='https://complicated/site/edit',
            headers=[('X-VHM-Url', 'https://complicated')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'https://complicated/site')
        self.assertEqual(site.get_root_path(), '/site')
        self.assertEqual(site.get_top_level_url(), 'https://complicated/site')
        self.assertEqual(site.get_top_level_path(), '/site')
    def test_virtual_site_simple(self):
        """Test simple cases nothing special is set or done.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/man/edit',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'http://localhost')
        self.assertEqual(site.get_root_path(), '/')
        self.assertEqual(site.get_top_level_url(), 'http://localhost')
        self.assertEqual(site.get_top_level_path(), '/')
    def test_virtual_site_top_level_is_not_root_at_top_level(self):
        """Test cases where the Silva root is not the highest URL you
        can get.
        """
        request = TestRequest(
            application=self.root,
            url='http://localhost/man/edit',
            headers=[('X-VHM-Url', 'http://localhost')])
        plugin = request.query_plugin(request.application, IVirtualHosting)
        root, method, path = plugin(request.method, request.path)

        site = IVirtualSite(request)
        self.assertTrue(verifyObject(IVirtualSite, site))
        self.assertEqual(site.get_root_url(), 'http://localhost')
        self.assertEqual(site.get_root_path(), '/')
        self.assertEqual(site.get_top_level_url(), 'http://localhost')
        self.assertEqual(site.get_top_level_path(), '/')
示例#5
0
    def _get_root_content_url(self):
        # Redirect to the root of the SMI if we are not already
        site = IVirtualSite(self.request)
        settings = getUtility(IUIService)
        if settings.smi_access_root:
            top_level = site.get_silva_root()
        else:
            top_level = site.get_root()

        # We lookup for the highest container where we have access
        root = self.context.get_container()
        while root != top_level:
            parent = root.get_real_container()
            if parent is None or not checkPermission("silva.ReadSilvaContent", parent):
                # We don't have access at that level
                break
            root = parent
        return getMultiAdapter((root, self.request), IContentURL)
示例#6
0
    def convert(self, context):
        image = None
        attributes = {'alignment': self.getattr('alignment', 'default'),
                      'alt': self.getattr('title', '')}

        if self.hasattr('reference'):
            # We have a reference
            reference_name = str(self.getattr('reference'))
            reference_name, reference = context.get_reference(
                reference_name, read_only=True)
            assert reference is not None, "Invalid reference"
            attributes['_silva_target'] = reference.target_id
            attributes['_silva_reference'] = reference_name
            image = reference.target
            if image is not None:
                attributes['src'] = absoluteURL(image, context.request)
            else:
                site = IVirtualSite(context.request)
                attributes['src'] = site.get_root_url() + \
                    "/++resource++Products.SilvaDocument/broken-link.jpg"
                attributes['alt'] = u'Referenced image is missing.'
        elif self.hasattr('path'):
            path = self.getattr('path')
            src = IPath(context.request).pathToUrlPath(str(path))
            attributes['src'] = src
            try:
                image = context.model.unrestrictedTraverse(src.split('/'))
            except:
                pass
        else:
            raise ValueError('Invalid silva image tag')

        if image and IImage.providedBy(image):
            attributes['width'], attributes['height'] = \
                image.get_dimensions(image.image)

        return html.img(self.content.convert(context), **attributes)
示例#7
0
 def root_url(self):
     site = IVirtualSite(self.request)
     return site.get_root_url()
示例#8
0
 def root_url(self):
     site = IVirtualSite(self.request)
     return site.get_root_url()
    def sax_img(self, node):
        """Unfortunately <image> is a special case, since height and width
        are not stored in the document but in the Image object itself, and
        need to be retrieved here.
        """
        attributes = {}
        options = self.getOptions()
        request = self.getExported().request
        if node.attributes:
            attributes = get_dict(node.attributes)

        if options.external_rendering:
            rewritten_path = None
            if 'reference' in attributes:
                service = getUtility(IReferenceService)
                reference = service.get_reference(
                    self.context, name=attributes['reference'])
                image = reference.target
                if options.upgrade30:
                    attributes['data-silva-target'] = str(reference.target_id)
                    attributes['data-silva-reference'] = reference.tags[1]
                    reference.tags[0] = u"body image"
                    reference._p_changed = True
                elif image is not None:
                    rewritten_path = absoluteURL(image, request)
            else:
                document = self.context.get_content()
                image = document.unrestrictedTraverse(
                    attributes['path'].split('/'), None)
                if options.upgrade30:
                    attributes['data-silva-url'] = attributes['path']
                elif image is not None:
                    path = IPath(document)
                    rewritten_path = path.pathToUrlPath(attributes['path'])
            if not options.upgrade30:
                if not rewritten_path:
                    site = IVirtualSite(request)
                    rewritten_path = site.get_root_url() + \
                        "/++resource++Products.SilvaDocument/broken-link.jpg"
                    attributes['title'] = _(u'Referenced image is missing')
                attributes['rewritten_path'] = rewritten_path

            if image is not None:
                if IImage.providedBy(image):
                    resolution = options.image_res
                    attributes['title'] = image.get_title()
                    if resolution and not options.upgrade30:
                        attributes['rewritten_path'] += '?%s' % resolution
                        if resolution == 'hires':
                            width, height = image.get_dimensions()
                        attributes['width'] = str(width)
                        attributes['height'] = str(height)

        else:
            if 'reference' in attributes:
                attributes['reference'] = self.get_reference(
                    attributes['reference'])

        if attributes.has_key('alignment'):
            if not attributes['alignment']:
                attributes['alignment'] = 'default'
        else:
            attributes['alignment'] = 'default'
        self.startElementNS(NS_DOCUMENT_URI, node.nodeName, attributes)
        self.endElementNS(NS_DOCUMENT_URI, node.nodeName)
示例#10
0
文件: smi.py 项目: silvacms/silva.ui
    def update(self):
        # Redirect to the root of the SMI if we are not already
        site = IVirtualSite(self.request)
        settings = getUtility(IUIService)
        if settings.smi_access_root:
            top_level = site.get_silva_root()
        else:
            top_level = site.get_root()

        # We lookup for the highest container where we have access
        root = self.context.get_container()
        while root != top_level:
            parent = root.get_real_container()
            if (parent is None or
                    not checkPermission('silva.ReadSilvaContent', parent)):
                # We don't have access at that level
                break
            root = parent

        root_content_url = getMultiAdapter((root, self.request), IContentURL)
        root_url = root_content_url.url()
        if root != self.context:
            # Relative path of the content from the root.
            content_url = getMultiAdapter(
                (self.context, self.request), IContentURL)
            root_path = root_content_url.url(relative=True).split('/')
            content_path = content_url.url(relative=True).split('/')
            path = '/'.join(relative_path(root_path, content_path))

            raise Redirect('/'.join((root_url, 'edit')) + '#!' + path)

        # Set the proper SMI skin
        set_smi_skin(self.context, self.request)

        # Load the extensions
        for load_entry in iter_entry_points('silva.ui.resources'):
            resource = load_entry.load()
            need(resource)

        # Customization from service
        if settings.logo is not None:
            settings_content_url = getMultiAdapter(
                (settings, self.request), IContentURL)
            self.logo_url = '/'.join((settings_content_url.url(), 'logo'))
        else:
            self.logo_url = self.static['img']['silva.png']()
        self.background = '#7996ac'
        self.name = settings.name
        self.listing_preview = settings.folder_icon_preview
        self.maintenance_message = settings.maintenance_message
        self.test_mode = settings.test_mode
        self.preview_resolutions = []
        self.notifications_life = settings.notifications_life
        if settings.preview_use_resolutions:
            self.preview_resolutions = list(settings.preview_resolutions)
        if settings.background:
            self.background = settings.background

        # Prepare values for template
        languages = IUserPreferredLanguages(
            self.request).getPreferredLanguages()

        self.language = languages[0] if languages else 'en'
        self.root_url = root_url
        self.can_manage = getSecurityManager().checkPermission(
            'View Management Screens', self.context)