feat: wire identify URL routes and stub views
This commit is contained in:
parent
a2da8e6457
commit
ae919a3fce
6 changed files with 84 additions and 1 deletions
5
plants/templates/plants/identify_confirm.html
Normal file
5
plants/templates/plants/identify_confirm.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "plants/base.html" %}
|
||||
{% block title %}Confirm species — PlantDB{% endblock %}
|
||||
{% block content %}
|
||||
<p>Confirm step (coming soon)</p>
|
||||
{% endblock %}
|
||||
5
plants/templates/plants/identify_fields.html
Normal file
5
plants/templates/plants/identify_fields.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "plants/base.html" %}
|
||||
{% block title %}Review fields — PlantDB{% endblock %}
|
||||
{% block content %}
|
||||
<p>Fields step (coming soon)</p>
|
||||
{% endblock %}
|
||||
5
plants/templates/plants/identify_upload.html
Normal file
5
plants/templates/plants/identify_upload.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "plants/base.html" %}
|
||||
{% block title %}Identify plant — PlantDB{% endblock %}
|
||||
{% block content %}
|
||||
<p>Upload step (coming soon)</p>
|
||||
{% endblock %}
|
||||
25
plants/tests/test_identify_views.py
Normal file
25
plants/tests/test_identify_views.py
Normal file
|
|
@ -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']
|
||||
|
|
@ -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/<int:pk>/', plants.plant_detail, name='plant_detail'),
|
||||
path('plants/<int:pk>/edit/', plants.plant_edit, name='plant_edit'),
|
||||
path('plants/<int:pk>/delete/', plants.plant_delete, name='plant_delete'),
|
||||
|
|
|
|||
40
plants/views/identify.py
Normal file
40
plants/views/identify.py
Normal file
|
|
@ -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),
|
||||
})
|
||||
Loading…
Add table
Reference in a new issue