Ejemplo n.º 1
0
 def get_default(self):
     """Get the default content object of the folder.
     """
     content = self._getOb('index', None)
     if IContent.providedBy(content):
         return content
     return None
    def _perform_search(self, query, root, ignore_case, search_targets):
        """ walk through (part of) the site in search of query matches

            returns a list of dicts with keys 'path', 'occurrences',
            'title' and 'state'
        """
        ret = []
        buffer = [root]
        processed = 0
        occurrences = 0
        while buffer:
            current = buffer.pop(0) # XXX or do we want depth first?
            if IContainer.providedBy(current):
                buffer += current.objectValues()
            elif IContent.providedBy(current):
                content_objects = self._get_content_objects(current)
                processed += len(content_objects)
                for state, url, obj in content_objects:
                    content = self._get_silvaxml_content(obj)
                    if content is None:
                        continue
                    num = self._count_or_replace(
                        content, query, None, ignore_case, search_targets)
                    occurrences += num
                    if num > 0:
                        ret.append({
                            'url': url,
                            'path': '/'.join(obj.getPhysicalPath()),
                            'title': obj.get_title(),
                            'occurrences': num,
                            'state': state,
                        })
        return processed, occurrences, ret
Ejemplo n.º 3
0
    def _breadcrumbs(self, preview=False, skip=None):
        name = minimize(self._title(preview=preview))
        container = aq_parent(self.context)
        if skip is not None:
            while skip.providedBy(container):
                container = aq_parent(container)

        if (container is None or
            IRoot.providedBy(self.context) or
            self._virtual_root(self.context)):
            return ({'name': name, 'url': self.__str__()},)

        base = tuple()
        parent = queryMultiAdapter((container, self.request), IContentURL)
        if parent is not None:
            base = tuple(parent._breadcrumbs(preview, skip))

        if (not IDisableBreadcrumbTag.providedBy(self.context) and
            (not IContent.providedBy(self.context) or
             not self.context.is_default())):
            base += ({'name': name, 'url': self.__str__()},)

        return base
Ejemplo n.º 4
0
 def validate(self, target, adding=False):
     error = super(GhostManager, self).validate(target, adding)
     if error is None:
         if not IContent.providedBy(target):
             return ContentInvalidTarget()
     return error
Ejemplo n.º 5
0
 def need_update(self):
     if IGhost.providedBy(self.manager.ghost):
         viewable = self.manager.ghost.get_viewable()
         return self.target != viewable.get_haunted()
     return IContent.providedBy(self.manager.ghost)
Ejemplo n.º 6
0
 def validate(self, target, adding=False):
     error = super(GhostManager, self).validate(target, adding)
     if error is None:
         if not IContent.providedBy(target):
             return ContentInvalidTarget()
     return error
Ejemplo n.º 7
0
 def need_update(self):
     if IGhost.providedBy(self.manager.ghost):
         viewable = self.manager.ghost.get_viewable()
         return self.target != viewable.get_haunted()
     return IContent.providedBy(self.manager.ghost)
 def validate(self, content):
     return (hasattr(aq_base(content), '__subscribability__') and
             (IContent.providedBy(content) or
              IContainer.providedBy(content)))
Ejemplo n.º 9
0
    def update(self):
        """Update the index.
        """
        result = {}
        want_next = None
        service = getUtility(IReferenceService)
        walker = advanced_walk_silva_tree(self.get_container(), IPublishable)

        # Collect references to cleanup later.
        used_references = set([])
        existing_references = set([])
        for reference in service.get_references_from(self, name=REFERENCE_TAG):
            existing_references.add(reference.__name__)

        # Walk through the Silva tree to search for indexes.
        while True:
            try:
                content = walker.send(want_next)
            except StopIteration:
                break
            want_next = content.is_published()
            if not want_next:
                continue

            if IContent.providedBy(content) and content.is_default():
                # We skip default contents.
                continue

            indexable = IIndexEntries(content)
            # No title, we skip
            title = indexable.get_title()
            if not title:
                continue
            # No indexes, we skip
            indexes = indexable.get_entries()
            if not indexes:
                continue

            # Find a reference to use.
            identifier = None
            references = list(service.get_references_between(
                    self, content, name=REFERENCE_TAG))
            if len(references) == 1:
                reference = references[0]
                if len(reference.tags) > 1:
                    # Don't use a reference that doesn't have the required tag.
                    identifier = reference.tags[1]
                    used_references.add(reference.__name__)

            if identifier is None:
                # There is no reference, create a new one.
                identifier = unicode(uuid.uuid1())
                reference = service.new_reference(
                    self, name=REFERENCE_TAG, factory=IndexerReferenceValue)
                reference.set_target(content)
                reference.add_tag(identifier)

            # Construct index
            for name, label in indexes:
                if label:
                    entry = result.setdefault(label, {})
                    entry[identifier] = (name, title)

        for name in existing_references.difference(used_references):
            service.delete_reference_by_name(name)

        self._index = result