Strassenverwaltung plus: Teilen von Strassenzügen
This commit is contained in:
1 parent
d54a986c14
commit
3eb3b746ab
22 files changed
+17391
-158
No files matched your search
@@ -1,8 +1,56 @@
|
||||
"""
|
||||
Hilfsfunktionen für CMBNet
|
||||
"""
|
||||
from flask import current_app, g
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
||||
from flask import current_app, g
|
||||
|
||||
# Mandantencodes werden als Dateinamensbestandteil verwendet. Nur Zeichen
|
||||
# zulassen, die keinen Pfadwechsel (../) oder Sonderpfade erzeugen können.
|
||||
_TENANT_FILE_RE = re.compile(r'^[A-Za-z0-9_-]+$')
|
||||
|
||||
|
||||
def str2pl_filename(tenant_code):
|
||||
"""Relativer Dateiname der mandantenspezifischen Polyline-Datei."""
|
||||
tenant_code = (tenant_code or '').strip()
|
||||
if not _TENANT_FILE_RE.match(tenant_code):
|
||||
raise ValueError('Ungültiger Mandantencode für den Polyline-Dateinamen')
|
||||
return f'js/str2pl-{tenant_code}.js'
|
||||
|
||||
|
||||
def str2pl_asset(tenant_code=None):
|
||||
"""Dateiname des Polyline-Skripts für einen Mandanten.
|
||||
|
||||
Existiert ``static/js/str2pl-<tenant>.js``, wird diese mandantenspezifische
|
||||
Datei verwendet. Andernfalls wird auf die gemeinsame ``str2pl.js``
|
||||
zurückgegriffen.
|
||||
"""
|
||||
if tenant_code is None:
|
||||
tenant_code = getattr(g, 'tenant_code', None)
|
||||
tenant_code = (tenant_code or '').strip()
|
||||
|
||||
if tenant_code and _TENANT_FILE_RE.match(tenant_code):
|
||||
candidate = str2pl_filename(tenant_code)
|
||||
static_folder = current_app.static_folder
|
||||
if static_folder and os.path.isfile(os.path.join(static_folder, candidate)):
|
||||
return candidate
|
||||
|
||||
return 'js/str2pl.js'
|
||||
|
||||
|
||||
def str2pl_asset_version(tenant_code=None):
|
||||
"""Cache-Busting-Version der aktuell verwendeten Polyline-Datei."""
|
||||
filename = str2pl_asset(tenant_code)
|
||||
static_folder = current_app.static_folder
|
||||
if not static_folder:
|
||||
return 0
|
||||
try:
|
||||
stat = os.stat(os.path.join(static_folder, filename))
|
||||
except OSError:
|
||||
return 0
|
||||
return f'{int(stat.st_mtime)}-{stat.st_size}'
|
||||
|
||||
|
||||
def get_tenant_id():
|
||||
|
||||
Reference in new issue
Block a user