umap-project 2.1.0__py3-none-any.whl → 2.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of umap-project might be problematic. Click here for more details.

umap/__init__.py CHANGED
@@ -1 +1 @@
1
- VERSION = "2.1.0"
1
+ VERSION = "2.1.2"
umap/models.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import json
2
+ import operator
2
3
  import os
3
4
  import time
4
5
  import uuid
@@ -471,17 +472,14 @@ class DataLayer(NamedModel):
471
472
  "size": self.geojson.storage.size(self.get_version_path(name)),
472
473
  }
473
474
 
474
- def get_versions(self):
475
+ @property
476
+ def versions(self):
475
477
  root = self.storage_root()
476
478
  names = self.geojson.storage.listdir(root)[1]
477
479
  names = [name for name in names if self.is_valid_version(name)]
478
- names.sort(reverse=True) # Recent first.
479
- return names
480
-
481
- @property
482
- def versions(self):
483
- names = self.get_versions()
484
- return [self.version_metadata(name) for name in names]
480
+ versions = [self.version_metadata(name) for name in names]
481
+ versions.sort(reverse=True, key=operator.itemgetter("at"))
482
+ return versions
485
483
 
486
484
  def get_version(self, name):
487
485
  path = self.get_version_path(name)
@@ -493,8 +491,13 @@ class DataLayer(NamedModel):
493
491
 
494
492
  def purge_old_versions(self):
495
493
  root = self.storage_root()
496
- names = self.get_versions()[settings.UMAP_KEEP_VERSIONS :]
497
- for name in names:
494
+ versions = self.versions[settings.UMAP_KEEP_VERSIONS :]
495
+ for version in versions:
496
+ name = version["name"]
497
+ # Should not be in the list, but ensure to not delete the file
498
+ # currently used in database
499
+ if self.geojson.name.endswith(name):
500
+ continue
498
501
  try:
499
502
  self.geojson.storage.delete(os.path.join(root, name))
500
503
  except FileNotFoundError:
@@ -503,8 +506,12 @@ class DataLayer(NamedModel):
503
506
  def purge_gzip(self):
504
507
  root = self.storage_root()
505
508
  names = self.geojson.storage.listdir(root)[1]
509
+ prefixes = [f"{self.pk}_"]
510
+ if self.old_id:
511
+ prefixes.append(f"{self.old_id}_")
512
+ prefixes = tuple(prefixes)
506
513
  for name in names:
507
- if name.startswith(f"{self.pk}_") and name.endswith(".gz"):
514
+ if name.startswith(prefixes) and name.endswith(".gz"):
508
515
  self.geojson.storage.delete(os.path.join(root, name))
509
516
 
510
517
  def can_edit(self, user=None, request=None):
@@ -146,7 +146,7 @@ export class ServerRequest extends Request {
146
146
  _onNOK(error) {
147
147
  if (error.status === 403) {
148
148
  this.ui.alert({
149
- content: message || L._('Action not allowed :('),
149
+ content: error.message || L._('Action not allowed :('),
150
150
  level: 'error',
151
151
  })
152
152
  }
@@ -1,4 +1,5 @@
1
1
  import os
2
+ from pathlib import Path
2
3
 
3
4
  import pytest
4
5
  from django.core.files.base import ContentFile
@@ -60,30 +61,43 @@ def test_clone_should_clone_geojson_too(datalayer):
60
61
  assert clone.geojson.path != datalayer.geojson.path
61
62
 
62
63
 
63
- def test_should_remove_old_versions_on_save(datalayer, map, settings):
64
+ def test_should_remove_old_versions_on_save(map, settings):
65
+ datalayer = DataLayerFactory(uuid="0f1161c0-c07f-4ba4-86c5-8d8981d8a813", old_id=17)
64
66
  settings.UMAP_KEEP_VERSIONS = 3
65
- root = datalayer.storage_root()
67
+ root = Path(datalayer.storage_root())
66
68
  before = len(datalayer.geojson.storage.listdir(root)[1])
67
- newer = f"{root}/{datalayer.pk}_1440924889.geojson"
68
- medium = f"{root}/{datalayer.pk}_1440923687.geojson"
69
- older = f"{root}/{datalayer.pk}_1440918637.geojson"
70
- other = f"{root}/123456_1440918637.geojson"
71
- for path in [medium, newer, older, other]:
72
- datalayer.geojson.storage.save(path, ContentFile("{}"))
73
- datalayer.geojson.storage.save(path + ".gz", ContentFile("{}"))
74
- assert len(datalayer.geojson.storage.listdir(root)[1]) == 8 + before
69
+ newer = f"{datalayer.pk}_1440924889.geojson"
70
+ medium = f"{datalayer.pk}_1440923687.geojson"
71
+ older = f"{datalayer.pk}_1440918637.geojson"
72
+ with_old_id = f"{datalayer.old_id}_1440918537.geojson"
73
+ other = "123456_1440918637.geojson"
74
+ for path in [medium, newer, older, with_old_id, other]:
75
+ datalayer.geojson.storage.save(root / path, ContentFile("{}"))
76
+ datalayer.geojson.storage.save(root / f"{path}.gz", ContentFile("{}"))
77
+ assert len(datalayer.geojson.storage.listdir(root)[1]) == 10 + before
78
+ files = datalayer.geojson.storage.listdir(root)[1]
79
+ # Those files should be present before save, which will purge them
80
+ assert older in files
81
+ assert older + ".gz" in files
82
+ assert with_old_id in files
83
+ assert with_old_id + ".gz" in files
75
84
  datalayer.save()
76
85
  files = datalayer.geojson.storage.listdir(root)[1]
77
86
  # Flat + gz files, but not latest gz, which is created at first datalayer read.
87
+ # older and with_old_id should have been removed
78
88
  assert len(files) == 5
79
- assert os.path.basename(newer) in files
80
- assert os.path.basename(medium) in files
81
- assert os.path.basename(datalayer.geojson.path) in files
89
+ assert newer in files
90
+ assert medium in files
91
+ assert Path(datalayer.geojson.path).name in files
82
92
  # File from another datalayer, purge should have impacted it.
83
- assert os.path.basename(other) in files
84
- assert os.path.basename(other + ".gz") in files
85
- assert os.path.basename(older) not in files
86
- assert os.path.basename(older + ".gz") not in files
93
+ assert other in files
94
+ assert other + ".gz" in files
95
+ assert older not in files
96
+ assert older + ".gz" not in files
97
+ assert with_old_id not in files
98
+ assert with_old_id + ".gz" not in files
99
+ names = [v["name"] for v in datalayer.versions]
100
+ assert names == [Path(datalayer.geojson.name).name, newer, medium]
87
101
 
88
102
 
89
103
  def test_anonymous_cannot_edit_in_editors_mode(datalayer):
@@ -44,6 +44,16 @@ def test_get_with_public_mode(client, settings, datalayer, map):
44
44
  assert j["type"] == "FeatureCollection"
45
45
 
46
46
 
47
+ def test_get_with_x_accel_redirect(client, settings, datalayer, map):
48
+ settings.UMAP_XSENDFILE_HEADER = "X-Accel-Redirect"
49
+ url = reverse("datalayer_view", args=(map.pk, datalayer.pk))
50
+ response = client.get(url)
51
+ assert response.status_code == 200
52
+ assert "X-Accel-Redirect" in response.headers
53
+ assert response["X-Accel-Redirect"].startswith("/internal/datalayer/")
54
+ assert response["X-Accel-Redirect"].endswith(".geojson")
55
+
56
+
47
57
  def test_get_with_open_mode(client, settings, datalayer, map):
48
58
  map.share_status = Map.PUBLIC
49
59
  map.save()
umap/views.py CHANGED
@@ -1020,8 +1020,8 @@ class DataLayerView(GZipMixin, BaseDetailView):
1020
1020
 
1021
1021
  if getattr(settings, "UMAP_XSENDFILE_HEADER", None):
1022
1022
  response = HttpResponse()
1023
- path = path.replace(settings.MEDIA_ROOT, "/internal")
1024
- response[settings.UMAP_XSENDFILE_HEADER] = path
1023
+ internal_path = str(path).replace(settings.MEDIA_ROOT, "/internal")
1024
+ response[settings.UMAP_XSENDFILE_HEADER] = internal_path
1025
1025
  else:
1026
1026
  # Do not use in production
1027
1027
  # (no gzip/cache-control/If-Modified-Since/If-None-Match)
@@ -1073,7 +1073,8 @@ class DataLayerUpdate(FormLessEditMixin, GZipMixin, UpdateView):
1073
1073
  """
1074
1074
 
1075
1075
  # Use the provided info to find the correct version in our storage.
1076
- for name in self.object.get_versions():
1076
+ for version in self.object.versions:
1077
+ name = version["name"]
1077
1078
  path = Path(settings.MEDIA_ROOT) / self.object.get_version_path(name)
1078
1079
  if reference_version == self.read_version(path):
1079
1080
  with open(path) as f:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: umap-project
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Create maps with OpenStreetMap layers in a minute and embed them in your site.
5
5
  Author-email: Yohan Boniface <yb@enix.org>
6
6
  Maintainer-email: David Larlet <david@larlet.fr>
@@ -1,4 +1,4 @@
1
- umap/__init__.py,sha256=NUYNa7PhqumIE5zRl-LPrL7HPtV6WkBx8Yf93ea7cEs,18
1
+ umap/__init__.py,sha256=g3cxz98sq2sH94EJfsXt9vgetLlENXp3IEKtEY6wMyg,18
2
2
  umap/admin.py,sha256=gL6zrexmDbIKIqOKHCuAM5wtqr8FIQkRtjbcXcNyBrs,749
3
3
  umap/apps.py,sha256=5ssKqPUuNJlapaBmr4LY_HDb7J1NFCT3wzythxQOOfs,109
4
4
  umap/autocomplete.py,sha256=WUsbsVBl_KzzEzxB4g3rAoS5-eEvCZGtelVzXeOFV90,444
@@ -8,11 +8,11 @@ umap/fields.py,sha256=c32tKWKF8aThrCXDJblwo0n9n2ET6hxBYzEupfr0B4o,900
8
8
  umap/forms.py,sha256=bpNLMSsB1sHUcaf24MmUpwVdEz_SHy_ohfhQMoKwDzI,3128
9
9
  umap/managers.py,sha256=-lBK0xYFRDfX76qDRdLnZOA8jEPYseEwIj8QOiHVM4w,243
10
10
  umap/middleware.py,sha256=p8EPW_gYW8Wh2lk0DNIAkZQbYlBZugW7Yq4iiA7L4aE,514
11
- umap/models.py,sha256=Ol1AqtsSwNXCU67yJxCyWxF8EVpHIWLjZy4rcHPHZn0,17180
11
+ umap/models.py,sha256=uraqRRDec7h0DWALb2yMJxaGgYIAN4BZTv8OYnktaWc,17519
12
12
  umap/storage.py,sha256=bdjjdn768fZJYsyDNBxgwLvSu6rhde_Cc6yzyZZDmSg,2282
13
13
  umap/urls.py,sha256=frMCdfDQ2QB39xxqI8I12EeT-yChn5KDwDp-kQxp930,6876
14
14
  umap/utils.py,sha256=19i8ibi-1IXxafT4k_yOHMhD-DsPH74Ll9qw-UrUkM4,5856
15
- umap/views.py,sha256=o91hRkYlMZP9QjH-BrD_2T4SV40C7vwmhOeBr80ijdg,41020
15
+ umap/views.py,sha256=N2J9BOP5Yq6ClTy2K_11l34pRIgCL4jwvU_n2K_wM8c,41075
16
16
  umap/wsgi.py,sha256=IopIgnDZbCus3XpSetTHnra9VyzWi0Y2tJo-CmfTWCY,1132
17
17
  umap/bin/__init__.py,sha256=iA3ON4A6NCpenrn3q2OgefUKF5QRFIQS-FtS0pxruI8,234
18
18
  umap/locale/am_ET/LC_MESSAGES/django.mo,sha256=xdPMnJ3Z0fkxocaO7IKexPyomuWUKak01D2T6pVruco,5457
@@ -206,7 +206,7 @@ umap/static/umap/js/modules/browser.js,sha256=-RPyTmnd8_d9FhkmL4wP3DlQHkaoA9QIAd
206
206
  umap/static/umap/js/modules/global.js,sha256=tp8tCmAqKlSVNPi7w3n9wiMTb5Wh-DVh_XedZz_Lo60,454
207
207
  umap/static/umap/js/modules/i18n.js,sha256=5EmqVuxda24BvXPZb8uOXNc21vHs7Rx8RF9fVZsnTR8,1207
208
208
  umap/static/umap/js/modules/leaflet-configure.js,sha256=P3aD8iNGxuVNv-xW4Di4txAjNmnlpKtCCzDvPaKEdQ8,243
209
- umap/static/umap/js/modules/request.js,sha256=7qMUuC5Q2Ql0U8bbojUMSdGMsWrvyqM364j3uF0sLZs,4001
209
+ umap/static/umap/js/modules/request.js,sha256=v10pLYqFcKeQeMTcjC1Vm9wlp5ehRFKQ65HfT7VrYLY,4007
210
210
  umap/static/umap/js/modules/schema.js,sha256=vP60-MU4rRowRrRQzWRQbT9vu4Klrp5sRTAy_ZgYyxQ,8926
211
211
  umap/static/umap/js/modules/urls.js,sha256=isqV_dslYuNQIErzf5Wgq-oZqORRK4as6e78sfQgaUo,1308
212
212
  umap/static/umap/js/modules/utils.js,sha256=sjCXiF3fb86evhDDJBDSRHjXTYTcKtjeC7SoNpFl680,558
@@ -429,8 +429,8 @@ umap/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
429
429
  umap/tests/base.py,sha256=WcrRnmgcTvx9hHekIJsGyVhFwvyNrgT7PYQ6DPwuAZU,4200
430
430
  umap/tests/conftest.py,sha256=hlUPzNq7JakJnT2k5LOp7a8CKhHBWhz3v9EwioPOVUg,1367
431
431
  umap/tests/settings.py,sha256=qzKYcWzVXUVYxNdv8m7lLV-xkNrV8A8-LWliTJagHOE,716
432
- umap/tests/test_datalayer.py,sha256=1C2z0VACCime11CMbp9ehbj-knLpW8r6j72EQ_hKLU4,6322
433
- umap/tests/test_datalayer_views.py,sha256=CG0ycp-z3brvsC8bwOjPzeCevue-nS357nHSDGAbyTI,21662
432
+ umap/tests/test_datalayer.py,sha256=HJYSQ11LVQe47nnsXdFeX5Ny4WMDPUYg3frnM5G1IzQ,6888
433
+ umap/tests/test_datalayer_views.py,sha256=AJ-0YBorAgKZaKGd8rSYDguqy8acrz54EaQdfkNOH48,22111
434
434
  umap/tests/test_licence.py,sha256=BxNY3gdKhIoc2u5OPmAkmjCp0jJN-Jm-uPOfAZlpOHA,339
435
435
  umap/tests/test_map.py,sha256=nX2eE1HJY3bjycXulglK2SY1ybcnjDVgr0yntX6OgyA,3836
436
436
  umap/tests/test_map_views.py,sha256=6EW0jqDepS8y117sfCbDwmhnhu0vHup3GXE57IrkAnI,31350
@@ -472,8 +472,8 @@ umap/tests/integration/test_slideshow.py,sha256=uLPw4SyhLgpqU4-jrTu5vKSqYuZG7hXj
472
472
  umap/tests/integration/test_star.py,sha256=icB5SbFbXe4KYp3DIJ0xAwCrSQS2rweqIaQTAng3CfY,842
473
473
  umap/tests/integration/test_statics.py,sha256=UqaN2O56yHwn1tEE9I8B1lGnyztDLC0p7_rG6J7vLIs,1494
474
474
  umap/tests/integration/test_tilelayer.py,sha256=3Jn1KdOM39DuDkLG-P3heDrsCiYvD6_FEnt0EKGjj5g,4141
475
- umap_project-2.1.0.dist-info/METADATA,sha256=WjxOBkcnYktf5E_US6kyu9jzuBYh_W3GePuO9i3IM90,2559
476
- umap_project-2.1.0.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
477
- umap_project-2.1.0.dist-info/entry_points.txt,sha256=gz-KDQfEsMLBae8ABOD3foJsCYGPW1tA4Y394R_1RW8,39
478
- umap_project-2.1.0.dist-info/licenses/LICENSE,sha256=kQtrtRKgiPhcl7aO0-lmvbrNAXu7WHyiXvPrUk-TD2Q,820
479
- umap_project-2.1.0.dist-info/RECORD,,
475
+ umap_project-2.1.2.dist-info/METADATA,sha256=pEqfRBAX0YjxA4wm2SBm7eYsska6n0IjIwwjU0GnoKQ,2559
476
+ umap_project-2.1.2.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
477
+ umap_project-2.1.2.dist-info/entry_points.txt,sha256=gz-KDQfEsMLBae8ABOD3foJsCYGPW1tA4Y394R_1RW8,39
478
+ umap_project-2.1.2.dist-info/licenses/LICENSE,sha256=kQtrtRKgiPhcl7aO0-lmvbrNAXu7WHyiXvPrUk-TD2Q,820
479
+ umap_project-2.1.2.dist-info/RECORD,,