Skip to content

Commit

Permalink
show urls and files when they exists (#2053)
Browse files Browse the repository at this point in the history
* show urls and files when they exists

* using same check as in jinja2 template
  • Loading branch information
ReimarBauer authored Oct 8, 2023
1 parent 97a5baa commit 92514ab
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
32 changes: 28 additions & 4 deletions mslib/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>/', defaults=dict(filename=''))
@APP.route('/xstatic/<name>/<path:filename>')
def files(name, filename):
Expand Down Expand Up @@ -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 file_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 file_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():
Expand Down
4 changes: 4 additions & 0 deletions mslib/mscolab/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion mslib/mscolab/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions mslib/mswms/demodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
#
Expand Down
14 changes: 8 additions & 6 deletions mslib/mswms/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand All @@ -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
Expand All @@ -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:
Expand Down
14 changes: 11 additions & 3 deletions mslib/static/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
</div>
<div class="container-fluid">
<div class="row" style="background-color:lavender;">
<div class="col-sm-5 col-md-6" style="background-color:f2f2f2;"><a href="{{ url_for('imprint') }}">
<p class="text-dark">Imprint</p></a>
</div>
{% if file_exists(imprint) %}
<div class="col-sm-2 col-md-2" style="background-color:f2f2f2;"><a href="{{ url_for('imprint') }}">
<p class="text-dark">Imprint</p></a>
</div>
{% endif %}
{% if file_exists(gdpr) %}

<div class="col-sm-2 col-md-2" style="background-color:f2f2f2;"><a href="{{ url_for('gdpr') }}">
<p class="text-dark">GDPR</p></a>
</div>
{% endif %}
<div class="col-sm-5 col-sm-offset-2 col-md-6 col-md-offset-0" style="background-color:f2f2f2;">
</div>
</div>
Expand Down

0 comments on commit 92514ab

Please sign in to comment.