diff --git a/src/moin/app.py b/src/moin/app.py index 1ccf93580..6646df9a0 100644 --- a/src/moin/app.py +++ b/src/moin/app.py @@ -29,13 +29,15 @@ from jinja2 import ChoiceLoader, FileSystemLoader from whoosh.index import EmptyIndexError -from moin.utils import monkeypatch # noqa -from moin.utils.clock import Clock from moin import auth, user, config from moin.constants.misc import ANON from moin.i18n import i18n_init -from moin.themes import setup_jinja_env, themed_error +from moin.search import SearchForm from moin.storage.middleware import protecting, indexing, routing +from moin.themes import setup_jinja_env, themed_error, ThemeSupport +from moin.utils import monkeypatch # noqa +from moin.utils.clock import Clock +from moin.utils.forms import make_generator from moin.wikiutil import WikiLinkAnalyzer from moin import log @@ -192,7 +194,9 @@ class ItemNameConverter(PathConverter): if app.cfg.template_dirs: app.jinja_env.loader = ChoiceLoader([FileSystemLoader(app.cfg.template_dirs), app.jinja_env.loader]) app.register_error_handler(403, themed_error) + app.context_processor(inject_common_template_vars) app.cfg.custom_css_path = os.path.isfile("wiki_local/custom.css") + setup_jinja_env(app.jinja_env) clock.stop("create_app flask-theme") # Create a global counter to limit Content Security Policy reports and prevent spam app.csp_count = 0 @@ -313,18 +317,37 @@ def setup_user_anon(): flaskg.user = user.User(name=ANON, auth_method="invalid") +def inject_common_template_vars() -> dict[str, Any]: + if getattr(flaskg, "no_variable_injection", False): + return {} + else: + return { + "clock": flaskg.clock, + "storage": flaskg.storage, + "user": flaskg.user, + "item_name": request.view_args.get("item_name", ""), + "theme_supp": ThemeSupport(app.cfg), + "cfg": app.cfg, + "gen": make_generator(), + "search_form": SearchForm.from_defaults(), + } + + def before_wiki(): """ Setup environment for wiki requests, start timers. """ - if request and (is_static_content(request.path) or request.path == "/+cspreport/log"): - logging.debug(f"skipping before_wiki for {request.path}") + request_path = getattr(request, "path", "") if request else "" + if is_static_content(request_path) or request_path == "/+cspreport/log": + logging.debug(f"skipping variable injection in before_wiki for {request.path}") + setattr(flaskg, "no_variable_injection", True) return logging.debug("running before_wiki") - flaskg.clock = Clock() - flaskg.clock.start("total") - flaskg.clock.start("init") + + clock = flaskg.clock = Clock() + clock.start("total") + clock.start("init") try: flaskg.unprotected_storage = app.storage cli_no_request_ctx = False @@ -342,40 +365,32 @@ def before_wiki(): if cli_no_request_ctx: # no request.user_agent if this is pytest or cli flaskg.add_lineno_attr = False else: - setup_jinja_env() flaskg.add_lineno_attr = request.headers.get("User-Agent", None) and flaskg.user.edit_on_doubleclick finally: - flaskg.clock.stop("init") + clock.stop("init") def teardown_wiki(response): """ Teardown environment of wiki requests, stop timers. """ - if request: - request_path = request.path - if is_static_content(request_path): - return response - else: - request_path = "" + request_path = getattr(request, "path", "") + if is_static_content(request_path) or request_path == "/+cspreport/log": + return response logging.debug("running teardown_wiki") - if hasattr(flaskg, "edit_utils"): + if edit_utils := getattr(flaskg, "edit_utils", None): # if transaction fails with sql file locked, we try to free it here try: - flaskg.edit_utils.conn.close() + edit_utils.conn.close() except AttributeError: pass try: # whoosh cache performance - for cache in ( - flaskg.storage.parse_acl, - flaskg.storage.eval_acl, - flaskg.storage.get_acls, - flaskg.storage.allows, - ): + storage = flaskg.storage + for cache in (storage.parse_acl, storage.eval_acl, storage.get_acls, storage.allows): if cache.cache_info()[3] > 0: msg = "cache = %s: hits = %s, misses = %s, maxsize = %s, size = %s" % ( (cache.__name__,) + cache.cache_info() @@ -386,8 +401,10 @@ def teardown_wiki(response): pass try: - flaskg.clock.stop("total", comment=request_path) - del flaskg.clock + clock = flaskg.pop("clock", None) + if clock is not None: + clock.stop("total", comment=request_path) + del clock except AttributeError: # can happen if teardown_wiki() is called twice, e.g. by unit tests. pass diff --git a/src/moin/apps/admin/templates/admin/group_acl_report.html b/src/moin/apps/admin/templates/admin/group_acl_report.html index 2507c4830..7d7d43b7e 100644 --- a/src/moin/apps/admin/templates/admin/group_acl_report.html +++ b/src/moin/apps/admin/templates/admin/group_acl_report.html @@ -11,7 +11,7 @@ #} {% extends theme("layout.html") %} -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% block content %}

{{ _("Group ACL Report") }}

{{ _("Group Name") }}: {{ group_name }}

diff --git a/src/moin/apps/admin/templates/admin/groupbrowser.html b/src/moin/apps/admin/templates/admin/groupbrowser.html index 46d80311d..f6520d2ba 100644 --- a/src/moin/apps/admin/templates/admin/groupbrowser.html +++ b/src/moin/apps/admin/templates/admin/groupbrowser.html @@ -1,5 +1,5 @@ {% extends theme("layout.html") %} -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% block content %}

{{ _("Groups") }}

diff --git a/src/moin/apps/admin/templates/admin/register_new_user.html b/src/moin/apps/admin/templates/admin/register_new_user.html index 7eedb8106..d859ac111 100644 --- a/src/moin/apps/admin/templates/admin/register_new_user.html +++ b/src/moin/apps/admin/templates/admin/register_new_user.html @@ -4,7 +4,7 @@ #} {% extends theme("layout.html") %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% block content %}

{{ _("Register New User") }}

diff --git a/src/moin/apps/admin/templates/admin/trash.html b/src/moin/apps/admin/templates/admin/trash.html index d3c9986c5..3813cf4c1 100644 --- a/src/moin/apps/admin/templates/admin/trash.html +++ b/src/moin/apps/admin/templates/admin/trash.html @@ -1,5 +1,5 @@ {% extends theme("layout.html") %} -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% block content %} {% if headline %}

{{ headline }}

diff --git a/src/moin/apps/admin/templates/admin/user_acl_report.html b/src/moin/apps/admin/templates/admin/user_acl_report.html index 1134197a0..49a7057d2 100644 --- a/src/moin/apps/admin/templates/admin/user_acl_report.html +++ b/src/moin/apps/admin/templates/admin/user_acl_report.html @@ -11,7 +11,7 @@ #} {% extends theme("layout.html") %} -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% block content %}

{{ _("User ACL Report") }}

{{ _("User Names") }}: {{ user_names|join(', ') }}

diff --git a/src/moin/apps/admin/templates/user/highlighterhelp.html b/src/moin/apps/admin/templates/user/highlighterhelp.html index 7dd01f4a7..5361e91fb 100644 --- a/src/moin/apps/admin/templates/user/highlighterhelp.html +++ b/src/moin/apps/admin/templates/user/highlighterhelp.html @@ -1,4 +1,4 @@ -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% extends theme("layout.html") %} {% block content %}

{{ _("Highlighters") }}

diff --git a/src/moin/apps/admin/templates/user/interwikihelp.html b/src/moin/apps/admin/templates/user/interwikihelp.html index 63b15198d..cffe40c82 100644 --- a/src/moin/apps/admin/templates/user/interwikihelp.html +++ b/src/moin/apps/admin/templates/user/interwikihelp.html @@ -1,4 +1,4 @@ -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% extends theme("layout.html") %} {% block content %}

{{ _("InterWiki Names") }}

diff --git a/src/moin/apps/admin/templates/user/itemsize.html b/src/moin/apps/admin/templates/user/itemsize.html index d537cd89b..1605043b7 100644 --- a/src/moin/apps/admin/templates/user/itemsize.html +++ b/src/moin/apps/admin/templates/user/itemsize.html @@ -1,4 +1,4 @@ -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% extends theme("layout.html") %} {% block content %}

{{ _("Item Sizes (last revision)") }}

diff --git a/src/moin/templates/404.html b/src/moin/templates/404.html index dcea94999..e84c0503b 100644 --- a/src/moin/templates/404.html +++ b/src/moin/templates/404.html @@ -5,7 +5,7 @@ abort(404, item_name) # where item_name is the local item name #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% extends theme("layout.html") %} {% block content %} diff --git a/src/moin/templates/atom.html b/src/moin/templates/atom.html index e0df8d022..b2967a7ce 100644 --- a/src/moin/templates/atom.html +++ b/src/moin/templates/atom.html @@ -1,4 +1,4 @@ -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {# A few style rules to ensure the content doesn't overflow #} {% macro atom_style() %} diff --git a/src/moin/templates/base.html b/src/moin/templates/base.html index 6aa80cefb..35af05cc3 100644 --- a/src/moin/templates/base.html +++ b/src/moin/templates/base.html @@ -8,7 +8,7 @@ {#- This allows child templates passing their header_search macro to the common layout (eg blog). If there is no header_search macro defined in child templates use the default one. #} {%- if not header_search %} - {%- from "utils.html" import header_search %} + {%- from "utils.html" import header_search with context %} {%- endif -%} diff --git a/src/moin/templates/blog/layout.html b/src/moin/templates/blog/layout.html index 042eef838..d8b8d3eb7 100644 --- a/src/moin/templates/blog/layout.html +++ b/src/moin/templates/blog/layout.html @@ -1,6 +1,6 @@ {% extends theme("show.html") %} {% import theme("blog/utils.html") as blog_utils with context %} -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% import "itemviews.html" as itemviews with context %} {% if blog_item %} diff --git a/src/moin/templates/blog/modify_entry_meta.html b/src/moin/templates/blog/modify_entry_meta.html index 58db2036f..947d345e0 100644 --- a/src/moin/templates/blog/modify_entry_meta.html +++ b/src/moin/templates/blog/modify_entry_meta.html @@ -1,4 +1,4 @@ -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% macro meta_editor(form, may_admin) %}

Blog entry metadata

diff --git a/src/moin/templates/blog/modify_main_meta.html b/src/moin/templates/blog/modify_main_meta.html index 5bf0604d7..7e77a66ff 100644 --- a/src/moin/templates/blog/modify_main_meta.html +++ b/src/moin/templates/blog/modify_main_meta.html @@ -1,4 +1,4 @@ -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% macro meta_editor(form, may_admin) %}

Blog metadata

diff --git a/src/moin/templates/blog/utils.html b/src/moin/templates/blog/utils.html index c78968d25..21a9bd584 100644 --- a/src/moin/templates/blog/utils.html +++ b/src/moin/templates/blog/utils.html @@ -1,5 +1,5 @@ -{% import "forms.html" as forms %} -{% import "utils.html" as utils %} +{% import "forms.html" as forms with context %} +{% import "utils.html" as utils with context %} {% macro show_blog_entry(entry_item) %} {% set summary = entry_item.meta['summary'] %} diff --git a/src/moin/templates/convert.html b/src/moin/templates/convert.html index 23218d01a..92993050f 100644 --- a/src/moin/templates/convert.html +++ b/src/moin/templates/convert.html @@ -3,7 +3,7 @@ an item to a different text markup language. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% extends theme("show.html") %} {% set title = _("Convert '{item_name}'").format(item_name=item.fqname|shorten_fqname) %} diff --git a/src/moin/templates/create_new_item.html b/src/moin/templates/create_new_item.html index 6e72ae8d3..20ec338db 100644 --- a/src/moin/templates/create_new_item.html +++ b/src/moin/templates/create_new_item.html @@ -5,7 +5,7 @@ The process rendering this template should have flashed a message describing the error. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% extends theme("layout.html") %} {% set title = _("Create New Item") %} diff --git a/src/moin/templates/delete.html b/src/moin/templates/delete.html index 5663cdf13..237de64d0 100644 --- a/src/moin/templates/delete.html +++ b/src/moin/templates/delete.html @@ -5,7 +5,7 @@ The revision's meta data and rendered content is displayed for user review. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% extends theme("show.html") %} {% if alias_names %} diff --git a/src/moin/templates/destroy.html b/src/moin/templates/destroy.html index eee348b1f..b986b4468 100644 --- a/src/moin/templates/destroy.html +++ b/src/moin/templates/destroy.html @@ -7,7 +7,7 @@ is removed from storage so server log is only record of the transaction. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% extends theme("show.html") %} {% if alias_names %} diff --git a/src/moin/templates/diff_text_atom.html b/src/moin/templates/diff_text_atom.html index 3d2005527..83eec436c 100644 --- a/src/moin/templates/diff_text_atom.html +++ b/src/moin/templates/diff_text_atom.html @@ -1,4 +1,4 @@ -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %}
{% for llineno, lcontent, rlineno, rcontent in diffs %} diff --git a/src/moin/templates/global_history.html b/src/moin/templates/global_history.html index 8dc0bb5d2..b4bb17225 100644 --- a/src/moin/templates/global_history.html +++ b/src/moin/templates/global_history.html @@ -12,7 +12,7 @@ #} {% extends theme("layout.html") %} -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {# map meta.action to font awesome classes #} {% set awesome_class = { diff --git a/src/moin/templates/login.html b/src/moin/templates/login.html index aa527faed..31694e016 100644 --- a/src/moin/templates/login.html +++ b/src/moin/templates/login.html @@ -1,5 +1,5 @@ {% extends theme("layout.html") %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% block content %}
diff --git a/src/moin/templates/lookup.html b/src/moin/templates/lookup.html index 0ed6287d1..46dd17fb7 100644 --- a/src/moin/templates/lookup.html +++ b/src/moin/templates/lookup.html @@ -1,6 +1,6 @@ {% extends theme("layout.html") %} -{% import "utils.html" as utils %} -{% import "forms.html" as forms %} +{% import "utils.html" as utils with context %} +{% import "forms.html" as forms with context %} {% block content %} {% if results is not defined %}

{{ _("Lookup") }}

diff --git a/src/moin/templates/lostpass.html b/src/moin/templates/lostpass.html index ead760f29..442e13359 100644 --- a/src/moin/templates/lostpass.html +++ b/src/moin/templates/lostpass.html @@ -1,5 +1,5 @@ {% extends theme("layout.html") %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% block content %}

{{ _("Lost Password") }}

diff --git a/src/moin/templates/modify.html b/src/moin/templates/modify.html index 105d19ae0..007994dbb 100644 --- a/src/moin/templates/modify.html +++ b/src/moin/templates/modify.html @@ -12,8 +12,8 @@ * select edit "from scratch" or "from template" #} -{% import "forms.html" as forms %} -{% import "utils.html" as utils %} +{% import "forms.html" as forms with context %} +{% import "utils.html" as utils with context %} {% extends theme("show.html") %} diff --git a/src/moin/templates/modify_binary.html b/src/moin/templates/modify_binary.html index c3ecb53bc..dd068de31 100644 --- a/src/moin/templates/modify_binary.html +++ b/src/moin/templates/modify_binary.html @@ -5,7 +5,7 @@ As binary items cannot be edited by moin, the only choice given is to upload a file. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% macro data_editor(form, item_name) %}
diff --git a/src/moin/templates/modify_meta.html b/src/moin/templates/modify_meta.html index b0b991d53..4140e49fe 100644 --- a/src/moin/templates/modify_meta.html +++ b/src/moin/templates/modify_meta.html @@ -5,7 +5,7 @@ The macro defines a portion of a form enabling a user to modify selected meta data. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% macro meta_editor(form, may_admin) %}
diff --git a/src/moin/templates/modify_text.html b/src/moin/templates/modify_text.html index 3ecbc31b3..cad4a3c7c 100644 --- a/src/moin/templates/modify_text.html +++ b/src/moin/templates/modify_text.html @@ -12,7 +12,7 @@ value and textarea scroll bars will be used as needed. #} -{% from "modify_binary.html" import data_editor as base_editor %} +{% from "modify_binary.html" import data_editor as base_editor with context %} {% macro data_editor(form, item_name) %} {% set textarea_rows = '1' if edit_rows == '0' else edit_rows %} diff --git a/src/moin/templates/mychanges.html b/src/moin/templates/mychanges.html index 8286d9baf..86c467f93 100644 --- a/src/moin/templates/mychanges.html +++ b/src/moin/templates/mychanges.html @@ -5,7 +5,7 @@ #} {% extends theme("layout.html") %} -{% import "utils.html" as utils %} +{% import "utils.html" as utils with context %} {% block content %}

{{ _('My Changes') }}

diff --git a/src/moin/templates/recoverpass.html b/src/moin/templates/recoverpass.html index 8a30077b8..3cb129dfa 100644 --- a/src/moin/templates/recoverpass.html +++ b/src/moin/templates/recoverpass.html @@ -1,5 +1,5 @@ {% extends theme("layout.html") %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% block content %}

{{ _("Recover Password") }}

diff --git a/src/moin/templates/register.html b/src/moin/templates/register.html index 59260ad90..6bbe37b30 100644 --- a/src/moin/templates/register.html +++ b/src/moin/templates/register.html @@ -1,5 +1,5 @@ {% extends theme("layout.html") %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% block content %}

{{ _("Create Account") }}

diff --git a/src/moin/templates/rename.html b/src/moin/templates/rename.html index 21bac3734..df96003c2 100644 --- a/src/moin/templates/rename.html +++ b/src/moin/templates/rename.html @@ -4,7 +4,7 @@ The item's meta data and rendered content is displayed for user review. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% extends theme("show.html") %} {% set title = _("Rename '{item_name}'").format(item_name=item.fqname|shorten_fqname) %} diff --git a/src/moin/templates/revert.html b/src/moin/templates/revert.html index 269c99395..0da2fc4f1 100644 --- a/src/moin/templates/revert.html +++ b/src/moin/templates/revert.html @@ -4,8 +4,8 @@ The revision's meta data and rendered content is displayed for user review. #} -{% import "forms.html" as forms %} -{% import "utils.html" as utils %} +{% import "forms.html" as forms with context %} +{% import "utils.html" as utils with context %} {% extends theme("layout.html") %} {% block content %} diff --git a/src/moin/templates/search.html b/src/moin/templates/search.html index a8af39c11..2b7baf6c4 100644 --- a/src/moin/templates/search.html +++ b/src/moin/templates/search.html @@ -7,8 +7,8 @@ #} {% extends theme("layout.html") %} -{% import "forms.html" as forms %} -{% import "utils.html" as utils %} +{% import "forms.html" as forms with context %} +{% import "utils.html" as utils with context %} {%- set search_form = None %} {# layout will not show search form in header #} diff --git a/src/moin/templates/ticket/advanced.html b/src/moin/templates/ticket/advanced.html index 115cf571c..c37148fcf 100644 --- a/src/moin/templates/ticket/advanced.html +++ b/src/moin/templates/ticket/advanced.html @@ -1,7 +1,7 @@ {# Display a form to search for tickets using meta data such tags, priority, etc. #} {% extends theme("layout.html") %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% set title = _("Advanced Search") %} {% block content %} diff --git a/src/moin/templates/ticket/modify.html b/src/moin/templates/ticket/modify.html index 5764d4f19..1c62fefae 100644 --- a/src/moin/templates/ticket/modify.html +++ b/src/moin/templates/ticket/modify.html @@ -2,7 +2,7 @@ {% extends "ticket/base.html" %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% import "ticket/ticket_macros.html" as ticket_macros with context %} {% block title_text %} diff --git a/src/moin/templates/ticket/submit.html b/src/moin/templates/ticket/submit.html index 8bf318ea7..b122296ec 100644 --- a/src/moin/templates/ticket/submit.html +++ b/src/moin/templates/ticket/submit.html @@ -2,7 +2,7 @@ {% extends "ticket/base.html" %} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% import "ticket/ticket_macros.html" as ticket_macros with context %} {% block title_text %} diff --git a/src/moin/templates/usersettings.html b/src/moin/templates/usersettings.html index 9d36705a7..99dfe58bc 100644 --- a/src/moin/templates/usersettings.html +++ b/src/moin/templates/usersettings.html @@ -13,7 +13,7 @@ #} {% extends theme("layout.html") %} -{% import "usersettings_forms.html" as user_forms %} +{% import "usersettings_forms.html" as user_forms with context %} {% block content %}

{{ _("User Settings") }}

diff --git a/src/moin/templates/usersettings_ajax.html b/src/moin/templates/usersettings_ajax.html index 811534696..d4995f965 100644 --- a/src/moin/templates/usersettings_ajax.html +++ b/src/moin/templates/usersettings_ajax.html @@ -2,7 +2,7 @@ This template returns the updates for one usersettings form processed as part of an XHR request. #} -{% import "usersettings_forms.html" as user_forms %} +{% import "usersettings_forms.html" as user_forms with context %} {% if part == 'personal' %} {{ user_forms.personal(form) }} diff --git a/src/moin/templates/usersettings_forms.html b/src/moin/templates/usersettings_forms.html index bc7062f5e..43a5b0810 100644 --- a/src/moin/templates/usersettings_forms.html +++ b/src/moin/templates/usersettings_forms.html @@ -6,7 +6,7 @@ Updates to the forms will be processed as XHR requests. #} -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% macro personal(form) %} {{ gen.form.open(form, id="usersettings_personal", method="post", action=url_for('frontend.usersettings')) }} diff --git a/src/moin/templates/utils.html b/src/moin/templates/utils.html index 67d509e31..4adb0c1cb 100644 --- a/src/moin/templates/utils.html +++ b/src/moin/templates/utils.html @@ -4,7 +4,7 @@ Original Moin code should be added here. Macros derived from Flatland should be added to forms.html. #} -{% import 'forms.html' as forms %} +{% import "forms.html" as forms with context %} {# "item" must be passed because of flakey jinja2 context passing #} {% macro rev_navigation(rev_navigation_ids_dates, fqname, view='frontend.show_item', item=item) %} diff --git a/src/moin/themes/__init__.py b/src/moin/themes/__init__.py index 54a164089..2ce556ece 100644 --- a/src/moin/themes/__init__.py +++ b/src/moin/themes/__init__.py @@ -34,7 +34,6 @@ from moin.constants.misc import FLASH_REPEAT, ICON_MAP from moin.constants.namespaces import NAMESPACE_DEFAULT, NAMESPACE_USERS, NAMESPACE_USERPROFILES, NAMESPACE_ALL from moin.constants.rights import SUPERUSER -from moin.search import SearchForm from moin.user import User from moin.utils.interwiki import ( split_interwiki, @@ -46,7 +45,6 @@ split_fqname, get_fqname, ) -from moin.utils.forms import make_generator from moin.utils.clock import timed from moin.utils.mime import Type from moin.utils import show_time @@ -763,19 +761,19 @@ def time_datetime(dt): return show_time.format_date_time(dt) -def setup_jinja_env(): - app.jinja_env.filters["shorten_fqname"] = shorten_fqname - app.jinja_env.filters["shorten_item_name"] = shorten_item_name - app.jinja_env.filters["shorten_id"] = shorten_id - app.jinja_env.filters["contenttype_to_class"] = contenttype_to_class - app.jinja_env.filters["json_dumps"] = dumps - app.jinja_env.filters["shorten_ctype"] = shorten_ctype - app.jinja_env.filters["time_hh_mm"] = time_hh_mm - app.jinja_env.filters["time_datetime"] = time_datetime +def setup_jinja_env(jinja_env): + jinja_env.filters["shorten_fqname"] = shorten_fqname + jinja_env.filters["shorten_item_name"] = shorten_item_name + jinja_env.filters["shorten_id"] = shorten_id + jinja_env.filters["contenttype_to_class"] = contenttype_to_class + jinja_env.filters["json_dumps"] = dumps + jinja_env.filters["shorten_ctype"] = shorten_ctype + jinja_env.filters["time_hh_mm"] = time_hh_mm + jinja_env.filters["time_datetime"] = time_datetime # please note that these filters are installed by flask-babel: # datetimeformat, dateformat, timeformat, timedeltaformat - app.jinja_env.globals.update( + jinja_env.globals.update( { # please note that flask-babel/jinja2.ext installs: # _, gettext, ngettext @@ -784,19 +782,11 @@ def setup_jinja_env(): "Type": Type, # please note that flask-theme installs: # theme, theme_static - "theme_supp": ThemeSupport(app.cfg), - "user": flaskg.user, - "storage": flaskg.storage, - "clock": flaskg.clock, - "cfg": app.cfg, - "item_name": request.view_args.get("item_name", ""), "url_for_item": url_for_item, "get_fqname": get_fqname, "get_editor_info": lambda meta: get_editor_info(meta), "get_assigned_to_info": lambda meta: get_assigned_to_info(meta), "utctimestamp": lambda dt: utctimestamp(dt), - "gen": make_generator(), - "search_form": SearchForm.from_defaults(), } ) diff --git a/src/moin/themes/basic/templates/modify.html b/src/moin/themes/basic/templates/modify.html index 432a366bd..1f8fd08a2 100644 --- a/src/moin/themes/basic/templates/modify.html +++ b/src/moin/themes/basic/templates/modify.html @@ -1,9 +1,9 @@ {% extends theme("layout.html") %} -{% import "forms.html" as forms %} -{% import "utils.html" as utils %} -{% from theme(form.meta_template) import basic_meta_editor %} +{% import "forms.html" as forms with context %} +{% import "utils.html" as utils with context %} +{% from theme(form.meta_template) import basic_meta_editor with context %} {% import theme("itemviews.html") as itemviews with context %} -{% import theme(form['content_form'].template) as content_template %} +{% import theme(form['content_form'].template) as content_template with context %} {% set extra_head = content_template.extra_head %} {% if content_template.basic_data_editor is defined %} {% set data_editor = content_template.basic_data_editor %} diff --git a/src/moin/themes/basic/templates/modify_binary.html b/src/moin/themes/basic/templates/modify_binary.html index ea6bd31cb..19284d95d 100644 --- a/src/moin/themes/basic/templates/modify_binary.html +++ b/src/moin/themes/basic/templates/modify_binary.html @@ -1,4 +1,4 @@ -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% macro basic_data_editor(form, item_name, class) %} {{ forms.render(form['data_file']) }} diff --git a/src/moin/themes/basic/templates/modify_meta.html b/src/moin/themes/basic/templates/modify_meta.html index fece23c33..904db2f95 100644 --- a/src/moin/themes/basic/templates/modify_meta.html +++ b/src/moin/themes/basic/templates/modify_meta.html @@ -1,4 +1,4 @@ -{% import "forms.html" as forms %} +{% import "forms.html" as forms with context %} {% macro basic_meta_editor(form) %} {% for e in [ diff --git a/src/moin/themes/basic/templates/modify_text.html b/src/moin/themes/basic/templates/modify_text.html index 56e11d99c..e6631d6b3 100644 --- a/src/moin/themes/basic/templates/modify_text.html +++ b/src/moin/themes/basic/templates/modify_text.html @@ -1,4 +1,4 @@ -{% from "modify_binary.html" import data_editor as base_editor %} +{% from "modify_binary.html" import data_editor as base_editor with context %} {% macro basic_data_editor(form, item_name) %} diff --git a/src/moin/themes/focus/templates/modify.html b/src/moin/themes/focus/templates/modify.html index f6a888b95..6d429e2f0 100644 --- a/src/moin/themes/focus/templates/modify.html +++ b/src/moin/themes/focus/templates/modify.html @@ -12,8 +12,8 @@ * select edit "from scratch" or "from template" #} -{% import "forms.html" as forms %} -{% import "utils.html" as utils %} +{% import "forms.html" as forms with context %} +{% import "utils.html" as utils with context %} {% extends theme("show.html") %}