From cb6efa5d22b61bcb7cde956b0a0f55581a95ca47 Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Fri, 6 Oct 2023 13:53:03 +0200 Subject: [PATCH 1/2] show urls and files when they exists --- mslib/index.py | 32 ++++++++++++++++++++++++++---- mslib/mscolab/conf.py | 4 ++++ mslib/mscolab/server.py | 2 +- mslib/mswms/demodata.py | 2 ++ mslib/mswms/wms.py | 14 +++++++------ mslib/static/templates/footer.html | 14 ++++++++++--- 6 files changed, 54 insertions(+), 14 deletions(-) diff --git a/mslib/index.py b/mslib/index.py index a819b78fa..ccdec930e 100644 --- a/mslib/index.py +++ b/mslib/index.py @@ -64,12 +64,26 @@ def _xstatic(name): return None -def create_app(name=""): +def file_exists(filepath=None): + try: + return os.path.isfile(filepath) + except TypeError: + return False + + +def create_app(name="", imprint=None, gdpr=None): + imprint_file = imprint + gdpr_file = gdpr + if "mscolab.server" in name: from mslib.mscolab.app import APP else: from mslib.mswms.app import APP + APP.jinja_env.globals.update(file_exists=file_exists) + APP.jinja_env.globals["imprint"] = imprint_file + APP.jinja_env.globals["gdpr"] = gdpr_file + @APP.route('/xstatic//', defaults=dict(filename='')) @APP.route('/xstatic//') def files(name, filename): @@ -190,9 +204,19 @@ def help(): @APP.route("/mss/imprint") def imprint(): - _file = os.path.join(DOCS_SERVER_PATH, 'static', 'docs', 'imprint.md') - content = get_content(_file) - return render_template("/content.html", act="imprint", content=content) + if os.path.exists(imprint_file): + content = get_content(imprint_file) + return render_template("/content.html", act="imprint", content=content) + else: + return "" + + @APP.route("/mss/gpdr") + def gdpr(): + if os.path.exists(gdpr_file): + content = get_content(gdpr_file) + return render_template("/content.html", act="gdpr", content=content) + else: + return "" @APP.route('/mss/favicon.ico') def favicons(): diff --git a/mslib/mscolab/conf.py b/mslib/mscolab/conf.py index 6cb60f05e..8ffd5bb83 100644 --- a/mslib/mscolab/conf.py +++ b/mslib/mscolab/conf.py @@ -102,6 +102,10 @@ class default_mscolab_settings: # mail accounts # MAIL_DEFAULT_SENDER = 'MSS@localhost' + # filepath to md file with imprint + IMPRINT = None + # filepath to md file with gdpr + GDPR = None mscolab_settings = default_mscolab_settings() diff --git a/mslib/mscolab/server.py b/mslib/mscolab/server.py index 4f57ca2ec..bf4e48f90 100644 --- a/mslib/mscolab/server.py +++ b/mslib/mscolab/server.py @@ -52,7 +52,7 @@ from mslib.mscolab.forms import ResetRequestForm, ResetPasswordForm -APP = create_app(__name__) +APP = create_app(__name__, imprint=mscolab_settings.IMPRINT, gdpr=mscolab_settings.GDPR) mail = Mail(APP) CORS(APP, origins=mscolab_settings.CORS_ORIGINS if hasattr(mscolab_settings, "CORS_ORIGINS") else ["*"]) auth = HTTPBasicAuth() diff --git a/mslib/mswms/demodata.py b/mslib/mswms/demodata.py index 986c93802..ccb80d06c 100644 --- a/mslib/mswms/demodata.py +++ b/mslib/mswms/demodata.py @@ -969,6 +969,8 @@ def create_server_config(self, detailed_information=False): #service_country = "Germany" #service_fees = "none" #service_access_constraints = "This service is intended for research purposes only." +#imprint = "" +#gdpr = "" # diff --git a/mslib/mswms/wms.py b/mslib/mswms/wms.py index 6f96f95a7..fc06e19f4 100644 --- a/mslib/mswms/wms.py +++ b/mslib/mswms/wms.py @@ -69,12 +69,6 @@ # Flask basic auth's documentation # https://flask-basicauth.readthedocs.io/en/latest/#flask.ext.basicauth.BasicAuth.check_credentials -app = create_app(__name__) -auth = HTTPBasicAuth() - -realm = 'Mission Support Web Map Service' -app.config['realm'] = realm - class default_mswms_settings: base_dir = os.path.abspath(os.path.dirname(__file__)) @@ -97,6 +91,8 @@ class default_mswms_settings: register_horizontal_layers = [] register_vertical_layers = [] register_linear_layers = [] + imprint = "" + gdpr = "" data = {} enable_basic_http_authentication = False __file__ = None @@ -110,6 +106,12 @@ class default_mswms_settings: except ImportError as ex: logging.warning("Couldn't import mswms_settings (ImportError:'%s'), Using dummy config.", ex) +app = create_app(__name__, imprint=mswms_settings.imprint, gdpr=mswms_settings.gdpr) +auth = HTTPBasicAuth() + +realm = 'Mission Support Web Map Service' +app.config['realm'] = realm + try: import mswms_auth except ImportError as ex: diff --git a/mslib/static/templates/footer.html b/mslib/static/templates/footer.html index 713e1c37d..7bd2cae4d 100644 --- a/mslib/static/templates/footer.html +++ b/mslib/static/templates/footer.html @@ -16,9 +16,17 @@
- + {% if file_exists(imprint) %} + + {% endif %} + {% if file_exists(gdpr) %} + + + {% endif %}
From c77eac5d1519fe688a76617d9ffed9eaf655723d Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Sat, 7 Oct 2023 10:11:12 +0200 Subject: [PATCH 2/2] using same check as in jinja2 template --- mslib/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mslib/index.py b/mslib/index.py index ccdec930e..340fe9cd3 100644 --- a/mslib/index.py +++ b/mslib/index.py @@ -204,7 +204,7 @@ def help(): @APP.route("/mss/imprint") def imprint(): - if os.path.exists(imprint_file): + if file_exists(imprint_file): content = get_content(imprint_file) return render_template("/content.html", act="imprint", content=content) else: @@ -212,7 +212,7 @@ def imprint(): @APP.route("/mss/gpdr") def gdpr(): - if os.path.exists(gdpr_file): + if file_exists(gdpr_file): content = get_content(gdpr_file) return render_template("/content.html", act="gdpr", content=content) else: