Logo Search packages:      
Sourcecode: zope-cmfplone version File versions

def zope-cmfplone-2.0.4::StatelessTreeNav::StatelessTreeBuilder::buildFlatMenuStructure (   self,
  batchSize = 65535,
  batchStart = None 
)

Constructs a Menu

Definition at line 207 of file StatelessTreeNav.py.

00207                                                                         :
        """
        Constructs a Menu
        """
        #print 'build...'
        import time
        t=time.time()
        list,itemtotal = self.buildMenuStructure()

        l=[]
        res = {'list':l,'batchSize':batchSize,'batchStart':batchStart,'next':0,'prev':0}

        itemcounter=0
        menucounter=0
        curpos=0

        skipself = self.skipIndex_html and self.object.getId()=='index_html'

        # Opening
        for item in list :
            act = 0
            current=0

            for sibling in item['siblings'] :
                current = 0

                if (self.skipIndex_html and sibling.getId()=='index_html') or sibling.getId()=='talkback':
                    continue

                if (sibling == item['object']) :
                    act = 1
                    if item==list[-2] and (skipself or self.showFolderishChildrenOnly and not self.showNonFolderishObject):
                        # deepest level
                        current=1
                        curpos=itemcounter

                else :
                    act = 0
                    current=0

                if sibling == self.object and not skipself and (self.showNonFolderishObject or not self.showFolderishChildrenOnly):
                    current=1
                    curpos=itemcounter

                if skipself and self.object == sibling:
                    continue

                lv = self.getLevel(sibling)
                r={'level':lv,'indent':lv - self.topLevel,'open':act,
                        'object':sibling,'title':sibling.title_or_id(),'iscurrent':current}

                if len(l) :
                    r['indentdiff'] = r['indent'] - l[-1]['indent']
                else:
                    r['indentdiff'] = 0

                itemcounter = itemcounter + 1

                if r['level'] >= self.topLevel and r['level'] <= self.bottomLevel:
                    l.append(r)

                if (act == 1) :
                    break

        # Closing
        list.reverse()

        ready=0
        for item in list :
            act = 0
            if ready: break

            for sibling in item['siblings'] :

                if (sibling == item['object']) :
                    act = 1
                    continue

                if (self.skipIndex_html and sibling.getId()=='index_html') or sibling.getId()=='talkback':
                    continue

                if (act == 1) :
                    itemcounter = itemcounter + 1
                    lv = self.getLevel(sibling)

                    r={'level':lv,'indent':lv - self.topLevel,'open':0,'object':sibling}

                    if len(l) :
                        r['indentdiff'] = r['indent'] - l[-1]['indent']
                    else:
                        r['indentdiff']=0

                    if sibling:
                        r.update({'title':sibling.title_or_id()})

                    if r['level'] >= self.topLevel and r['level'] <= self.bottomLevel:
                        l.append(r)

        # and now extract the correct batch out of the data
        if batchStart is None:
            start=0
        else:
            start=batchStart

        end=start+batchSize

        if batchStart is None and not start <= curpos < end:
            res['prevBatchStart'] = max(start - batchSize, 0)
            res['prev']=1
            start = max(curpos - batchSize/2, 0)
            end=start + batchSize
        elif batchStart > 0:
            res['prev']=1
            res['prevBatchStart']=max(0,batchStart-batchSize)

        if end < len(l):
            res['nextBatchStart'] = end
            res['next']=1

        l = l[start:end]

        #force the parents to be in the list
        if self.forceParentsInBatch and start and l[0]['indent']:
            for p in list[1:]:
                sibling=p['object']
                lv = self.getLevel(sibling)
                if lv < self.topLevel:
                    break

                if p != list[-1]:
                    indentdiff=1
                else:
                    indentdiff=0

                r={'level':lv,'indent':lv - self.topLevel,'open':0,'object':sibling,'indentdiff':indentdiff}
                if not sibling in [o['object'] for o in l]:
                    l.insert(0,r)

        #set indentdiff for the first element
        if len(l):
            l[0]['indentdiff']=l[0]['indent']

        res['list']=l
        return res

allow_class(StatelessTreeBuilder)
allow_class(StatelessTreeBuilder)


Generated by  Doxygen 1.6.0   Back to index