Changes for page Rangee Index

Last modified by Tobias Wintrich on 2025/10/31 08:26

From version 16.1
edited by Tobias Wintrich
on 2025/10/14 16:35
Change comment: There is no comment for this version
To version 17.1
edited by Tobias Wintrich
on 2025/10/14 16:36
Change comment: There is no comment for this version

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,15 +1,20 @@
1 1  {{python}}
2 2  from xwiki import XWikiContextProvider
3 3  
4 -# Kontext-Objekte
5 5  xcontext = XWikiContextProvider().get()
6 6  xwiki = xcontext.getWiki()
7 7  services = xcontext.services
8 8  doc = xcontext.doc
9 -depth = wikimacro.parameters.get("depth", 0)
8 +wikimacro = locals().get('wikimacro', None)
9 +depth = 0
10 +if wikimacro and wikimacro.parameters.get("depth"):
11 + depth = int(wikimacro.parameters.get("depth"))
10 10  
11 -# Sprache setzen
12 -locale = "" if str(xcontext.locale) == "de" else str(xcontext.locale)
13 +# Sprache bestimmen
14 +if str(xcontext.locale) == 'de':
15 + locale = ''
16 +else:
17 + locale = str(xcontext.locale)
13 13  
14 14  def get_children(parent_fullname):
15 15   query = services.query.xwql("where doc.parent = :doc and doc.hidden = 0 order by doc.title asc")
... ... @@ -20,14 +20,15 @@
20 20   for child_name in get_children(parent_fullname):
21 21   rdoc = xwiki.getDocument(child_name).getTranslatedDocument()
22 22   if locale == rdoc.getLanguage():
23 - li_class = "jstree-open" if current_depth > 0 else ""
24 - html += f'<li class="{li_class}">[[{rdoc.getDisplayTitle()}>>{rdoc.fullName}]]</li>'
28 + li_class = ""
29 + if current_depth > 0:
30 + li_class = "jstree-open"
31 + html += '<li class="' + li_class + '">[[{0}>>{1}]]</li>'.format(rdoc.getDisplayTitle(), rdoc.fullName)
25 25   if current_depth < depth:
26 26   html += render_tree(rdoc.fullName, current_depth + 1)
27 27   html += "</ul>"
28 28   return html
29 29  
30 -html_output = render_tree(doc.fullName, 0)
31 -print(html_output)
37 +print(render_tree(doc.fullName, 0))
32 32  {{/python}}
33 33