Changes for page Rangee Index

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

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

Summary

Details

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