diff options
author | B. Stack <bgstack15@gmail.com> | 2023-08-31 09:05:42 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2023-08-31 09:05:42 -0400 |
commit | ce7455fb1f7131215d381427ddbea1e4f139a1bc (patch) | |
tree | 22450d598aa1433acefd84b24609aeace5a30107 | |
parent | debug by printf (diff) | |
download | newspipe-ce7455fb1f7131215d381427ddbea1e4f139a1bc.tar.gz newspipe-ce7455fb1f7131215d381427ddbea1e4f139a1bc.tar.bz2 newspipe-ce7455fb1f7131215d381427ddbea1e4f139a1bc.zip |
try a context processor
-rw-r--r-- | newspipe/bootstrap.py | 12 | ||||
-rw-r--r-- | newspipe/lib/utils.py | 9 |
2 files changed, 12 insertions, 9 deletions
diff --git a/newspipe/bootstrap.py b/newspipe/bootstrap.py index 9160c857..1af61d2f 100644 --- a/newspipe/bootstrap.py +++ b/newspipe/bootstrap.py @@ -5,6 +5,7 @@ import os from flask import Flask from flask import request +from flask import url_for as f_url_for from flask_babel import Babel from flask_babel import format_datetime from flask_migrate import Migrate @@ -111,3 +112,14 @@ application.jinja_env.filters["datetime"] = format_datetime application.jinja_env.filters["datetimeformat"] = datetimeformat # inject application in Jinja env application.jinja_env.globals["application"] = application + +@application.context_processor +def utility_processor(): + def url_for(endpoint, **values): + """ Custom reverse-proxy support for url_for """ + print(f"DEBUG: generating url_for {endpoint}") + _uf = f_url_for(endpoint, **values) + if application.config and "PREFIX" in application.config: + _uf = str(application.config("PREFIX")) + _uf + return _uf + return dict(url_for=url_for) diff --git a/newspipe/lib/utils.py b/newspipe/lib/utils.py index eb20ff4b..7e8e4a15 100644 --- a/newspipe/lib/utils.py +++ b/newspipe/lib/utils.py @@ -6,20 +6,11 @@ from hashlib import md5 import requests from flask import request -from flask import url_for as f_url_for from newspipe.bootstrap import application logger = logging.getLogger(__name__) -def url_for(endpoint, **values): - """ Custom reverse-proxy support for url_for """ - print(f"DEBUG: generating url_for {endpoint}") - _uf = f_url_for(endpoint, **values) - if application.config and "PREFIX" in application.config: - _uf = str(application.config("PREFIX")) + _uf - return _uf - def default_handler(obj, role="admin"): """JSON handler for default query formatting""" |