Browse Source

macro allpages added and macro subpages fixed

master
Dirk Alders 2 months ago
parent
commit
4116e36e7c
1 changed files with 26 additions and 11 deletions
  1. 26
    11
      pages/page.py

+ 26
- 11
pages/page.py View File

72
 
72
 
73
     def render_text(self, request, txt):
73
     def render_text(self, request, txt):
74
         macros = {
74
         macros = {
75
-            "subpages": self.macro_subpages
75
+            "subpages": self.macro_subpages,
76
+            "allpages": self.macro_allpages,
76
         }
77
         }
77
         return mycreole.render(request, txt, self.attachment_path, macros=macros)
78
         return mycreole.render(request, txt, self.attachment_path, macros=macros)
78
 
79
 
80
+    def macro_allpages(self, *args, **kwargs):
81
+        kwargs["allpages"] = True
82
+        return self.macro_subpages(*args, **kwargs)
83
+
79
     def macro_subpages(self, *args, **kwargs):
84
     def macro_subpages(self, *args, **kwargs):
85
+        allpages = kwargs.pop("allpages", False)
86
+        #
87
+
80
         def parse_depth(s: str):
88
         def parse_depth(s: str):
81
             try:
89
             try:
82
                 return int(s)
90
                 return int(s)
83
             except ValueError:
91
             except ValueError:
84
                 pass
92
                 pass
85
 
93
 
86
-        params = kwargs.get('', '').split(",")
87
-        depth = parse_depth(params[0])
88
-        if len(params) == 2:
89
-            startname = params[1]
90
-        elif depth is None:
91
-            startname = params[0]
94
+        params = kwargs.get('', '')
95
+        startname = ''
96
+        depth = parse_depth(params)
92
         if depth is None:
97
         if depth is None:
93
-            depth = 9999
98
+            params = params.split(",")
99
+            depth = parse_depth(params[0])
100
+            if len(params) == 2:
101
+                startname = params[1]
102
+            elif depth is None:
103
+                startname = params[0]
104
+            if depth is None:
105
+                depth = 9999
94
         #
106
         #
95
         rv = ""
107
         rv = ""
96
         pathlist = fstools.dirlist(settings.PAGES_ROOT, rekursive=False)
108
         pathlist = fstools.dirlist(settings.PAGES_ROOT, rekursive=False)
98
         for path in pathlist:
110
         for path in pathlist:
99
             contentname = self.__folder_content_filter__(os.path.basename(path))
111
             contentname = self.__folder_content_filter__(os.path.basename(path))
100
             #
112
             #
101
-            if contentname.startswith(self._rel_path) and contentname != self._rel_path:
102
-                name = contentname[len(self._rel_path)+1:]
103
-                if name.count('/') <= depth and name.startswith(startname):
113
+            if (contentname.startswith(self._rel_path) or allpages) and contentname != self._rel_path:
114
+                if allpages:
115
+                    name = contentname
116
+                else:
117
+                    name = contentname[len(self._rel_path)+1:]
118
+                if name.count('/') < depth and name.startswith(startname):
104
                     rv += f'  <li><a href="{url_page(self._request, contentname)}">{name}</a></li>\n'
119
                     rv += f'  <li><a href="{url_page(self._request, contentname)}">{name}</a></li>\n'
105
         if len(rv) > 0:
120
         if len(rv) > 0:
106
             rv = "<ul>\n" + rv + "</ul>\n"
121
             rv = "<ul>\n" + rv + "</ul>\n"

Loading…
Cancel
Save