Ejemplo n.º 1
0
 def get_path_to(self, content):
     """Return the path to the given content, even if the content
     is outside of the export root folder. If it is outside, the
     path will be absolute from the Silva root and prefixed with
     root:.
     """
     exported = self.getExported()
     content_path = content.getPhysicalPath()
     if is_inside_path(exported.rootPath, content_path):
         return "/".join(canonical_tuple_path(
                 [exported.root.getId()] +  relative_tuple_path(
                     exported.rootPath, content_path)))
     return "root:" + "/".join(canonical_tuple_path(
             relative_tuple_path(exported.basePath, content_path)))
Ejemplo n.º 2
0
 def get_references(self, name):
     ref_set = ReferenceSet(self.context, name)
     options = self.getOptions()
     exported = self.getExported()
     have_external = 0
     root = exported.root
     for reference in ref_set.get_references():
         if not options.external_rendering:
             if not reference.target_id:
                 # The reference is broken. Return an empty path.
                 yield ""
             if not reference.is_target_inside_container(root):
                 if options.external_references:
                     have_external += 1
                     continue
                 else:
                     raise ExternalReferenceError(
                         _(u"External references"),
                         self.context, reference.target, root)
             # Add root path id as it is always mentioned in exports
             path = [root.getId()] + reference.relative_path_to(root)
             yield '/'.join(canonical_tuple_path(path))
         else:
             # Return url to the target
             yield absoluteURL(reference.target, exported.request)
     if have_external:
         # Report the collected problems.
         exported.reportProblem(
             (u'Content contains {0} reference(s) pointing outside ' +
              u'of the export.').format(
                 have_external),
             self.context)
Ejemplo n.º 3
0
 def get_relative_path_to(self, content):
     exported = self.getExported()
     return '/'.join(canonical_tuple_path(
             [exported.root.getId()] +
             relative_tuple_path(
                 exported.rootPath,
                 content.getPhysicalPath())))
Ejemplo n.º 4
0
 def get_reference(self, name):
     """Return a path to refer an item that is contained inside the
     export root folder for a reference tagged name.
     """
     service = getUtility(IReferenceService)
     reference = service.get_reference(self.context, name=name)
     if reference is None:
         return None
     exported = self.getExported()
     options = self.getOptions()
     root = exported.root
     if not options.external_rendering:
         if not reference.target_id:
             # The reference is broken. Return an empty path.
             exported.reportProblem(
                 u'Content has a broken reference in the export.',
                 self.context)
             return ""
         if not reference.is_target_inside_container(root):
             if options.external_references:
                 # The reference is not inside the export, export
                 # anyway with a broken reference if the option is given.
                 exported.reportProblem(
                     u'Content refers to an another content outside of '
                     u'the export ({0}).'.format(
                         '/'.join(reference.relative_path_to(root))),
                     self.context)
                 return ""
             else:
                 raise ExternalReferenceError(
                     _(u"External references"),
                     self.context, reference.target, root)
         # Add root path id as it is always mentioned in exports
         return '/'.join(canonical_tuple_path(
                 [root.getId()] + reference.relative_path_to(root)))
     # Return url to the target
     return absoluteURL(reference.target, exported.request)