Moved page list creation to new class page_list. Usage of this class for search results
This commit is contained in:
parent
859d073a7e
commit
dd21345eb7
2
fstools
2
fstools
@ -1 +1 @@
|
|||||||
Subproject commit c10e8792abb05671dab6de51cdadda3bf8ead50f
|
Subproject commit 9237f6f7f77eed79b8163077c1b4d87189193fbe
|
@ -54,6 +54,28 @@ def navigationbar(context, request, caller_name, **kwargs):
|
|||||||
finalise_bar(request, bar)
|
finalise_bar(request, bar)
|
||||||
|
|
||||||
|
|
||||||
|
def menubar(context, request, caller_name, **kwargs):
|
||||||
|
bar = context[context.MENUBAR]
|
||||||
|
menubar_users(bar, request)
|
||||||
|
add_help_menu(request, bar, "current_help_page" in kwargs)
|
||||||
|
add_index_menu(request, bar, kwargs.get("rel_path", ''))
|
||||||
|
finalise_bar(request, bar)
|
||||||
|
|
||||||
|
|
||||||
|
def actionbar(context, request, caller_name, **kwargs):
|
||||||
|
bar = context[context.ACTIONBAR]
|
||||||
|
if caller_name == 'page':
|
||||||
|
if access.write_page(request, kwargs["rel_path"]):
|
||||||
|
add_edit_menu(request, bar, kwargs["rel_path"])
|
||||||
|
if access.modify_attachment(request, kwargs["rel_path"]):
|
||||||
|
add_manageupload_menu(request, bar, kwargs['upload_path'])
|
||||||
|
if access.read_page(request, kwargs["rel_path"]):
|
||||||
|
add_meta_menu(request, bar, kwargs["rel_path"])
|
||||||
|
elif caller_name == 'helpview':
|
||||||
|
actionbar_add_help(context, request, **kwargs)
|
||||||
|
finalise_bar(request, bar)
|
||||||
|
|
||||||
|
|
||||||
def add_back_menu(request, bar):
|
def add_back_menu(request, bar):
|
||||||
bar.append_entry(
|
bar.append_entry(
|
||||||
BACK_UID, # uid
|
BACK_UID, # uid
|
||||||
@ -76,14 +98,6 @@ def navigation_entry_parameters(request, path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def menubar(context, request, caller_name, **kwargs):
|
|
||||||
bar = context[context.MENUBAR]
|
|
||||||
menubar_users(bar, request)
|
|
||||||
add_help_menu(request, bar, "current_help_page" in kwargs)
|
|
||||||
add_index_menu(request, bar, kwargs.get("rel_path", ''))
|
|
||||||
finalise_bar(request, bar)
|
|
||||||
|
|
||||||
|
|
||||||
def add_help_menu(request, bar, active):
|
def add_help_menu(request, bar, active):
|
||||||
bar.append_entry(
|
bar.append_entry(
|
||||||
HELP_UID, # uid
|
HELP_UID, # uid
|
||||||
@ -106,20 +120,6 @@ def add_index_menu(request, bar, rel_path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def actionbar(context, request, caller_name, **kwargs):
|
|
||||||
bar = context[context.ACTIONBAR]
|
|
||||||
if caller_name == 'page':
|
|
||||||
if access.write_page(request, kwargs["rel_path"]):
|
|
||||||
add_edit_menu(request, bar, kwargs["rel_path"])
|
|
||||||
if access.modify_attachment(request, kwargs["rel_path"]):
|
|
||||||
add_manageupload_menu(request, bar, kwargs['upload_path'])
|
|
||||||
if access.read_page(request, kwargs["rel_path"]):
|
|
||||||
add_meta_menu(request, bar, kwargs["rel_path"])
|
|
||||||
elif caller_name == 'helpview':
|
|
||||||
actionbar_add_help(context, request, **kwargs)
|
|
||||||
finalise_bar(request, bar)
|
|
||||||
|
|
||||||
|
|
||||||
def add_edit_menu(request, bar, rel_path):
|
def add_edit_menu(request, bar, rel_path):
|
||||||
bar.append_entry(
|
bar.append_entry(
|
||||||
EDIT_UID, # uid
|
EDIT_UID, # uid
|
||||||
|
@ -197,39 +197,57 @@ class creole_page(base_page):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
params = kwargs.get('', '')
|
params = kwargs.get('', '')
|
||||||
startname = ''
|
filter_str = ''
|
||||||
depth = parse_depth(params)
|
depth = parse_depth(params)
|
||||||
if depth is None:
|
if depth is None:
|
||||||
params = params.split(",")
|
params = params.split(",")
|
||||||
depth = parse_depth(params[0])
|
depth = parse_depth(params[0])
|
||||||
if len(params) == 2:
|
if len(params) == 2:
|
||||||
startname = params[1]
|
filter_str = params[1]
|
||||||
elif depth is None:
|
elif depth is None:
|
||||||
startname = params[0]
|
filter_str = params[0]
|
||||||
if depth is None:
|
|
||||||
depth = 9999
|
|
||||||
#
|
#
|
||||||
rv = ""
|
rv = ""
|
||||||
# create a rel_path list
|
# create a page_list
|
||||||
pathlist = [base_page(path).rel_path for path in fstools.dirlist(settings.PAGES_ROOT, rekursive=False)]
|
|
||||||
# sort basename
|
|
||||||
pathlist.sort(key=os.path.basename)
|
|
||||||
|
|
||||||
last_char = None
|
|
||||||
for contentname in pathlist:
|
|
||||||
#
|
|
||||||
if (contentname.startswith(self.rel_path) or allpages) and contentname != self.rel_path:
|
|
||||||
if allpages:
|
if allpages:
|
||||||
name = contentname
|
expression = "*"
|
||||||
|
parent_rel_path = ""
|
||||||
else:
|
else:
|
||||||
name = contentname[len(self.rel_path)+1:]
|
expression = os.path.basename(self._path) + 2 * self.SPLITCHAR + "*"
|
||||||
if name.count('/') < depth and name.startswith(startname):
|
parent_rel_path = self.rel_path
|
||||||
if last_char != os.path.basename(name)[0].upper():
|
pl = page_list(
|
||||||
last_char = os.path.basename(name)[0].upper()
|
self._request,
|
||||||
if last_char is not None:
|
[creole_page(self._request, path) for path in fstools.dirlist(settings.PAGES_ROOT, expression=expression, rekursive=False)]
|
||||||
rv += "</ul>\n"
|
)
|
||||||
rv += f'<h3>{last_char}</h3>\n<ul>\n'
|
return pl.html_list(depth=depth, filter_str=filter_str, parent_rel_path=parent_rel_path)
|
||||||
rv += f' <li><a href="{url_page(self._request, contentname)}">{name}</a></li>\n'
|
|
||||||
if len(rv) > 0:
|
|
||||||
rv += "</ul>\n"
|
class page_list(list):
|
||||||
|
def __init__(self, request, *args, **kwargs):
|
||||||
|
self._request = request
|
||||||
|
return super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def sort_basename(self):
|
||||||
|
return list.sort(self, key=lambda x: os.path.basename(x.rel_path))
|
||||||
|
|
||||||
|
def creole_list(self, depth=None, filter_str='', parent_rel_path=''):
|
||||||
|
self.sort_basename()
|
||||||
|
depth = depth or 9999 # set a random high value if None
|
||||||
|
#
|
||||||
|
parent_rel_path = parent_rel_path + "/" if len(parent_rel_path) > 0 else ""
|
||||||
|
#
|
||||||
|
rv = ""
|
||||||
|
last_char = None
|
||||||
|
for page in self:
|
||||||
|
name = page.rel_path[len(parent_rel_path):]
|
||||||
|
if name.startswith(filter_str) and name != filter_str:
|
||||||
|
if name.count('/') < depth:
|
||||||
|
first_char = os.path.basename(name)[0].upper()
|
||||||
|
if last_char != first_char:
|
||||||
|
last_char = first_char
|
||||||
|
rv += f"=== {first_char}\n"
|
||||||
|
rv += f"* [[{url_page(self._request, page.rel_path)} | {name} ]]\n"
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
def html_list(self, depth=9999, filter_str='', parent_rel_path=''):
|
||||||
|
return mycreole.render_simple(self.creole_list(depth, filter_str, parent_rel_path))
|
||||||
|
@ -15,7 +15,7 @@ from .context import context_adaption
|
|||||||
from .forms import EditForm
|
from .forms import EditForm
|
||||||
from .help import help_pages
|
from .help import help_pages
|
||||||
import mycreole
|
import mycreole
|
||||||
from .page import creole_page
|
from .page import creole_page, page_list
|
||||||
from .search import whoosh_search
|
from .search import whoosh_search
|
||||||
from themes import Context
|
from themes import Context
|
||||||
|
|
||||||
@ -110,15 +110,13 @@ def search(request):
|
|||||||
if sr is None:
|
if sr is None:
|
||||||
django_messages.error(request, _('Invalid search pattern: %s') % repr(search_txt))
|
django_messages.error(request, _('Invalid search pattern: %s') % repr(search_txt))
|
||||||
sr = []
|
sr = []
|
||||||
page_content = "= Searchresults\n"
|
pl = page_list(request, [creole_page(request, rel_path) for rel_path in sr])
|
||||||
for rel_path in sr:
|
|
||||||
p = creole_page(request, rel_path)
|
|
||||||
page_content += f"[[/page/{rel_path}|{p.title}]]\n"
|
|
||||||
#
|
#
|
||||||
context_adaption(
|
context_adaption(
|
||||||
context,
|
context,
|
||||||
request,
|
request,
|
||||||
page_content=mycreole.render_simple(page_content)
|
title=_("Searchresults"),
|
||||||
|
page_content=mycreole.render_simple(pl.creole_list())
|
||||||
)
|
)
|
||||||
return render(request, 'pages/page.html', context=context)
|
return render(request, 'pages/page.html', context=context)
|
||||||
|
|
||||||
|
@ -176,14 +176,14 @@ for property_name in USER_CONFIG_DEFAULTS:
|
|||||||
if SECRET_KEY is None:
|
if SECRET_KEY is None:
|
||||||
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
||||||
s_key = ''.join([random.choice(chars) for n in range(50)])
|
s_key = ''.join([random.choice(chars) for n in range(50)])
|
||||||
secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--). " % repr(s_key)
|
secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key)
|
||||||
raise KeyError(secret_key_warning)
|
raise KeyError(secret_key_warning)
|
||||||
|
|
||||||
|
|
||||||
# Logging Configuration
|
# Logging Configuration
|
||||||
#
|
#
|
||||||
ROOT_LOGGER_NAME = os.path.basename(os.path.dirname(__file__))
|
ROOT_LOGGER_NAME = os.path.basename(os.path.dirname(__file__))
|
||||||
default_handler = ['socket'] if DEBUG else ['console']
|
default_handler = ['socket', 'console'] if DEBUG else ['console']
|
||||||
|
|
||||||
|
|
||||||
class DjangoSocketHandler(_SocketHandler):
|
class DjangoSocketHandler(_SocketHandler):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user