Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show urls and files when they exists #2053

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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