Skip to content

Commit

Permalink
fix: update map.modified_at when saving a datalayer (#2423)
Browse files Browse the repository at this point in the history
fix #2421
  • Loading branch information
yohanboniface authored Jan 10, 2025
2 parents a7325dc + 92b7be3 commit 7072b54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion umap/tests/test_datalayer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import tempfile
from pathlib import Path

import pytest
Expand Down
16 changes: 16 additions & 0 deletions umap/tests/test_datalayer_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from copy import deepcopy
from datetime import datetime, timedelta
from pathlib import Path
from unittest import mock
from uuid import uuid4

import pytest
Expand Down Expand Up @@ -621,3 +623,17 @@ def test_optimistic_merge_conflicting_change_raises(
modified_datalayer = DataLayer.objects.get(pk=datalayer.pk)
merged_features = json.load(modified_datalayer.geojson)["features"]
assert merged_features == client1_data["features"]


def test_saving_datalayer_should_change_map_last_modified(
client, datalayer, map, post_data
):
with mock.patch("django.utils.timezone.now") as mocked:
mocked.return_value = datetime.utcnow() - timedelta(days=8)
map.save() # Change last_modified to past
old_modified_at = map.modified_at.date()
url = reverse("datalayer_update", args=(map.pk, datalayer.pk))
client.login(username=map.owner.username, password="123123")
response = client.post(url, post_data, follow=True)
assert response.status_code == 200
assert Map.objects.get(pk=map.pk).modified_at.date() != old_modified_at
1 change: 1 addition & 0 deletions umap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,7 @@ def post(self, request, *args, **kwargs):

def form_valid(self, form):
self.object = form.save()
self.object.map.save(update_fields=["modified_at"])
data = {**self.object.metadata(self.request)}
if self.request.session.get("needs_reload"):
data["geojson"] = json.loads(self.object.geojson.read().decode())
Expand Down

0 comments on commit 7072b54

Please sign in to comment.