Example #1
0
 def __call__(self, content):
     if IContainer.providedBy(content):
         path = list(content.getPhysicalPath()) + [
             'index.' + self.extension]
     elif IPublishable.providedBy(content):
         path = list(aq_parent(content).getPhysicalPath()) + [
             content.getId() + '.' + self.extension]
     elif IAsset.providedBy(content):
         path = list(aq_parent(content).getPhysicalPath()) + [
             content.get_filename()]
     else:
         path = content.getPhysicalPath()
     return '/'.join(relative_path(self._origin, path))
 def serializeValue(self, field, value, producer):
     if not value:
         return
     handler = producer.getHandler()
     options = handler.getOptions()
     if options.external_rendering:
         return
     if not bool(field.get_value('multiple')):
         value = [value]
     exported = handler.getExported()
     producer.startPrefixMapping(None, NS_REFERENCES)
     for target in value:
         if value is not None:
             if is_inside_container(exported.root, target):
                 target_path = [exported.root.getId()] + relative_path(
                     exported.rootPath, target.getPhysicalPath())
                 producer.startElement('path')
                 producer.characters(canonical_path('/'.join(target_path)))
                 producer.endElement('path')
             else:
                 if options.external_references:
                     exported.reportProblem(
                         (u"A reference field '{0}' refers to an " +
                          u'content outside of the export ({1}).').format(
                             field.getId(),
                             '/'.join(relative_path(
                                     exported.rootPath,
                                     target.getPhysicalPath()))),
                         producer.context)
                     producer.startElement('path')
                     producer.endElement('path')
                 else:
                     raise ExternalReferenceError(
                         _(u"External reference"),
                         producer.context, target, exported.root)
     producer.endPrefixMapping(None)
Example #3
0
 def sax_excludes(self):
     self.startElementNS(NS_NEWS_URI, "excludes")
     exported = self.getExported()
     for item in self.context.get_excluded_items():
         if is_inside_container(exported.root, item):
             path = [exported.root.getId()] + relative_path(
                 exported.rootPath, item.getPhysicalPath())
             path = canonical_path('/'.join(path))
             self.startElementNS(
                 NS_NEWS_URI, 'exclude', {'target': path})
             self.endElementNS(NS_NEWS_URI, 'exclude')
         else:
             exported.reportProblem(
                 'Content excluded from the filter was not exported',
                 content=self.context)
     self.endElementNS(NS_NEWS_URI, "excludes")
Example #4
0
    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)
Example #5
0
 def get_content_path(self, content):
     content_url = getMultiAdapter((content, self.request), IContentURL)
     content_path = content_url.url(relative=True).split("/")
     root_path = self.root_path.split("/")
     return "/".join(relative_path(root_path, content_path))