API & Client - update map attribution to match tile server - fix #54
This commit is contained in:
@ -5,15 +5,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
import requests
|
||||
from fittrackee_api import appLog, db
|
||||
from flask import (
|
||||
Blueprint,
|
||||
Response,
|
||||
current_app,
|
||||
jsonify,
|
||||
request,
|
||||
send_file,
|
||||
stream_with_context,
|
||||
)
|
||||
from flask import Blueprint, Response, current_app, jsonify, request, send_file
|
||||
from sqlalchemy import exc
|
||||
|
||||
from ..users.utils import (
|
||||
@ -754,7 +746,7 @@ def get_map_tile(s, z, x, y):
|
||||
Status codes are status codes returned by tile server
|
||||
|
||||
"""
|
||||
url = current_app.config["TILE_SERVER_URL"].format(s=s, z=z, x=x, y=y)
|
||||
url = current_app.config['TILE_SERVER']['URL'].format(s=s, z=z, x=x, y=y)
|
||||
headers = {'User-Agent': 'Mozilla/5.0'}
|
||||
response = requests.get(url, headers=headers)
|
||||
return (
|
||||
|
@ -20,6 +20,10 @@ class AppConfig(db.Model):
|
||||
nb_users = User.query.count()
|
||||
return self.max_users == 0 or nb_users < self.max_users
|
||||
|
||||
@property
|
||||
def map_attribution(self):
|
||||
return current_app.config['TILE_SERVER']['ATTRIBUTION']
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
"gpx_limit_import": self.gpx_limit_import,
|
||||
@ -27,6 +31,7 @@ class AppConfig(db.Model):
|
||||
"max_single_file_size": self.max_single_file_size,
|
||||
"max_zip_file_size": self.max_zip_file_size,
|
||||
"max_users": self.max_users,
|
||||
"map_attribution": self.map_attribution,
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,9 +28,18 @@ class BaseConfig:
|
||||
EMAIL_URL = os.environ.get('EMAIL_URL')
|
||||
SENDER_EMAIL = os.environ.get('SENDER_EMAIL')
|
||||
DRAMATIQ_BROKER = broker
|
||||
TILE_SERVER_URL = os.environ.get(
|
||||
'TILE_SERVER_URL', 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
||||
)
|
||||
TILE_SERVER = {
|
||||
'URL': os.environ.get(
|
||||
'TILE_SERVER_URL',
|
||||
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
),
|
||||
'ATTRIBUTION': os.environ.get(
|
||||
'MAP_ATTRIBUTION',
|
||||
'© <a href="http://www.openstreetmap.org/copyright" '
|
||||
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a>'
|
||||
' contributors',
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class DevelopmentConfig(BaseConfig):
|
||||
|
@ -48,6 +48,8 @@ def get_app(with_config=False):
|
||||
@pytest.fixture
|
||||
def app(monkeypatch):
|
||||
monkeypatch.setenv('EMAIL_URL', 'smtp://none:none@0.0.0.0:1025')
|
||||
monkeypatch.delenv('TILE_SERVER_URL')
|
||||
monkeypatch.delenv('MAP_ATTRIBUTION')
|
||||
yield from get_app(with_config=True)
|
||||
|
||||
|
||||
|
@ -26,6 +26,11 @@ class TestGetConfig:
|
||||
assert data['data']['max_single_file_size'] == 1048576
|
||||
assert data['data']['max_zip_file_size'] == 10485760
|
||||
assert data['data']['max_users'] == 100
|
||||
assert data['data']['map_attribution'] == (
|
||||
'© <a href="http://www.openstreetmap.org/copyright" '
|
||||
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a> '
|
||||
'contributors'
|
||||
)
|
||||
|
||||
def test_it_returns_error_if_application_has_no_config(
|
||||
self, app_no_config, user_1_admin
|
||||
|
@ -12,3 +12,8 @@ class TestConfigModel:
|
||||
assert serialized_app_config['max_single_file_size'] == 1048576
|
||||
assert serialized_app_config['max_zip_file_size'] == 10485760
|
||||
assert serialized_app_config['max_users'] == 100
|
||||
assert serialized_app_config['map_attribution'] == (
|
||||
'© <a href="http://www.openstreetmap.org/copyright" '
|
||||
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a> '
|
||||
'contributors'
|
||||
)
|
||||
|
Reference in New Issue
Block a user