Added the macro subpages
This commit is contained in:
джерело
dfcf8e15fd
коміт
7f357e9a3a
2
mycreole
2
mycreole
@ -1 +1 @@
|
||||
Subproject commit 8a2da2b84379df346d4f24c8fc5c1e6fe62c75e9
|
||||
Subproject commit 2abea3c4aec4716a2609828faddcd6b6e4c7728e
|
@ -1,27 +0,0 @@
|
||||
from django.urls.base import reverse
|
||||
|
||||
# TODO: Add a filter to show all subpages <<piki-subpages>> and add it to settings and help
|
||||
|
||||
|
||||
"""
|
||||
def page_link_filter(text):
|
||||
render_txt = ''
|
||||
while len(text) > 0:
|
||||
try:
|
||||
pos = text.index('[[page:')
|
||||
except ValueError:
|
||||
pos = len(text)
|
||||
print(pos)
|
||||
render_txt += text[:pos]
|
||||
text = text[pos + 7:]
|
||||
if len(text):
|
||||
pos = text.index(']]')
|
||||
try:
|
||||
rel_path = int(text[:pos])
|
||||
except ValueError:
|
||||
render_txt += "[[page:" + text[:pos + 2]
|
||||
else:
|
||||
render_txt += '[[%s|%s]]' % (reverse('pages-pages', kwargs={'rel_path': rel_path}), rel_path)
|
||||
text = text[pos + 2:]
|
||||
return render_txt
|
||||
"""
|
@ -21,7 +21,12 @@ MAIN = mycreole.render_simple(_(
|
||||
CREOLE = mycreole.mycreole_help_pagecontent()
|
||||
CREOLE += mycreole.render_simple("""
|
||||
= Piki Markup
|
||||
{{{[[rel_path_to_page|Name]]}}} will result in a Link to the given wiki page.
|
||||
| {{{[[rel_path_to_page|Name]]}}} | will result in a Link to the given wiki page. |
|
||||
| {{{<<subpages>>}}} | will result in a list of all subpages below the current page. |
|
||||
| {{{<<subpages=N,startswith>>}}} | will result in a list of subpages below the current page.\
|
||||
N will reduce the depth of the subpages to N. \
|
||||
startswith will reduce the hits to all pages starting with the given string.
|
||||
You can give one or both Parameters. |
|
||||
""")
|
||||
|
||||
ACCESS = mycreole.render_simple(_("""
|
||||
|
@ -29,9 +29,15 @@ class creol_page(object):
|
||||
def attachment_path(self):
|
||||
return os.path.join(self.content_folder_name, self.FOLDER_ATTACHMENTS)
|
||||
|
||||
def __content_folder_filter__(self, folder):
|
||||
return folder.replace('/', '::')
|
||||
|
||||
def __folder_content_filter__(self, folder):
|
||||
return folder.replace('::', '/')
|
||||
|
||||
@property
|
||||
def content_folder_name(self):
|
||||
return self._rel_path.replace('/', '::')
|
||||
return self.__content_folder_filter__(self._rel_path)
|
||||
|
||||
@property
|
||||
def content_file_name(self):
|
||||
@ -54,7 +60,46 @@ class creol_page(object):
|
||||
|
||||
def render_to_html(self, request):
|
||||
if self.is_available():
|
||||
return mycreole.render(request, self.raw_page_src, self.attachment_path, "next_anchor")
|
||||
return self.render_text(request, self.raw_page_src)
|
||||
else:
|
||||
messages.unavailable_msg_page(request, self._rel_path)
|
||||
return ""
|
||||
|
||||
def render_text(self, request, txt):
|
||||
macros = {
|
||||
"subpages": self.macro_subpages
|
||||
}
|
||||
return mycreole.render(request, txt, self.attachment_path, "next_anchor", macros=macros)
|
||||
|
||||
def macro_subpages(self, *args, **kwargs):
|
||||
def parse_depth(s: str):
|
||||
try:
|
||||
return int(s)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
params = kwargs.get('').split(",")
|
||||
depth = parse_depth(params[0])
|
||||
if len(params) == 2:
|
||||
startname = params[1]
|
||||
elif depth is None:
|
||||
startname = params[0]
|
||||
if depth is None:
|
||||
depth = 9999
|
||||
#
|
||||
rv = ""
|
||||
pathlist = fstools.dirlist(settings.PAGES_ROOT, rekursive=False)
|
||||
pathlist.sort()
|
||||
for path in pathlist:
|
||||
dirname = os.path.basename(path)
|
||||
contentname = self.__folder_content_filter__(dirname)
|
||||
#
|
||||
my_dirname = self.__content_folder_filter__(self._rel_path)
|
||||
#
|
||||
if dirname.startswith(my_dirname) and dirname != my_dirname:
|
||||
name = contentname[len(self._rel_path)+1:]
|
||||
if name.count('/') <= depth and name.startswith(startname):
|
||||
rv += f' <li><a href="{contentname}">{name}</a></li>\n'
|
||||
if len(rv) > 0:
|
||||
rv = "<ul>\n" + rv + "</ul>\n"
|
||||
return rv
|
||||
|
@ -17,6 +17,9 @@ from themes import Context
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# TODO: /!\ Deactivate self registration
|
||||
# TODO: /!\ Remove config and add config_example with data from mm_tmux /!\
|
||||
|
||||
|
||||
def root(request):
|
||||
return HttpResponseRedirect(url_page(request, config.STARTPAGE))
|
||||
@ -79,7 +82,7 @@ def edit(request, rel_path):
|
||||
# TODO: Add translation
|
||||
title=_("Edit page %s") % repr(p.title),
|
||||
upload_path=p.attachment_path,
|
||||
page_content=mycreole.render(request, page_txt, p.attachment_path, 'next-anchor')
|
||||
page_content=p.render_text(request, page_txt)
|
||||
)
|
||||
return render(request, 'pages/page_form.html', context=context)
|
||||
else:
|
||||
|
@ -169,9 +169,6 @@ MYCREOLE_BAR = {
|
||||
'navibar': 'pages.context.navigationbar',
|
||||
'menubar': 'pages.context.menubar',
|
||||
}
|
||||
MYCREOLE_EXT_FILTERS = [
|
||||
# 'pages.creole.page_link_filter',
|
||||
]
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||
|
||||
|
Завантаження…
x
Посилання в новій задачі
Block a user