Utilisation de l'id du nœud racine, plutôt que l'id de l'objet.
[MosaicDocument.git] / skins / xml_nav_tree.py
1 ##parameters=filter=''
2 from ZTUtils import SimpleTreeMaker
3 stm = SimpleTreeMaker()
4 def replaceXMLEntities(text) :
5 for c, ent in (('<', '&lt;'), ('>', '&gt;'), ('&', '&amp;')) :
6 text = text.replace(c, ent)
7 return text
8
9 from string import maketrans
10 rmBadAttrChars = maketrans('<&"', ' ')
11
12 filter = filter.split(',')
13
14 root = context
15 context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
16 print '<xml>'
17 for ob in context.listNearestFolderContents(contentFilter={'portal_type':filter}) :
18 icon = context.restrictedTraverse(ob.getIcon())
19 state = 0
20 if not getattr(ob, 'isPortalContent', False) :
21 state = ob.listNearestFolderContents(contentFilter={'portal_type':filter}) and "-1" or "0"
22 row = '<row name="%(name)s" url="%(url)s" icon="%(icon)s" height="%(height)d" width="%(width)d" state="%(state)s" description="%(description)s">%(title)s</row>' % {
23 'name' : stm.node(ob).id,
24 'url' : ob.absolute_url(),
25 'title' : ' '+replaceXMLEntities(ob.title_or_id()),
26 'description' : ob.Description().translate(rmBadAttrChars),
27 'icon' : icon.absolute_url(),
28 'height' : icon.height,
29 'width' : icon.width,
30 'state' : state
31 }
32 print row
33
34
35 print '</xml>'
36
37 return printed