I'm working on (what I thought) was a simple Trac macro. Basically
it's similar to the TitleIndex() macro but specific for my needs.
Unfortunately I don't really know Python and I've run into a problem I
just can't see. Could someone help me out and take a quick look at
this? I'm tired of banging my head against the wall! :)

I'll post the body of the code below (it's fairly short), but the gist
of the problem is that I'm converting the list of wiki pages into HTML
and getting duplicated data in my output like this:
     * Modem
         * TransmissionProblems
         * Troubleshooting
     * TransmissionProblems
     * Troubleshooting
     * Printers
Note the duplication of "TransmissionProblems" and "Troubleshooting"
which really only exist one time. It appears like some sort of
corruption when the recursion unwinds, but it's not clear to me what
it could be. I suspect it's a Python idiosyncrasy I don't know.

Thanks for any help you can offer!

Here's the body of the code (it's fairly short). Note that list_item()
calls itself recursively.

    def render_macro(self, req, name, content):
        args, kw = parse_args(content)
        current_page = req.args.get('page', 'WikiStart')
        depth = int(kw.get('depth', 100))

        wiki = WikiSystem(self.env)

        def list_item(parentpage,max_depth):
            item = []
 
item.append(html.A(wiki.format_page_name(parentpage[parentpage.rfind('/')
+1:]), href=req.href.wiki(parentpage)))

            child_items = []
            for page in sorted(wiki.get_pages(parentpage+'/')):
                if page.count('/') <= max_depth:
                    if child_items and page.count('/') == max_depth:
                        child_items.append(html(', '))
                    child_items.append(list_item(page,max_depth))
            if child_items:
                if parentpage.count('/') < max_depth-1:
                    item.append(html.UL(child_items))
                else:
                    item.append(html.UL(child_items,class_='wiki-
children-bottom'))

            return html.LI(item)

        page_list = []
        if not args:
            if current_page == '' or current_page == 'WikiStart':
                for parent_page in sorted(wiki.get_pages('')):
                    page_list.append(list_item(parent_page,depth-1))
            else:
                for parent_page in sorted(wiki.get_pages(current_page
+'/')):
 
page_list.append(list_item(parent_page,current_page.count('/')+depth))
        else:
            for parent_page in args:
 
page_list.append(list_item(parent_page,parent_page.count('/')
+depth-1))
        return html.DIV(html.UL(page_list),class_='wiki-children')



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to