recipe links

This commit is contained in:
Joren de Graaf
2026-10-23 14:30:58 +02:00
parent 5b986134be
commit 4d76a2bc9c
52 changed files with 2698 additions and 19 deletions
@@ -1 +1,2 @@
.grocery-page{max-width:1050px;margin:0 auto;padding:clamp(1rem,3vw,2.5rem);color:var(--text,#21372c)}.grocery-page h1{font-size:clamp(2rem,4vw,3rem);margin:.2rem 0}.grocery-kicker{text-transform:uppercase;letter-spacing:.12em;font-weight:700}.grocery-panel{background:var(--surface,#fff);border:1px solid #d3ddd5;border-radius:1rem;padding:clamp(1rem,2vw,1.5rem);margin:1.25rem 0;box-shadow:0 6px 24px #172a2010}.grocery-panel h2{margin:0 0 1rem}.grocery-add,.grocery-filter,.grocery-edit{display:flex;flex-wrap:wrap;align-items:end;gap:.75rem}.grocery-add label,.grocery-filter label,.grocery-edit label{display:grid;gap:.3rem;min-width:120px;flex:1}.grocery-add label:first-child{flex:2;min-width:200px}.grocery-page input,.grocery-page select,.grocery-page textarea{box-sizing:border-box;width:100%;padding:.65rem;border:1px solid #a7b7a9;border-radius:.5rem;background:var(--surface,#fff);color:inherit;font:inherit}.grocery-page button{padding:.65rem 1rem;border:0;border-radius:.5rem;background:#315d4d;color:white;font:inherit;cursor:pointer}.grocery-page button:focus-visible,.grocery-page a:focus-visible,.grocery-page input:focus-visible,.grocery-page select:focus-visible,.grocery-page summary:focus-visible{outline:3px solid #bd7319;outline-offset:2px}.grocery-panel-head{display:flex;justify-content:space-between;align-items:center;gap:1rem}.grocery-page .grocery-text-button{background:transparent;color:#315d4d;text-decoration:underline;padding:.4rem}.grocery-group h3{border-bottom:1px solid #d3ddd5;padding-bottom:.4rem}.grocery-group ul,.grocery-preview-list{list-style:none;padding:0}.grocery-item{display:flex;align-items:start;gap:.8rem;border-bottom:1px solid #e2e8e2;padding:.8rem 0}.grocery-item-body{flex:1;min-width:0}.grocery-item-body strong,.grocery-item-body span,.grocery-item-body small{display:block}.grocery-item-body small{color:#52655b}.grocery-item-body details{margin-top:.4rem}.grocery-check{min-width:2.7rem}.grocery-uncertain{display:block;color:#8a4400;font-weight:600}.grocery-confirm{display:flex;gap:.5rem;align-items:center;margin:1rem 0}.grocery-confirm input{width:auto}.grocery-preview-list li{padding:.8rem 0;border-bottom:1px solid #d3ddd5}@media(max-width:600px){.grocery-page{padding:1rem}.grocery-add,.grocery-filter,.grocery-edit{display:grid;grid-template-columns:1fr 1fr}.grocery-add label:first-child,.grocery-add button,.grocery-edit label:first-child,.grocery-edit button{grid-column:1/-1}.grocery-item{gap:.4rem}.grocery-page .grocery-text-button{font-size:.9rem}}
.grocery-page-header{display:flex;align-items:center;justify-content:space-between;gap:1.25rem}.grocery-sync-action{display:grid;justify-items:start;gap:.35rem;flex:none}.grocery-sync-button{display:inline-flex;align-items:center;justify-content:center;min-height:44px;padding:.65rem 1rem;border-radius:.5rem;background:#315d4d;color:#fff;text-decoration:none;font-weight:700}.grocery-sync-action small{color:#52655b}@media(max-width:600px){.grocery-page-header{align-items:flex-start;flex-direction:column}.grocery-sync-action{width:100%}.grocery-sync-button{width:100%;box-sizing:border-box}}
@@ -2,7 +2,7 @@
{% block title %}Groceries · Tasknest{% endblock %}
{% block content %}
<link rel="stylesheet" href="{% static 'groceries/groceries.css' %}?v=2">
<div class="grocery-page"><header><p class="grocery-kicker">Food</p><h1>Grocery list</h1><p>Plan what to buy. Marking an item purchased does not add it to Kitchen Inventory.</p></header>
<div class="grocery-page"><header class="grocery-page-header"><div><p class="grocery-kicker">Food</p><h1>Grocery list</h1><p>Plan what to buy. Marking an item purchased does not add it to Kitchen Inventory.</p></div>{% if ha_grocery_sync_available %}<div class="grocery-sync-action"><a class="grocery-sync-button" href="{% url 'home_assistant:preview' %}">Sync with Home Assistant</a><small>Review changes before confirming.</small></div>{% endif %}</header>
<section class="grocery-panel" aria-labelledby="quick-add"><h2 id="quick-add">Quick add</h2><form class="grocery-add" method="post" action="{% url 'groceries:add' %}">{% csrf_token %}<label>Name<input name="name" maxlength="180" required autocomplete="off"></label><label>Quantity<input name="quantity" type="number" min="0.001" step="0.001" value="1" required></label><label>Unit<select name="unit"><option value="pieces">pieces</option><option value="g">g</option><option value="kg">kg</option><option value="ml">ml</option><option value="L">L</option><option value="packs">packs</option><option value="portions">portions</option><option value="tsp">tsp</option><option value="tbsp">tbsp</option></select></label><label>Category<input name="category" maxlength="80"></label><button type="submit">Add item</button></form></section>
<section class="grocery-panel" aria-labelledby="grocery-items"><div class="grocery-panel-head"><h2 id="grocery-items">Items</h2><form method="post" action="{% url 'groceries:clear-purchased' %}">{% csrf_token %}<button type="submit" class="grocery-text-button">Clear purchased</button></form></div><form method="get" class="grocery-filter" hx-get="{% url 'groceries:index' %}" hx-target="#grocery-list" hx-push-url="true"><label>Search<input type="search" name="q" value="{{ query }}"></label><label>Status<select name="status"><option value="needed"{% if selected_status == 'needed' %} selected{% endif %}>Needed</option><option value="purchased"{% if selected_status == 'purchased' %} selected{% endif %}>Purchased</option><option value="all"{% if selected_status == 'all' %} selected{% endif %}>All</option></select></label><button type="submit">Filter</button></form><div id="grocery-list" aria-live="polite">{% include 'groceries/partials/list.html' %}</div></section></div>
{% endblock %}
+14
View File
@@ -8,6 +8,7 @@ from django.conf import settings
from food.models import FoodProduct
from food.api import create_token
from home_assistant.models import HomeAssistantConnection
from recipes.models import Recipe, RecipeIngredient
from .models import GroceryItem
from .services import GroceryError, add, add_purchased_to_inventory, apply_recipe, edit, recipe_preview, search
@@ -71,6 +72,19 @@ class GroceryTests(TestCase):
RecipeIngredient.objects.create(recipe=recipe, name='Water', quantity=200, unit='ml')
self.assertContains(self.client.get(f'/groceries/recipe/{recipe.api_id}/preview/'), 'Review groceries')
@override_settings(MIDDLEWARE=[item for item in settings.MIDDLEWARE if not item.startswith('whitenoise.')],
SECURE_SSL_REDIRECT=False)
def test_grocery_page_shows_home_assistant_sync_action_when_list_is_configured(self):
self.client.force_login(self.user)
response = self.client.get('/groceries/')
self.assertNotContains(response, 'Sync with Home Assistant')
HomeAssistantConnection.objects.create(user=self.user, base_url='https://ha.example',
encrypted_token='encrypted', grocery_entity_id='todo.shopping')
response = self.client.get('/groceries/')
self.assertContains(response, 'Sync with Home Assistant')
self.assertContains(response, 'Review changes before confirming.')
self.assertContains(response, 'href="/settings/home-assistant/preview/"')
def test_inventory_transfer_requires_purchase_and_is_single_use(self):
item = add(self.user, name='Rice', quantity='500', unit='g')
product = FoodProduct.objects.create(owner=self.user, product_name='Rice')
+5 -1
View File
@@ -5,6 +5,8 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.views.decorators.http import require_POST
from recipes.models import Recipe
from home_assistant.models import HomeAssistantConnection
from planner.demo_policy import is_demo_user
from .models import GroceryItem
from food.models import FoodProduct
from .services import (GroceryError, add, add_purchased_to_inventory, apply_recipe,
@@ -17,7 +19,9 @@ def _page(request, status=200):
items = list(search(request.user, query=request.GET.get('q', ''), status=selected).order_by('category', 'status', 'name'))
except GroceryError:
selected, items = 'needed', list(search(request.user))
context = {'items': items, 'selected_status': selected, 'query': request.GET.get('q', '')}
connection = None if is_demo_user(request.user) else HomeAssistantConnection.objects.filter(user=request.user).first()
context = {'items': items, 'selected_status': selected, 'query': request.GET.get('q', ''),
'ha_grocery_sync_available': bool(connection and connection.grocery_entity_id)}
template = 'groceries/partials/list.html' if request.headers.get('HX-Request') == 'true' else 'groceries/index.html'
return render(request, template, context, status=status)