chore: Use datalayers' UUIDs in the views

This commit is contained in:
Alexis Métaireau 2024-02-22 11:10:52 +01:00
parent 6b7efda37a
commit c46f59e3dd
2 changed files with 10 additions and 7 deletions

View file

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

View file

@ -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<map_id>\d+)/(?P<pk>[\d]+)/$",
r"^datalayer/(?P<map_id>\d+)/(?P<pk>" + uuid + ")/$",
views.DataLayerView.as_view(),
name="datalayer_view",
),
re_path(
r"^datalayer/(?P<map_id>\d+)/(?P<pk>[\d]+)/versions/$",
r"^datalayer/(?P<map_id>\d+)/(?P<pk>" + uuid + r")/versions/$",
views.DataLayerVersions.as_view(),
name="datalayer_versions",
),
re_path(
r"^datalayer/(?P<map_id>\d+)/(?P<pk>[\d]+)/(?P<name>[_\w]+.geojson)$",
r"^datalayer/(?P<map_id>\d+)/(?P<pk>" + uuid + r" )/(?P<name>[_\w]+.geojson)$",
views.DataLayerVersion.as_view(),
name="datalayer_version",
),
@ -146,12 +148,12 @@ map_urls = [
name="datalayer_create",
),
re_path(
r"^map/(?P<map_id>[\d]+)/datalayer/delete/(?P<pk>\d+)/$",
r"^map/(?P<map_id>[\d]+)/datalayer/delete/(?P<pk>" + uuid + r")/$",
views.DataLayerDelete.as_view(),
name="datalayer_delete",
),
re_path(
r"^map/(?P<map_id>[\d]+)/datalayer/permissions/(?P<pk>\d+)/$",
r"^map/(?P<map_id>[\d]+)/datalayer/permissions/(?P<pk>" + 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<map_id>[\d]+)/datalayer/update/(?P<pk>\d+)/$",
r"^map/(?P<map_id>[\d]+)/datalayer/update/(?P<pk>" + uuid + r")/$",
views.DataLayerUpdate.as_view(),
name="datalayer_update",
),