From ae919a3fcec1e27e9ed4b9715e848a6ee195b13e Mon Sep 17 00:00:00 2001 From: Stephan Kerkman Date: Sat, 30 May 2026 17:37:46 +0200 Subject: [PATCH] feat: wire identify URL routes and stub views --- plants/templates/plants/identify_confirm.html | 5 +++ plants/templates/plants/identify_fields.html | 5 +++ plants/templates/plants/identify_upload.html | 5 +++ plants/tests/test_identify_views.py | 25 ++++++++++++ plants/urls.py | 5 ++- plants/views/identify.py | 40 +++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 plants/templates/plants/identify_confirm.html create mode 100644 plants/templates/plants/identify_fields.html create mode 100644 plants/templates/plants/identify_upload.html create mode 100644 plants/tests/test_identify_views.py create mode 100644 plants/views/identify.py diff --git a/plants/templates/plants/identify_confirm.html b/plants/templates/plants/identify_confirm.html new file mode 100644 index 0000000..3fc8a26 --- /dev/null +++ b/plants/templates/plants/identify_confirm.html @@ -0,0 +1,5 @@ +{% extends "plants/base.html" %} +{% block title %}Confirm species — PlantDB{% endblock %} +{% block content %} +

Confirm step (coming soon)

+{% endblock %} diff --git a/plants/templates/plants/identify_fields.html b/plants/templates/plants/identify_fields.html new file mode 100644 index 0000000..8b083e8 --- /dev/null +++ b/plants/templates/plants/identify_fields.html @@ -0,0 +1,5 @@ +{% extends "plants/base.html" %} +{% block title %}Review fields — PlantDB{% endblock %} +{% block content %} +

Fields step (coming soon)

+{% endblock %} diff --git a/plants/templates/plants/identify_upload.html b/plants/templates/plants/identify_upload.html new file mode 100644 index 0000000..b6abd76 --- /dev/null +++ b/plants/templates/plants/identify_upload.html @@ -0,0 +1,5 @@ +{% extends "plants/base.html" %} +{% block title %}Identify plant — PlantDB{% endblock %} +{% block content %} +

Upload step (coming soon)

+{% endblock %} diff --git a/plants/tests/test_identify_views.py b/plants/tests/test_identify_views.py new file mode 100644 index 0000000..b46d556 --- /dev/null +++ b/plants/tests/test_identify_views.py @@ -0,0 +1,25 @@ +import pytest +from django.test import Client +from django.urls import reverse + + +@pytest.fixture +def client(): + return Client() + + +def test_upload_get(client): + resp = client.get(reverse('identify_upload')) + assert resp.status_code == 200 + + +def test_confirm_redirects_without_session(client): + resp = client.get(reverse('identify_confirm')) + assert resp.status_code == 302 + assert reverse('identify_upload') in resp['Location'] + + +def test_fields_redirects_without_session(client): + resp = client.get(reverse('identify_fields')) + assert resp.status_code == 302 + assert reverse('identify_upload') in resp['Location'] diff --git a/plants/urls.py b/plants/urls.py index 2dfdcc1..b01fb1e 100644 --- a/plants/urls.py +++ b/plants/urls.py @@ -1,11 +1,14 @@ from django.urls import path -from plants.views import dashboard, plants, pruning, species +from plants.views import dashboard, plants, pruning, species, identify urlpatterns = [ path('', dashboard.dashboard, name='dashboard'), path('plants/', plants.plant_list, name='plant_list'), path('plants/add/', plants.plant_add, name='plant_add'), path('plants/scan/', plants.add_plant_from_scan, name='add_plant_from_scan'), + path('identify/', identify.identify_upload, name='identify_upload'), + path('identify/confirm/', identify.identify_confirm, name='identify_confirm'), + path('identify/fields/', identify.identify_fields, name='identify_fields'), path('plants//', plants.plant_detail, name='plant_detail'), path('plants//edit/', plants.plant_edit, name='plant_edit'), path('plants//delete/', plants.plant_delete, name='plant_delete'), diff --git a/plants/views/identify.py b/plants/views/identify.py new file mode 100644 index 0000000..c48baf8 --- /dev/null +++ b/plants/views/identify.py @@ -0,0 +1,40 @@ +from django.shortcuts import render, redirect + +_SESSION_KEYS = [ + 'identify_matches', 'identify_image_paths', 'identify_selected', + 'identify_vpc_results', 'identify_vpc_idx', +] + + +def _clear_session(request): + for key in _SESSION_KEYS: + request.session.pop(key, None) + + +def identify_upload(request): + if request.method == 'POST': + return redirect('identify_confirm') + return render(request, 'plants/identify_upload.html') + + +def identify_confirm(request): + if 'identify_matches' not in request.session: + return redirect('identify_upload') + if request.method == 'POST': + return redirect('identify_fields') + return render(request, 'plants/identify_confirm.html', { + 'matches': request.session.get('identify_matches', []), + }) + + +def identify_fields(request): + if 'identify_selected' not in request.session: + return redirect('identify_upload') + if request.method == 'POST': + _clear_session(request) + return redirect('plant_list') + return render(request, 'plants/identify_fields.html', { + 'selected': request.session.get('identify_selected', {}), + 'vpc_results': request.session.get('identify_vpc_results', []), + 'vpc_idx': request.session.get('identify_vpc_idx', 0), + })