Skip to content

Commit 62f70be

Browse files
committed
Add get_endpoints function and fix itemlinks
1 parent b0f9354 commit 62f70be

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/moin/app.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from moin.utils import monkeypatch # noqa
3131
from moin.utils.clock import Clock
3232
from moin import auth, user, config
33-
from moin.constants.misc import ANON
33+
from moin.constants.misc import ANON, VALID_ITEMLINK_VIEWS
3434
from moin.i18n import i18n_init
3535
from moin.themes import setup_jinja_env, themed_error
3636
from moin.storage.middleware import protecting, indexing, routing
@@ -156,6 +156,8 @@ class ItemNameConverter(PathConverter):
156156
from moin.apps.serve import serve
157157

158158
app.register_blueprint(serve, url_prefix="/+serve")
159+
160+
app.view_endpoints = get_endpoints(app)
159161
clock.stop("create_app register")
160162
clock.start("create_app flask-cache")
161163
# 'SimpleCache' caching uses a dict and is not thread safe according to the docs.
@@ -191,6 +193,16 @@ class ItemNameConverter(PathConverter):
191193
return app
192194

193195

196+
def get_endpoints(app):
197+
"""Get dict with views and related endpoints allowed as itemlink"""
198+
view_endpoints = {}
199+
for rule in app.url_map.iter_rules():
200+
view = rule.rule.split("/")[1]
201+
if view in VALID_ITEMLINK_VIEWS and rule.rule == f"/{view}/<itemname:item_name>":
202+
view_endpoints[view] = rule.endpoint
203+
return view_endpoints
204+
205+
194206
def destroy_app(app):
195207
deinit_backends(app)
196208

src/moin/converters/link.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
special wiki links.
1010
"""
1111

12+
from flask import current_app as app
1213
from flask import g as flaskg
1314

1415
from moin.constants.misc import VALID_ITEMLINK_VIEWS
@@ -202,8 +203,9 @@ def handle_wikilocal_links(self, elem, input, page, to_tag=ConverterBase._tag_xl
202203
item_name = str(page.path[1:]) if page else ""
203204
endpoint, rev, query = self._get_do_rev(input.query)
204205

205-
if view_name == "+meta": # TODO: add other views
206-
endpoint = "frontend.show_item_meta"
206+
if view_name in app.view_endpoints.keys():
207+
# Other views will be shown with class moin-nonexistent as non-existent links
208+
endpoint = app.view_endpoints[view_name]
207209

208210
url = url_for_item(item_name, rev=rev, endpoint=endpoint)
209211
if not page:

0 commit comments

Comments
 (0)