Kaynağa Gözat

macro allpages added and macro subpages fixed

master
Dirk Alders 2 ay önce
ebeveyn
işleme
4116e36e7c
1 değiştirilmiş dosya ile 26 ekleme ve 11 silme
  1. 26
    11
      pages/page.py

+ 26
- 11
pages/page.py Dosyayı Görüntüle

@@ -72,25 +72,37 @@ class creol_page(object):
72 72
 
73 73
     def render_text(self, request, txt):
74 74
         macros = {
75
-            "subpages": self.macro_subpages
75
+            "subpages": self.macro_subpages,
76
+            "allpages": self.macro_allpages,
76 77
         }
77 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 84
     def macro_subpages(self, *args, **kwargs):
85
+        allpages = kwargs.pop("allpages", False)
86
+        #
87
+
80 88
         def parse_depth(s: str):
81 89
             try:
82 90
                 return int(s)
83 91
             except ValueError:
84 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 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 107
         rv = ""
96 108
         pathlist = fstools.dirlist(settings.PAGES_ROOT, rekursive=False)
@@ -98,9 +110,12 @@ class creol_page(object):
98 110
         for path in pathlist:
99 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 119
                     rv += f'  <li><a href="{url_page(self._request, contentname)}">{name}</a></li>\n'
105 120
         if len(rv) > 0:
106 121
             rv = "<ul>\n" + rv + "</ul>\n"

Loading…
İptal
Kaydet