Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update map.modified_at when saving a datalayer #2423

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading