Skip to content

Commit

Permalink
refactor: move helper methods into helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
redimp committed Nov 10, 2024
1 parent e9d6cbe commit a921cb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
34 changes: 34 additions & 0 deletions otterwiki/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,40 @@ def get_pagename_prefixes(filter=[]):
return pagename_prefixes


def get_breadcrumbs(pagepath):
if not pagepath or len(pagepath)<1:
return []
# strip trailing slashes
pagepath = pagepath.rstrip("/")
parents = []
crumbs = []
for e in split_path(pagepath):
parents.append(e)
crumbs.append(
(
get_pagename(e),
join_path(parents),
)
)
return crumbs


def upsert_pagecrumbs(pagepath):
"""
adds the given pagepath to the page specific crumbs "pagecrumbs" stored in the session
"""
if pagepath is None or pagepath == "/":
return
if "pagecrumbs" not in session:
session["pagecrumbs"] = []
else:
session["pagecrumbs"] = list(filter(lambda x: x.lower() != pagepath.lower(), session["pagecrumbs"]))

# add the pagepath to the tail of the list of pagecrumbs
session["pagecrumbs"] = session["pagecrumbs"][-7:] + [pagepath]
# flask.session: modifications on mutable structures are not picked up automatically
session.modified = True


def patchset2urlmap(patchset, rev_b, rev_a=None):
url_map = {}
Expand Down
38 changes: 2 additions & 36 deletions otterwiki/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
get_pagename,
get_pagename_prefixes,
patchset2urlmap,
get_breadcrumbs,
upsert_pagecrumbs,
)
from otterwiki.auth import has_permission, current_user
from otterwiki.plugins import chain_hooks
Expand All @@ -55,37 +57,6 @@
PIL.Image.Resampling = PIL.Image


def get_breadcrumbs(pagepath):
if not pagepath or len(pagepath)<1:
return []
# strip trailing slashes
pagepath = pagepath.rstrip("/")
parents = []
crumbs = []
for e in split_path(pagepath):
parents.append(e)
crumbs.append(
(
get_pagename(e),
join_path(parents),
)
)
return crumbs


def upsert_pagecrumbs(pagepath):
if pagepath is None or pagepath == "/":
return
if "pagecrumbs" not in session:
session["pagecrumbs"] = []
else:
session["pagecrumbs"] = list(filter(lambda x: x.lower() != pagepath.lower(), session["pagecrumbs"]))

# add the pagepath to the tail of the list of pagecrumbs
session["pagecrumbs"] = session["pagecrumbs"][-7:] + [pagepath]
# flask.session: modifications on mutable structures are not picked up automatically
session.modified = True

class PageIndex:
def __init__(self, path=None):
'''
Expand Down Expand Up @@ -274,11 +245,6 @@ def get(self):
return log

def render(self):
"""revert_form.
:param revision:
:param message:
"""
if not has_permission("READ"):
abort(403)
log = self.get()
Expand Down

0 comments on commit a921cb8

Please sign in to comment.