API & Client - update map attribution to match tile server - fix #54

This commit is contained in:
Sam
2020-09-16 13:01:15 +02:00
parent a5e40612ba
commit a5a2033918
16 changed files with 242 additions and 123 deletions

View File

@ -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 (

View File

@ -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,
}

View File

@ -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',
'&copy; <a href="http://www.openstreetmap.org/copyright" '
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a>'
' contributors',
),
}
class DevelopmentConfig(BaseConfig):

View File

@ -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)

View File

@ -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'] == (
'&copy; <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

View File

@ -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'] == (
'&copy; <a href="http://www.openstreetmap.org/copyright" '
'target="_blank" rel="noopener noreferrer">OpenStreetMap</a> '
'contributors'
)