Example #1
0
    def metadataFor(self,page):
        """
        Make a catalog-brain-like object containing page's principal metadata.

        Given a real page object, this returns a PageBrain which emulates
        a catalog brain object (search result), for use when there is no
        catalog. All PAGE_METADATA fields will be included, plus a few more
        for backwards compatibility with old skin templates.

        Warning: fields such as the parents list may be
        copies-by-reference, and should not be mutated.
        """
        class PageBrain(SimpleItem): # XXX why a SimpleItem ?
            def __init__(self,obj): self._obj = obj
            def getObject(self): return self._obj
        brain = PageBrain(page)
        for attr in PAGE_METADATA+['page_url','title_or_id']:
            # protect against import or attr errors when a page type has
            # been uninstalled
            try:
                # don't acquire these properties
                # aq_base won't be present during unit tests.. messy
                setattr(brain, attr,
                        absattr(getattr(getattr(page,'aq_base',page),attr,None)))
            except (ImportError, AttributeError):
                setattr(brain, attr, None)
        #XXX not using now.. leave blank so tests pass
        brain.linkTitle = '' 
        return brain
Example #2
0
    def reparent(self, parents=[], REQUEST=None, pagename=None):
        """
        Move this page under the named parent pages in the wiki outline.

        parent page names may be passed in several ways:
        - in the parents argument (a list or string of page names)
        - in the pagename argument (a single name)
        (this last is to support the page management form).

        Page names may be ids, or fuzzy, even partial. Any which do not
        resolve to an existing page or are duplicates will be ignored.
        """
        if not self.checkSufficientId(REQUEST):
            return self.denied(
                _("Sorry, this wiki doesn't allow anonymous reparenting. Please configure a username in options first."
                  ))

        oldparents = self.getParents()
        # clean the arguments carefully to avoid parenting anomalies
        # page mgmt form must use pagename field:
        pagename = pagename and self.tounicode(pagename)
        if pagename:
            parents = [pagename]
        # or parents might be a string
        elif type(parents) != ListType:
            parents = [parents]
        # empty strings are common, remove before calling pageWithFuzzyName
        parents = filter(lambda x: x, parents)
        # to unicode
        parents = map(self.tounicode, parents)
        # look up the page (brain) corresponding to each (fuzzy) parent name
        parents = map(lambda x: self.pageWithFuzzyName(x, allow_partial=1),
                      parents)
        # strip out Nones (pages not found)
        parents = filter(lambda x: x, parents)
        # convert back to proper page names
        parents = map(lambda x: absattr(x.Title), parents)
        # remove any duplicates
        uniqueparents = []
        for p in parents:
            if not p in uniqueparents: uniqueparents.append(p)

        # finally - update our parents property, the outline cache, and catalog
        self.setParents(uniqueparents)
        self.wikiOutline().reparent(self.pageName(), uniqueparents)
        self.index_object()

        # send mail if appropriate
        self.sendMailToEditSubscribers(
            '%s was reparented from %s to %s.' %
            (self.pageName(), oldparents, uniqueparents),
            REQUEST=REQUEST,
            subject='(reparented)')

        if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST['URL1'])
    def reparent(self, parents=[], REQUEST=None, pagename=None):
        """
        Move this page under the named parent pages in the wiki outline.

        parent page names may be passed in several ways:
        - in the parents argument (a list or string of page names)
        - in the pagename argument (a single name)
        (this last is to support the page management form).

        Page names may be ids, or fuzzy, even partial. Any which do not
        resolve to an existing page or are duplicates will be ignored.
        """
        if not self.checkSufficientId(REQUEST):
            return self.denied(
                _("Sorry, this wiki doesn't allow anonymous reparenting. Please configure a username in options first."))

        oldparents = self.getParents()
        # clean the arguments carefully to avoid parenting anomalies
        # page mgmt form must use pagename field:
        if pagename:
            parents = [pagename] 
        # or parents might be a string
        elif type(parents) != ListType:
            parents = [parents] 
        # empty strings are common, remove before calling pageWithFuzzyName
        parents = filter(lambda x:x, parents)
        # look up the page (brain) corresponding to each (fuzzy) parent name
        parents = map(lambda x:self.pageWithFuzzyName(x,allow_partial=1),
                      parents)
        # strip out Nones (pages not found)
        parents = filter(lambda x:x, parents)
        # convert back to proper page names
        parents = map(lambda x:absattr(x.Title), parents)
        # remove any duplicates
        uniqueparents = []
        for p in parents:
            if not p in uniqueparents: uniqueparents.append(p)
            
        # finally - update our parents property, the outline cache, and catalog
        self.setParents(uniqueparents) 
        self.wikiOutline().reparent(self.pageName(),uniqueparents)
        self.index_object()

        # send mail if appropriate
        self.sendMailToEditSubscribers(
            '%s was reparented from %s to %s.' % (
              self.pageName(), oldparents, uniqueparents),
            REQUEST=REQUEST,
            subject='(reparented)')

        if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST['URL1'])
Example #4
0
    def metadataFor(self, page):
        """
        Make a catalog-brain-like object containing page's principal metadata.

        Given a real page object, this returns a PageBrain which emulates
        a catalog brain object (search result), for use when there is no
        catalog. All PAGE_METADATA fields will be included, plus a few more
        for backwards compatibility with old skin templates.

        Warning: fields such as the parents list may be
        copies-by-reference, and should not be mutated.

        Since we're ensuring that we always have a catalog now (since 0.60),
        this thing should not be needed any more. XXX remove this method?
        """
        if getattr(page, 'meta_type', None) != PAGE_METATYPE:
            raise TypeError(str(page) + ' is not a ' + PAGE_METATYPE)

        class PageBrain(SimpleItem):  # XXX why a SimpleItem ?
            def __init__(self, obj):
                self._obj = obj

            def getObject(self):
                return self._obj

        brain = PageBrain(page)
        for attr in PAGE_METADATA + ['page_url', 'title_or_id']:
            # protect against import or attr errors when a page type has
            # been uninstalled
            try:
                # don't acquire these properties
                # aq_base won't be present during unit tests.. messy
                setattr(
                    brain, attr,
                    absattr(getattr(getattr(page, 'aq_base', page), attr,
                                    None)))
            except (ImportError, AttributeError):
                setattr(brain, attr, None)
        #XXX not using now.. leave blank so tests pass
        brain.linkTitle = ''
        return brain
Example #5
0
 def ensureValidParents(self):
     """
     Ensure that this page's parents are all valid, and reindex if needed.
     """
     parents = self.getParents()
     # convert to exact page names, filtering out any which don't exist
     cleanedupparents = map(
         lambda x: absattr(x.Title),
         filter(lambda x: x, map(lambda x: self.pageWithName(x), parents)))
     # make sure we're not parented under ourself
     if self.pageName() in cleanedupparents:
         cleanedupparents.remove(self.pageName())
     # sort
     cleanedupparents.sort()
     # if changed, save and reindex
     if cleanedupparents != parents:
         BLATHER("adjusting %s's parents from %s to %s" %
                 (self.pageName(), parents, cleanedupparents))
         self.setParents(cleanedupparents)
         self.index_object(
         )  #XXX only need to update parents index & metadata
 def ensureValidParents(self):
     """
     Ensure that this page's parents are all valid, and reindex if needed.
     """
     parents = self.getParents()
     # convert to exact page names, filtering out any which don't exist
     cleanedupparents = map(lambda x:absattr(x.Title),
                            filter(lambda x:x,
                                   map(lambda x:self.pageWithName(x),
                                       parents)))
     # make sure we're not parented under ourself
     if self.pageName() in cleanedupparents:
         cleanedupparents.remove(self.pageName())
     # sort
     cleanedupparents.sort()
     # if changed, save and reindex
     if cleanedupparents != parents:
         BLATHER("adjusting %s's parents from %s to %s" % 
              (self.pageName(), parents, cleanedupparents))
         self.setParents(cleanedupparents)
         self.index_object() #XXX only need to update parents index & metadata
Example #7
0
 def offspringIdsAsList(self, REQUEST=None):
     """
     Return my offsprings' page ids as a flat list.
     """
     return map(lambda x: absattr(self.pageWithNameOrId(x).id),
                self.offspringAsList())
Example #8
0
 def childrenIdsAsList(self, REQUEST=None):
     """
     Return all my children's page ids as a flat list.
     """
     return map(lambda x: absattr(self.pageWithNameOrId(x).id),
                self.childrenAsList())
 def offspringIdsAsList(self, REQUEST=None):
     """
     Return my offsprings' page ids as a flat list.
     """
     return map(lambda x:absattr(self.pageWithNameOrId(x).id),
                self.offspringAsList())
Example #10
0
 def childrenIdsAsList(self, REQUEST=None):
     """
     Return all my children's page ids as a flat list.
     """
     return map(lambda x:absattr(self.pageWithNameOrId(x).id),
                self.childrenAsList())