|
@@ -22,6 +22,7 @@ def full_path_all_pages(expression="*"):
|
22
|
22
|
system_pages = fstools.dirlist(settings.SYSTEM_PAGES_ROOT, expression=expression, rekursive=False)
|
23
|
23
|
system_pages = [os.path.join(settings.PAGES_ROOT, os.path.basename(path)) for path in system_pages]
|
24
|
24
|
pages = fstools.dirlist(settings.PAGES_ROOT, expression=expression, rekursive=False)
|
|
25
|
+ # TODO: strip path, if page or meta.json is missing
|
25
|
26
|
return list(set(system_pages + pages))
|
26
|
27
|
|
27
|
28
|
|
|
@@ -197,15 +198,15 @@ class page_django(page_data):
|
197
|
198
|
name = _("Current")
|
198
|
199
|
meta += f"| {name} \
|
199
|
200
|
| {timestamp_to_datetime(self._request, mtime)} \
|
200
|
|
- | [[{url_page(self._request, self.rel_path)} | Page]] \
|
201
|
|
- | [[{url_page(self._request, self.rel_path, meta=None)} | Meta]]\n"
|
|
201
|
+ | [[{url_page(self.rel_path)} | Page]] \
|
|
202
|
+ | [[{url_page(self.rel_path, meta=None)} | Meta]]\n"
|
202
|
203
|
# History
|
203
|
204
|
for num in reversed(hnl):
|
204
|
205
|
p = page_wrapped(self._request, self._path, history_version=num)
|
205
|
206
|
meta += f"| {num} \
|
206
|
207
|
| {timestamp_to_datetime(self._request, p.modified_time)} \
|
207
|
|
- | [[{url_page(self._request, p.rel_path, history=num)} | Page]] \
|
208
|
|
- | [[{url_page(self._request, p.rel_path, meta=None, history=num)} | Meta]] (with page changes)\n"
|
|
208
|
+ | [[{url_page(p.rel_path, history=num)} | Page]] \
|
|
209
|
+ | [[{url_page(p.rel_path, meta=None, history=num)} | Meta]] (with page changes)\n"
|
209
|
210
|
# Diff
|
210
|
211
|
html_diff = ""
|
211
|
212
|
if self._history_version:
|
|
@@ -222,6 +223,8 @@ class page_django(page_data):
|
222
|
223
|
macros = {
|
223
|
224
|
"subpages": self.macro_subpages,
|
224
|
225
|
"allpages": self.macro_allpages,
|
|
226
|
+ "subpagetree": self.macro_subpagetree,
|
|
227
|
+ "allpagestree": self.macro_allpagestree,
|
225
|
228
|
}
|
226
|
229
|
return mycreole.render(request, txt, self.attachment_path, macros=macros)
|
227
|
230
|
|
|
@@ -231,6 +234,7 @@ class page_django(page_data):
|
231
|
234
|
|
232
|
235
|
def macro_subpages(self, *args, **kwargs):
|
233
|
236
|
allpages = kwargs.pop("allpages", False)
|
|
237
|
+ tree = kwargs.pop("tree", False)
|
234
|
238
|
#
|
235
|
239
|
|
236
|
240
|
def parse_depth(s: str):
|
|
@@ -263,7 +267,19 @@ class page_django(page_data):
|
263
|
267
|
self._request,
|
264
|
268
|
[page_django(self._request, path) for path in full_path_all_pages(expression)]
|
265
|
269
|
)
|
266
|
|
- return pl.html_list(depth=depth, filter_str=filter_str, parent_rel_path=parent_rel_path)
|
|
270
|
+ if tree:
|
|
271
|
+ return page_tree(pl).html()
|
|
272
|
+ else:
|
|
273
|
+ return pl.html_list(depth=depth, filter_str=filter_str, parent_rel_path=parent_rel_path)
|
|
274
|
+
|
|
275
|
+ def macro_allpagestree(self, *args, **kwargs):
|
|
276
|
+ kwargs["allpages"] = True
|
|
277
|
+ kwargs["tree"] = True
|
|
278
|
+ return self.macro_subpages(*args, **kwargs)
|
|
279
|
+
|
|
280
|
+ def macro_subpagetree(self, * args, **kwargs):
|
|
281
|
+ kwargs["tree"] = True
|
|
282
|
+ return self.macro_subpages(*args, **kwargs)
|
267
|
283
|
|
268
|
284
|
|
269
|
285
|
class page_list(list):
|
|
@@ -290,13 +306,50 @@ class page_list(list):
|
290
|
306
|
if last_char != first_char:
|
291
|
307
|
last_char = first_char
|
292
|
308
|
rv += f"=== {first_char}\n"
|
293
|
|
- rv += f"* [[{url_page(self._request, page.rel_path)} | {name} ]]\n"
|
|
309
|
+ rv += f"* [[{url_page(page.rel_path)} | {name} ]]\n"
|
294
|
310
|
return rv
|
295
|
311
|
|
296
|
312
|
def html_list(self, depth=9999, filter_str='', parent_rel_path=''):
|
297
|
313
|
return mycreole.render_simple(self.creole_list(depth, filter_str, parent_rel_path))
|
298
|
314
|
|
299
|
315
|
|
|
316
|
+class page_tree(dict):
|
|
317
|
+ T_PATTERN = "├── "
|
|
318
|
+ L_PATTERN = "└── "
|
|
319
|
+ I_PATTERN = "│ "
|
|
320
|
+ D_PATTERN = " "
|
|
321
|
+
|
|
322
|
+ def __init__(self, pl: page_list):
|
|
323
|
+ super().__init__()
|
|
324
|
+ for page in pl:
|
|
325
|
+ store_item = self
|
|
326
|
+ for entry in page.rel_path.split("/"):
|
|
327
|
+ if not entry in store_item:
|
|
328
|
+ store_item[entry] = {}
|
|
329
|
+ store_item = store_item[entry]
|
|
330
|
+
|
|
331
|
+ def html(self, rel_path=None, fill=""):
|
|
332
|
+ base = self
|
|
333
|
+ try:
|
|
334
|
+ for key in rel_path.split("/"):
|
|
335
|
+ base = base[key]
|
|
336
|
+ except AttributeError:
|
|
337
|
+ rel_path = ''
|
|
338
|
+ #
|
|
339
|
+ rv = ""
|
|
340
|
+ #
|
|
341
|
+ l = len(base)
|
|
342
|
+ for entry in sorted(list(base.keys())):
|
|
343
|
+ l -= 1
|
|
344
|
+ page_path = os.path.join(rel_path, entry)
|
|
345
|
+ page = page_wrapped(None, page_path)
|
|
346
|
+ if page.is_available():
|
|
347
|
+ entry = f'<a href="{url_page(page_path)}">{entry}</a>'
|
|
348
|
+ rv += fill + (self.L_PATTERN if l == 0 else self.T_PATTERN) + entry + "<br>\n"
|
|
349
|
+ rv += self.html(page_path, fill=fill+(self.D_PATTERN if l == 0 else self.I_PATTERN))
|
|
350
|
+ return rv
|
|
351
|
+
|
|
352
|
+
|
300
|
353
|
class page_wrapped(object):
|
301
|
354
|
"""
|
302
|
355
|
This class holds different page and meta instances and decides which will be used in which case.
|
|
@@ -395,6 +448,9 @@ class page_wrapped(object):
|
395
|
448
|
rv = page.attachment_path
|
396
|
449
|
return rv
|
397
|
450
|
|
|
451
|
+ def is_available(self):
|
|
452
|
+ return self._page.is_available() or self._system_page.is_available()
|
|
453
|
+
|
398
|
454
|
@property
|
399
|
455
|
def raw_page_src(self):
|
400
|
456
|
page = self.__page_choose__()
|