###################################################################### # zwiki page parenting functionality from string import join from types import * from urllib import quote import Acquisition import Permissions ########################################################################### # CLASS ZwikiParentsMixin # RESPONSIBILITIES help generate table of contents # COLLABORATORS ZWikiPage ########################################################################### class ZWikiParentsMixin: """ This mix-in class encapsulates ZWikiPage's page parenting functionality. I had to leave several related code fragments over in ZWikiPage.py but I think it's worth doing. """ ###################################################################### # CLASS VARIABLES ###################################################################### parents = [] _properties=( {'id':'parents', 'type': 'lines', 'mode': 'w'}, ) __ac_permissions__=( (Permissions.Reparent, ('reparent',)), ) ###################################################################### # METHOD CATEGORY: parenting ###################################################################### def reparent(self, parents=None, REQUEST=None): """Reset parents property according to request.""" if parents is None: parents = REQUEST.get('parents', None) if parents is None: self.parents = [] else: if type(parents) != ListType: parents = [parents] self.parents = parents self._set_last_editor(REQUEST) if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST['URL1']) def get_ancestors(self): """Return a trimmed nesting structure indicating this page's ancestors. See the WikiNesting docstring for nestings structure description.""" container = self.aq_parent ancestors = {} offspring = {} tops = {} # Ancestors that have no parents. todo = {self.id(): None} while todo: doing = todo todo = {} for i in doing.keys(): if ancestors.has_key(i): continue # We've already collected this one. else: if not hasattr(container, i): continue # Absent - ignore it. ancestors[i] = None obj = container[i] if not hasattr(obj, 'parents'): continue parents = obj.parents if type(parents) != ListType: # SKWM parents = [] if parents: for p in parents: if offspring.has_key(p): offspring[p].append(i) else: offspring[p] = [i] todo[p] = None else: tops[i] = None # Ok, now go back down, unravelling each forebear only once: tops = tops.keys() tops.sort did = {}; got = [] for t in tops: got.append(descend_ancestors(t, ancestors, did, offspring)) return got def context(self, REQUEST=None, with_siblings=0, enlarge_current=0): """Return HTML showing this page's parents and siblings.""" myid = self.id() if with_siblings: try: nesting = WikiNesting(self.aq_parent).get_up_and_back(myid) except: nesting=() else: nesting = self.get_ancestors() if (len(nesting) == 0 or (len(nesting) == 1 and len(nesting[0]) == 1)) and not enlarge_current: return " " #SKWM XXX if self.aq_parent.title: #titletxt = ' for %s' % (self.aq_parent.title) titletxt = '%s ' % (self.aq_parent.title) else: titletxt = '' #SKWM XXX #special case: if we are creating a new page, display it's title if REQUEST.has_key('page') and REQUEST['page'] is not myid: myid = REQUEST['page'] nesting = self.deepappend(nesting, myid) suppress_hyperlink=1 else: suppress_hyperlink=0 #SKWM XXX #detect when parents have gotten confused & reset if necessary hierarchy = present_nesting(myid, nesting, self.wiki_url(), enlarge_current=enlarge_current, suppress_hyperlink=suppress_hyperlink) if hierarchy == '': self.parents = [] hierarchy = present_nesting(myid, nesting, self.wiki_url(), enlarge_current=enlarge_current, suppress_hyperlink=suppress_hyperlink) # return '