From 8d069df9d16876666f226a4f778c691aaa80e8f5 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 31 May 2026 23:24:22 -0400 Subject: [PATCH] [scrobbles] Fix log saving tests --- tests/scrobbles_tests/test_views.py | 3 ++- vrobbler/apps/scrobbles/forms.py | 31 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/scrobbles_tests/test_views.py b/tests/scrobbles_tests/test_views.py index cd1d772..c8f1e6e 100644 --- a/tests/scrobbles_tests/test_views.py +++ b/tests/scrobbles_tests/test_views.py @@ -607,7 +607,8 @@ def test_scrobble_detail_view_post_updates_log(client): scrobble.refresh_from_db() assert scrobble.log["description"] == "Updated description" - assert scrobble.log["notes"] == ["Updated note"] + assert isinstance(scrobble.log["notes"], dict) + assert list(scrobble.log["notes"].values()) == ["Updated note"] @pytest.mark.skip("Need to refactor") diff --git a/vrobbler/apps/scrobbles/forms.py b/vrobbler/apps/scrobbles/forms.py index 2d14df4..e9ffc4e 100644 --- a/vrobbler/apps/scrobbles/forms.py +++ b/vrobbler/apps/scrobbles/forms.py @@ -112,11 +112,14 @@ class NotesDictWidget(forms.Widget): def value_from_datadict(self, data, files, name): timestamps = data.getlist(f"{name}_timestamps") - contents = data.getlist(f"{name}_contents") - return { - "timestamps": timestamps, - "contents": contents, - } + if timestamps: + contents = data.getlist(f"{name}_contents") + result = {} + for i, ts in enumerate(timestamps): + if i < len(contents) and ts: + result[ts] = contents[i] + return result if result else "" + return data.get(name, "") def get_context(self, name, value, attrs): context = super().get_context(name, value, attrs) @@ -139,10 +142,14 @@ class NotesDictField(forms.Field): def clean(self, value): if not value: return {} - result = {} - timestamps = value.get("timestamps", []) - contents = value.get("contents", []) - for i, ts in enumerate(timestamps): - if i < len(contents) and ts and contents[i].strip(): - result[ts] = contents[i].strip() - return result if result else {} + + if isinstance(value, str): + if value.strip(): + from datetime import datetime + return {datetime.now().isoformat(): value.strip()} + return {} + + if isinstance(value, dict): + return value + + return {}