From c46f59e3dd2251014f5544cb78b30d37aad0b175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 22 Feb 2024 11:10:52 +0100 Subject: [PATCH] chore: Use datalayers' UUIDs in the views --- umap/models.py | 3 ++- umap/urls.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/umap/models.py b/umap/models.py index 9bda2979..780aeb75 100644 --- a/umap/models.py +++ b/umap/models.py @@ -374,7 +374,7 @@ class DataLayer(NamedModel): (EDITORS, _("Editors only")), (OWNER, _("Owner only")), ) - uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False) + uuid = models.UUIDField(unique=True, primary_key=True, default=uuid.uuid4, editable=False) map = models.ForeignKey(Map, on_delete=models.CASCADE) description = models.TextField(blank=True, null=True, verbose_name=_("description")) geojson = models.FileField(upload_to=upload_to, blank=True, null=True) @@ -437,6 +437,7 @@ class DataLayer(NamedModel): def clone(self, map_inst=None): new = self.__class__.objects.get(pk=self.pk) + new._state.adding = True new.pk = None if map_inst: new.map = map_inst diff --git a/umap/urls.py b/umap/urls.py index 72fff437..09ce7f24 100644 --- a/umap/urls.py +++ b/umap/urls.py @@ -21,6 +21,8 @@ from .utils import decorated_patterns admin.autodiscover() +uuid = r"[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}" + urlpatterns = [ re_path(r"^admin/", admin.site.urls), re_path("", include("social_django.urls", namespace="social")), @@ -73,17 +75,17 @@ i18n_urls = [ i18n_urls += decorated_patterns( [can_view_map, cache_control(must_revalidate=True)], re_path( - r"^datalayer/(?P\d+)/(?P[\d]+)/$", + r"^datalayer/(?P\d+)/(?P" + uuid + ")/$", views.DataLayerView.as_view(), name="datalayer_view", ), re_path( - r"^datalayer/(?P\d+)/(?P[\d]+)/versions/$", + r"^datalayer/(?P\d+)/(?P" + uuid + r")/versions/$", views.DataLayerVersions.as_view(), name="datalayer_versions", ), re_path( - r"^datalayer/(?P\d+)/(?P[\d]+)/(?P[_\w]+.geojson)$", + r"^datalayer/(?P\d+)/(?P" + uuid + r" )/(?P[_\w]+.geojson)$", views.DataLayerVersion.as_view(), name="datalayer_version", ), @@ -146,12 +148,12 @@ map_urls = [ name="datalayer_create", ), re_path( - r"^map/(?P[\d]+)/datalayer/delete/(?P\d+)/$", + r"^map/(?P[\d]+)/datalayer/delete/(?P" + uuid + r")/$", views.DataLayerDelete.as_view(), name="datalayer_delete", ), re_path( - r"^map/(?P[\d]+)/datalayer/permissions/(?P\d+)/$", + r"^map/(?P[\d]+)/datalayer/permissions/(?P" + uuid + r"\d+)/$", views.UpdateDataLayerPermissions.as_view(), name="datalayer_permissions", ), @@ -166,7 +168,7 @@ if settings.DEFAULT_FROM_EMAIL: ) datalayer_urls = [ re_path( - r"^map/(?P[\d]+)/datalayer/update/(?P\d+)/$", + r"^map/(?P[\d]+)/datalayer/update/(?P" + uuid + r")/$", views.DataLayerUpdate.as_view(), name="datalayer_update", ),