Skip to content

Commit a921cb8

Browse files
committed
refactor: move helper methods into helpers.py
1 parent e9d6cbe commit a921cb8

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

otterwiki/helper.py

+34
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,40 @@ def get_pagename_prefixes(filter=[]):
194194
return pagename_prefixes
195195

196196

197+
def get_breadcrumbs(pagepath):
198+
if not pagepath or len(pagepath)<1:
199+
return []
200+
# strip trailing slashes
201+
pagepath = pagepath.rstrip("/")
202+
parents = []
203+
crumbs = []
204+
for e in split_path(pagepath):
205+
parents.append(e)
206+
crumbs.append(
207+
(
208+
get_pagename(e),
209+
join_path(parents),
210+
)
211+
)
212+
return crumbs
213+
214+
215+
def upsert_pagecrumbs(pagepath):
216+
"""
217+
adds the given pagepath to the page specific crumbs "pagecrumbs" stored in the session
218+
"""
219+
if pagepath is None or pagepath == "/":
220+
return
221+
if "pagecrumbs" not in session:
222+
session["pagecrumbs"] = []
223+
else:
224+
session["pagecrumbs"] = list(filter(lambda x: x.lower() != pagepath.lower(), session["pagecrumbs"]))
225+
226+
# add the pagepath to the tail of the list of pagecrumbs
227+
session["pagecrumbs"] = session["pagecrumbs"][-7:] + [pagepath]
228+
# flask.session: modifications on mutable structures are not picked up automatically
229+
session.modified = True
230+
197231

198232
def patchset2urlmap(patchset, rev_b, rev_a=None):
199233
url_map = {}

otterwiki/wiki.py

+2-36
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
get_pagename,
4141
get_pagename_prefixes,
4242
patchset2urlmap,
43+
get_breadcrumbs,
44+
upsert_pagecrumbs,
4345
)
4446
from otterwiki.auth import has_permission, current_user
4547
from otterwiki.plugins import chain_hooks
@@ -55,37 +57,6 @@
5557
PIL.Image.Resampling = PIL.Image
5658

5759

58-
def get_breadcrumbs(pagepath):
59-
if not pagepath or len(pagepath)<1:
60-
return []
61-
# strip trailing slashes
62-
pagepath = pagepath.rstrip("/")
63-
parents = []
64-
crumbs = []
65-
for e in split_path(pagepath):
66-
parents.append(e)
67-
crumbs.append(
68-
(
69-
get_pagename(e),
70-
join_path(parents),
71-
)
72-
)
73-
return crumbs
74-
75-
76-
def upsert_pagecrumbs(pagepath):
77-
if pagepath is None or pagepath == "/":
78-
return
79-
if "pagecrumbs" not in session:
80-
session["pagecrumbs"] = []
81-
else:
82-
session["pagecrumbs"] = list(filter(lambda x: x.lower() != pagepath.lower(), session["pagecrumbs"]))
83-
84-
# add the pagepath to the tail of the list of pagecrumbs
85-
session["pagecrumbs"] = session["pagecrumbs"][-7:] + [pagepath]
86-
# flask.session: modifications on mutable structures are not picked up automatically
87-
session.modified = True
88-
8960
class PageIndex:
9061
def __init__(self, path=None):
9162
'''
@@ -274,11 +245,6 @@ def get(self):
274245
return log
275246

276247
def render(self):
277-
"""revert_form.
278-
279-
:param revision:
280-
:param message:
281-
"""
282248
if not has_permission("READ"):
283249
abort(403)
284250
log = self.get()

0 commit comments

Comments
 (0)