Replace LEAFLET_STORAGE_XXX settings by UMAP_XXXX
We keep a retrocompatibility for now.
This commit is contained in:
parent
e0169d569e
commit
62a825e6ed
10 changed files with 25 additions and 21 deletions
|
@ -17,7 +17,7 @@ LOGIN_URL = (reverse_lazy(LOGIN_URL) if not LOGIN_URL.startswith("/")
|
||||||
def login_required_if_not_anonymous_allowed(view_func):
|
def login_required_if_not_anonymous_allowed(view_func):
|
||||||
@wraps(view_func)
|
@wraps(view_func)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
if (not getattr(settings, "LEAFLET_STORAGE_ALLOW_ANONYMOUS", False)
|
if (not getattr(settings, "UMAP_ALLOW_ANONYMOUS", False)
|
||||||
and not request.user.is_authenticated):
|
and not request.user.is_authenticated):
|
||||||
return simple_json_response(login_required=str(LOGIN_URL))
|
return simple_json_response(login_required=str(LOGIN_URL))
|
||||||
return view_func(request, *args, **kwargs)
|
return view_func(request, *args, **kwargs)
|
||||||
|
|
|
@ -38,7 +38,7 @@ def get_default_licence():
|
||||||
"""
|
"""
|
||||||
return Licence.objects.get_or_create(
|
return Licence.objects.get_or_create(
|
||||||
# can't use ugettext_lazy for database storage, see #13965
|
# can't use ugettext_lazy for database storage, see #13965
|
||||||
name=getattr(settings, "LEAFLET_STORAGE_DEFAULT_LICENCE_NAME",
|
name=getattr(settings, "UMAP_DEFAULT_LICENCE_NAME",
|
||||||
'No licence set')
|
'No licence set')
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ class Map(NamedModel):
|
||||||
"""
|
"""
|
||||||
can = False
|
can = False
|
||||||
if request and not self.owner:
|
if request and not self.owner:
|
||||||
if (getattr(settings, "LEAFLET_STORAGE_ALLOW_ANONYMOUS", False)
|
if (getattr(settings, "UMAP_ALLOW_ANONYMOUS", False)
|
||||||
and self.is_anonymous_owner(request)):
|
and self.is_anonymous_owner(request)):
|
||||||
can = True
|
can = True
|
||||||
if user and user.is_authenticated:
|
if user and user.is_authenticated:
|
||||||
|
@ -346,7 +346,7 @@ class DataLayer(NamedModel):
|
||||||
|
|
||||||
def purge_old_versions(self):
|
def purge_old_versions(self):
|
||||||
root = self.storage_root()
|
root = self.storage_root()
|
||||||
names = self.get_versions()[settings.LEAFLET_STORAGE_KEEP_VERSIONS:]
|
names = self.get_versions()[settings.UMAP_KEEP_VERSIONS:]
|
||||||
for name in names:
|
for name in names:
|
||||||
for ext in ['', '.gz']:
|
for ext in ['', '.gz']:
|
||||||
path = os.path.join(root, name + ext)
|
path = os.path.join(root, name + ext)
|
||||||
|
|
|
@ -35,4 +35,8 @@ else:
|
||||||
print('Loaded local config from', path)
|
print('Loaded local config from', path)
|
||||||
for key in dir(d):
|
for key in dir(d):
|
||||||
if key.isupper():
|
if key.isupper():
|
||||||
|
if key.startswith('LEAFLET_STORAGE'):
|
||||||
|
# Retrocompat pre 1.0, remove me in 1.1.
|
||||||
|
globals()['UMAP' + key[15:]] = getattr(d, key)
|
||||||
|
else:
|
||||||
globals()[key] = getattr(d, key)
|
globals()[key] = getattr(d, key)
|
||||||
|
|
|
@ -152,12 +152,12 @@ AUTHENTICATION_BACKENDS += (
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Miscellaneous project settings
|
# Miscellaneous project settings
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
LEAFLET_STORAGE_ALLOW_ANONYMOUS = False
|
UMAP_ALLOW_ANONYMOUS = False
|
||||||
LEAFLET_STORAGE_EXTRA_URLS = {
|
UMAP_EXTRA_URLS = {
|
||||||
'routing': 'http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}', # noqa
|
'routing': 'http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}', # noqa
|
||||||
'ajax_proxy': '/ajax-proxy/?url={url}'
|
'ajax_proxy': '/ajax-proxy/?url={url}'
|
||||||
}
|
}
|
||||||
LEAFLET_STORAGE_KEEP_VERSIONS = 10
|
UMAP_KEEP_VERSIONS = 10
|
||||||
SITE_URL = "http://umap.org"
|
SITE_URL = "http://umap.org"
|
||||||
SITE_NAME = 'uMap'
|
SITE_NAME = 'uMap'
|
||||||
UMAP_DEMO_SITE = False
|
UMAP_DEMO_SITE = False
|
||||||
|
|
|
@ -69,7 +69,7 @@ SOCIAL_AUTH_BACKEND_ERROR_URL = "/"
|
||||||
UMAP_DEMO_SITE = True
|
UMAP_DEMO_SITE = True
|
||||||
|
|
||||||
# Whether to allow non authenticated people to create maps.
|
# Whether to allow non authenticated people to create maps.
|
||||||
LEAFLET_STORAGE_ALLOW_ANONYMOUS = True
|
UMAP_ALLOW_ANONYMOUS = True
|
||||||
|
|
||||||
# This setting will exclude empty maps (in fact, it will exclude all maps where
|
# This setting will exclude empty maps (in fact, it will exclude all maps where
|
||||||
# the default center has not been updated)
|
# the default center has not been updated)
|
||||||
|
@ -110,4 +110,4 @@ LEAFLET_LATITUDE = 51
|
||||||
LEAFLET_ZOOM = 6
|
LEAFLET_ZOOM = 6
|
||||||
|
|
||||||
# Number of old version to keep per datalayer.
|
# Number of old version to keep per datalayer.
|
||||||
LEAFLET_STORAGE_KEEP_VERSIONS = 10
|
UMAP_KEEP_VERSIONS = 10
|
||||||
|
|
|
@ -51,7 +51,7 @@ def cookieclient(client, anonymap):
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def allow_anonymous(settings):
|
def allow_anonymous(settings):
|
||||||
settings.LEAFLET_STORAGE_ALLOW_ANONYMOUS = True
|
settings.UMAP_ALLOW_ANONYMOUS = True
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -59,7 +59,7 @@ def test_clone_should_clone_geojson_too(datalayer):
|
||||||
|
|
||||||
|
|
||||||
def test_should_remove_old_versions_on_save(datalayer, map, settings):
|
def test_should_remove_old_versions_on_save(datalayer, map, settings):
|
||||||
settings.LEAFLET_STORAGE_KEEP_VERSIONS = 3
|
settings.UMAP_KEEP_VERSIONS = 3
|
||||||
root = datalayer.storage_root()
|
root = datalayer.storage_root()
|
||||||
before = len(datalayer.geojson.storage.listdir(root)[1])
|
before = len(datalayer.geojson.storage.listdir(root)[1])
|
||||||
newer = '%s/%s_1440924889.geojson' % (root, datalayer.pk)
|
newer = '%s/%s_1440924889.geojson' % (root, datalayer.pk)
|
||||||
|
|
|
@ -24,7 +24,7 @@ def post_data():
|
||||||
def test_get(client, settings, datalayer):
|
def test_get(client, settings, datalayer):
|
||||||
url = reverse('datalayer_view', args=(datalayer.pk, ))
|
url = reverse('datalayer_view', args=(datalayer.pk, ))
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
if getattr(settings, 'LEAFLET_STORAGE_XSENDFILE_HEADER', None):
|
if getattr(settings, 'UMAP_XSENDFILE_HEADER', None):
|
||||||
assert response['ETag'] is not None
|
assert response['ETag'] is not None
|
||||||
assert response['Last-Modified'] is not None
|
assert response['Last-Modified'] is not None
|
||||||
assert response['Cache-Control'] is not None
|
assert response['Cache-Control'] is not None
|
||||||
|
@ -90,7 +90,7 @@ def test_should_not_be_possible_to_delete_with_wrong_map_id_in_url(client, datal
|
||||||
def test_get_gzipped(client, datalayer, settings):
|
def test_get_gzipped(client, datalayer, settings):
|
||||||
url = reverse('datalayer_view', args=(datalayer.pk, ))
|
url = reverse('datalayer_view', args=(datalayer.pk, ))
|
||||||
response = client.get(url, HTTP_ACCEPT_ENCODING='gzip')
|
response = client.get(url, HTTP_ACCEPT_ENCODING='gzip')
|
||||||
if getattr(settings, 'LEAFLET_STORAGE_XSENDFILE_HEADER', None):
|
if getattr(settings, 'UMAP_XSENDFILE_HEADER', None):
|
||||||
assert response['ETag'] is not None
|
assert response['ETag'] is not None
|
||||||
assert response['Last-Modified'] is not None
|
assert response['Last-Modified'] is not None
|
||||||
assert response['Cache-Control'] is not None
|
assert response['Cache-Control'] is not None
|
||||||
|
|
|
@ -36,7 +36,7 @@ def test_create(client, user, post_data):
|
||||||
|
|
||||||
|
|
||||||
def test_map_create_permissions(client, settings):
|
def test_map_create_permissions(client, settings):
|
||||||
settings.LEAFLET_STORAGE_ALLOW_ANONYMOUS = False
|
settings.UMAP_ALLOW_ANONYMOUS = False
|
||||||
url = reverse('map_create')
|
url = reverse('map_create')
|
||||||
# POST anonymous
|
# POST anonymous
|
||||||
response = client.post(url, {})
|
response = client.post(url, {})
|
||||||
|
@ -169,7 +169,7 @@ def test_clone_map_should_create_a_new_instance(client, map):
|
||||||
|
|
||||||
|
|
||||||
def test_user_not_allowed_should_not_clone_map(client, map, user, settings):
|
def test_user_not_allowed_should_not_clone_map(client, map, user, settings):
|
||||||
settings.LEAFLET_STORAGE_ALLOW_ANONYMOUS = False
|
settings.UMAP_ALLOW_ANONYMOUS = False
|
||||||
assert Map.objects.count() == 1
|
assert Map.objects.count() == 1
|
||||||
url = reverse('map_clone', kwargs={'map_id': map.pk})
|
url = reverse('map_clone', kwargs={'map_id': map.pk})
|
||||||
map.edit_status = map.OWNER
|
map.edit_status = map.OWNER
|
||||||
|
|
|
@ -304,7 +304,7 @@ def _urls_for_js(urls=None):
|
||||||
urls = [url.name for url in urlpatterns + i18n_urls
|
urls = [url.name for url in urlpatterns + i18n_urls
|
||||||
if getattr(url, 'name', None)]
|
if getattr(url, 'name', None)]
|
||||||
urls = dict(zip(urls, [get_uri_template(url) for url in urls]))
|
urls = dict(zip(urls, [get_uri_template(url) for url in urls]))
|
||||||
urls.update(getattr(settings, 'LEAFLET_STORAGE_EXTRA_URLS', {}))
|
urls.update(getattr(settings, 'UMAP_EXTRA_URLS', {}))
|
||||||
return urls
|
return urls
|
||||||
|
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ class MapDelete(DeleteView):
|
||||||
class MapClone(View):
|
class MapClone(View):
|
||||||
|
|
||||||
def post(self, *args, **kwargs):
|
def post(self, *args, **kwargs):
|
||||||
if not getattr(settings, "LEAFLET_STORAGE_ALLOW_ANONYMOUS", False) \
|
if not getattr(settings, "UMAP_ALLOW_ANONYMOUS", False) \
|
||||||
and not self.request.user.is_authenticated:
|
and not self.request.user.is_authenticated:
|
||||||
return HttpResponseForbidden('Forbidden')
|
return HttpResponseForbidden('Forbidden')
|
||||||
owner = self.request.user if self.request.user.is_authenticated else None
|
owner = self.request.user if self.request.user.is_authenticated else None
|
||||||
|
@ -674,7 +674,7 @@ class GZipMixin(object):
|
||||||
path = self._path()
|
path = self._path()
|
||||||
statobj = os.stat(path)
|
statobj = os.stat(path)
|
||||||
ae = self.request.META.get('HTTP_ACCEPT_ENCODING', '')
|
ae = self.request.META.get('HTTP_ACCEPT_ENCODING', '')
|
||||||
if re_accepts_gzip.search(ae) and getattr(settings, 'LEAFLET_STORAGE_GZIP', True):
|
if re_accepts_gzip.search(ae) and getattr(settings, 'UMAP_GZIP', True):
|
||||||
gzip_path = "{path}{ext}".format(path=path, ext=self.EXT)
|
gzip_path = "{path}{ext}".format(path=path, ext=self.EXT)
|
||||||
up_to_date = True
|
up_to_date = True
|
||||||
if not os.path.exists(gzip_path):
|
if not os.path.exists(gzip_path):
|
||||||
|
@ -701,10 +701,10 @@ class DataLayerView(GZipMixin, BaseDetailView):
|
||||||
response = None
|
response = None
|
||||||
path = self.path()
|
path = self.path()
|
||||||
|
|
||||||
if getattr(settings, 'LEAFLET_STORAGE_XSENDFILE_HEADER', None):
|
if getattr(settings, 'UMAP_XSENDFILE_HEADER', None):
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
path = path.replace(settings.MEDIA_ROOT, '/internal')
|
path = path.replace(settings.MEDIA_ROOT, '/internal')
|
||||||
response[settings.LEAFLET_STORAGE_XSENDFILE_HEADER] = path
|
response[settings.UMAP_XSENDFILE_HEADER] = path
|
||||||
else:
|
else:
|
||||||
# TODO IMS
|
# TODO IMS
|
||||||
statobj = os.stat(path)
|
statobj = os.stat(path)
|
||||||
|
|
Loading…
Reference in a new issue