From e85d6ec77963e4b3ab82795f10da2e09ec537723 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 15 May 2026 12:20:27 -0400 Subject: [PATCH] [birds] Fix importer not finishing, and add formjs --- tests/birds_tests/test_importer.py | 9 +++++++++ vrobbler/apps/birds/importer.py | 8 ++++++-- vrobbler/templates/scrobbles/scrobble_detail.html | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/birds_tests/test_importer.py b/tests/birds_tests/test_importer.py index 54c317d..ff66cd4 100644 --- a/tests/birds_tests/test_importer.py +++ b/tests/birds_tests/test_importer.py @@ -1,3 +1,5 @@ +from datetime import timedelta + import pytest from birds.importer import ( import_birding_csv, @@ -111,6 +113,13 @@ class TestImportBirdingCSV: goose = next(b for b in birds if b["quantity"] == 6) assert goose is not None + def test_import_sets_stop_timestamp(self, user, birding_csv_file): + import_birding_csv(birding_csv_file, user.id) + scrobble = Scrobble.objects.filter(source="Birding CSV Import").first() + assert scrobble.stop_timestamp is not None + expected = scrobble.timestamp + timedelta(minutes=9) + assert scrobble.stop_timestamp == expected + class TestBirdingCSVImportModel: def test_create_import_model(self, db, user): diff --git a/vrobbler/apps/birds/importer.py b/vrobbler/apps/birds/importer.py index 38451e1..38f4b48 100644 --- a/vrobbler/apps/birds/importer.py +++ b/vrobbler/apps/birds/importer.py @@ -2,7 +2,7 @@ import csv import logging import re from collections import defaultdict -from datetime import datetime +from datetime import datetime, timedelta from zoneinfo import ZoneInfo from django.contrib.auth import get_user_model @@ -122,9 +122,10 @@ def import_birding_csv(file_path, user_id): ) birds_data.append(entry.asdict) + duration_minutes = parse_duration(first_row.get("Duration", "")) logdata = BirdSightingLogData( birds=birds_data, - duration_minutes=parse_duration(first_row.get("Duration", "")), + duration_minutes=duration_minutes, observation_type=first_row.get("Observation Type", "").strip() or None, distance=first_row.get("Distance", "").strip() or None, area=first_row.get("Area", "").strip() or None, @@ -134,9 +135,12 @@ def import_birding_csv(file_path, user_id): log_dict = logdata.asdict + stop_timestamp = timestamp + timedelta(minutes=duration_minutes) if duration_minutes else None + scrobble = Scrobble( user=user, timestamp=timestamp, + stop_timestamp=stop_timestamp, source="Birding CSV Import", birding_location=location, log=log_dict, diff --git a/vrobbler/templates/scrobbles/scrobble_detail.html b/vrobbler/templates/scrobbles/scrobble_detail.html index d73d10c..15b481f 100644 --- a/vrobbler/templates/scrobbles/scrobble_detail.html +++ b/vrobbler/templates/scrobbles/scrobble_detail.html @@ -136,3 +136,5 @@ {% endblock %} + +{% block extra_js %}{{ block.super }}{{ log_form.media }}{% endblock %}