latest changes

This commit is contained in:
Joren de Graaf
2026-10-22 10:32:41 +02:00
parent 5799b542c8
commit 5b986134be
63 changed files with 2412 additions and 77 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Edit food log · Tasknest{% endblock %}
{% block content %}
<link rel="stylesheet" href="{% static 'food/food.css' %}">
<link rel="stylesheet" href="{% static 'food/food.css' %}?v=20261021-nutrition">
{% include 'food/partials/edit_content.html' %}
{% endblock %}
+1 -1
View File
@@ -3,7 +3,7 @@
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}?v=20261012-actions">
<div class="food-form-page inventory-page"><a href="{% url 'food:inventory' %}">← Kitchen Inventory</a><h1>Add to inventory</h1>
{% if product %}
<section class="food-card inventory-product">{% if product.image_url %}<img src="{{ product.image_url }}" alt="" loading="lazy">{% endif %}<div><h2>{{ product.product_name }}</h2>{% if product.brand %}<p>{{ product.brand }}</p>{% endif %}{% if product.package_quantity %}<p>{{ product.package_quantity }}</p>{% endif %}{% if off_categories %}<p><small>Open Food Facts: {{ off_categories }}</small></p>{% endif %}</div></section>
<section class="food-card inventory-product">{% if product.image_url %}<img src="{{ product.image_url }}" alt="" loading="lazy">{% endif %}<div><h2>{{ product.product_name }}</h2>{% if product.brand %}<p>{{ product.brand }}</p>{% endif %}{% if product.package_quantity %}<p>{{ product.package_quantity }}</p>{% endif %}{% if off_categories %}<p><small>Open Food Facts: {{ off_categories }}</small></p>{% endif %}<p><a href="{% url 'food:product-edit' product.pk %}">View or edit product nutrition</a></p></div></section>
{% if existing %}<section class="food-card"><h2>Already in inventory</h2>{% for item in existing %}<div class="inventory-existing"><span>{{ item.location.name }} · Quantity {{ item.quantity }}{% if item.best_before %} · Best before {{ item.best_before }}{% endif %}</span><form method="post" action="{% url 'food:inventory-add-one' item.pk %}">{% csrf_token %}<button class="button button--secondary" type="submit">+1 existing item</button></form></div>{% endfor %}<p>Use the form below to add this product separately.</p></section>{% endif %}
<form class="food-card inventory-form" method="post">{% csrf_token %}<input type="hidden" name="product" value="{{ product.pk }}">{{ form.non_field_errors }}
{% for field in form %}<div class="form-field">{{ field.label_tag }}{% if field.name == 'quantity' %}<div class="inventory-quantity" data-inventory-quantity><button type="button" data-inventory-step="-1" aria-label="Decrease quantity">−</button>{{ field }}<button type="button" data-inventory-step="1" aria-label="Increase quantity">+</button></div>{% else %}{{ field }}{% endif %}{{ field.errors }}</div>{% endfor %}
+1 -1
View File
@@ -1,3 +1,3 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Edit inventory item · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}"><div class="food-form-page inventory-page"><a href="{% url 'food:inventory' %}">← Kitchen Inventory</a><h1>Edit {{ item.product.product_name }}</h1><form method="post" class="food-card inventory-form">{% csrf_token %}{{ form.non_field_errors }}{% for field in form %}<div class="form-field">{{ field.label_tag }}{% if field.name == 'quantity' %}<div class="inventory-quantity" data-inventory-quantity><button type="button" data-inventory-step="-1" aria-label="Decrease quantity">−</button>{{ field }}<button type="button" data-inventory-step="1" aria-label="Increase quantity">+</button></div>{% else %}{{ field }}{% endif %}{{ field.errors }}</div>{% endfor %}<datalist id="inventory-locations">{% for location in locations %}<option value="{{ location.name }}">{% endfor %}</datalist><datalist id="inventory-categories">{% for category in categories %}<option value="{{ category.name }}">{% endfor %}</datalist><button class="button" type="submit">Save changes</button></form></div><script src="{% static 'food/inventory.js' %}" defer></script>{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}"><div class="food-form-page inventory-page"><a href="{% url 'food:inventory' %}">← Kitchen Inventory</a><h1>Edit {{ item.product.product_name }}</h1><p>This form changes stock for this package. <a href="{% url 'food:product-edit' item.product.pk %}">View or edit product nutrition</a> for future food logs.</p><form method="post" class="food-card inventory-form">{% csrf_token %}{{ form.non_field_errors }}{% for field in form %}<div class="form-field">{{ field.label_tag }}{% if field.name == 'quantity' %}<div class="inventory-quantity" data-inventory-quantity><button type="button" data-inventory-step="-1" aria-label="Decrease quantity">−</button>{{ field }}<button type="button" data-inventory-step="1" aria-label="Increase quantity">+</button></div>{% else %}{{ field }}{% endif %}{{ field.errors }}</div>{% endfor %}<datalist id="inventory-locations">{% for location in locations %}<option value="{{ location.name }}">{% endfor %}</datalist><datalist id="inventory-categories">{% for category in categories %}<option value="{{ category.name }}">{% endfor %}</datalist><button class="button" type="submit">Save changes</button></form></div><script src="{% static 'food/inventory.js' %}" defer></script>{% endblock %}
@@ -1,3 +1,5 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Create inventory product · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}"><div class="food-form-page"><a href="{% url 'food:inventory-add' %}">← Add item</a><h1>Create product</h1><p>Save a product to the shared food catalogue. Nutrition can be added later.</p><form method="post" class="food-card inventory-form">{% csrf_token %}{% for field in form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Continue to inventory</button></form></div>{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}?v=20261021-nutrition"><div class="food-form-page"><a href="{% url 'food:inventory-add' %}">← Add item</a><h1>Create product</h1><p>Save a product for both Kitchen Inventory and Food Diary. Package size describes stock; nutrition is entered separately for the chosen basis.</p><form method="post" class="food-card product-form">{% csrf_token %}{{ form.non_field_errors }}
{% for field in form %}{% if field.name == 'product_name' or field.name == 'brand' or field.name == 'barcode' or field.name == 'package_quantity' %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endif %}{% endfor %}
{% include 'food/partials/product_nutrition_fields.html' %}<button class="button" type="submit">Continue to inventory</button></form></div>{% endblock %}
@@ -8,6 +8,7 @@
</form>
{% for card in cards %}<article class="food-card inventory-product-card">
<div class="inventory-product-heading">{% if card.product.image_url %}<img src="{{ card.product.image_url }}" alt="" loading="lazy">{% endif %}<div><h2>{{ card.product.product_name }}</h2>{% if card.product.brand %}<p>{{ card.product.brand }}</p>{% endif %}<p><strong>{{ card.total|floatformat:-3 }} {% if card.unit == "packs" and card.total == 1 %}pack{% else %}{{ card.unit }}{% endif %} remaining</strong> · {{ card.packages|length }} package{{ card.packages|length|pluralize }}</p></div></div>
<p><a href="{% url 'food:product-edit' card.product.pk %}">View or edit product nutrition</a></p>
<details class="inventory-packages"><summary>View packages</summary><div class="inventory-package-list">{% for item in card.packages %}<div class="inventory-package"><div class="inventory-package-fill" role="img" aria-label="{{ item.percentage_remaining }}% remaining"><span style="height:{{ item.percentage_remaining }}%"></span></div><div><strong>Pack {{ forloop.counter }} · {{ item.package_status|title }}</strong><p>{% if item.original_amount %}{{ item.remaining_amount|floatformat:-3 }} / {{ item.original_amount|floatformat:-3 }} {{ item.inventory_unit }} · {{ item.percentage_remaining }}% remaining{% else %}{{ item.quantity }} pack{{ item.quantity|pluralize }} · size unknown{% endif %}</p><small>{{ item.location.name }}{% if item.category %} · {{ item.category.name }}{% endif %}{% if item.best_before %} · Best before {{ item.best_before }}{% endif %}</small><div><a href="{% url 'food:inventory-edit' item.pk %}">Edit package</a></div></div></div>{% endfor %}</div></details>
<details class="inventory-use"><summary>Use amount</summary><form method="post" action="{% url 'food:inventory-preview' card.product.pk %}" hx-post="{% url 'food:inventory-preview' card.product.pk %}" hx-target="#inventory-preview-{{ card.product.pk }}-{{ card.unit }}" hx-swap="innerHTML" class="inventory-use-form">{% csrf_token %}<label>Amount<input type="number" name="amount" min="{% if card.count_unit %}1{% else %}0.001{% endif %}" step="{% if card.count_unit %}1{% else %}0.001{% endif %}" required inputmode="decimal"></label><label>Unit<select name="unit">{% for unit in card.units %}<option value="{{ unit }}" {% if unit == card.unit %}selected{% endif %}>{{ unit }}</option>{% endfor %}</select></label><label>Package (optional)<select name="package_id"><option value="">Automatic selection</option>{% for item in card.packages %}<option value="{{ item.api_id }}">Pack {{ forloop.counter }} · {% if item.remaining_amount is not None %}{{ item.remaining_amount|floatformat:-3 }} {{ item.inventory_unit }}{% else %}{{ item.quantity }} pack{{ item.quantity|pluralize }}{% endif %}</option>{% endfor %}</select></label><button class="button button--secondary" type="submit">Preview</button></form><div id="inventory-preview-{{ card.product.pk }}-{{ card.unit }}" aria-live="polite"></div></details>
</article>{% empty %}<section class="food-card"><p>No inventory items found.</p><a class="button" href="{% url 'food:inventory-add' %}">Add your first item</a></section>{% endfor %}
+3 -1
View File
@@ -1,3 +1,5 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Create food · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}"><div class="food-form-page"><a href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">← Back to foods</a><h1>Create a food</h1><p>Enter nutrition for the base quantity and unit you choose. Missing optional values stay unknown.</p><form method="post" class="food-card">{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="meal" value="{{ meal }}">{% for field in form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save food</button></form></div>{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}?v=20261021-nutrition"><div class="food-form-page"><a href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">← Back to foods</a><h1>Create a food</h1><p>Save nutrition once, then choose how much to log. You can correct this product later; existing diary entries keep their recorded values.</p><form method="post" class="food-card product-form">{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="meal" value="{{ meal }}">{{ form.non_field_errors }}
{% for field in form %}{% if field.name == 'product_name' or field.name == 'brand' or field.name == 'barcode' %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endif %}{% endfor %}
{% include 'food/partials/product_nutrition_fields.html' %}<button class="button" type="submit">Save food</button></form></div>{% endblock %}
@@ -12,11 +12,13 @@
<dt>Carbohydrates</dt><dd>{{ product.carbohydrates_100|default_if_none:'—' }} g</dd>
<dt>Protein</dt><dd>{{ product.protein_100|default_if_none:'—' }} g</dd>
<dt>Fat</dt><dd>{{ product.fat_100|default_if_none:'—' }} g</dd>
<dt>Saturated fat</dt><dd>{{ product.saturated_fat_100|default_if_none:'—' }} g</dd>
<dt>Sugars</dt><dd>{{ product.sugars_100|default_if_none:'—' }} g</dd>
<dt>Fibre</dt><dd>{{ product.fibre_100|default_if_none:'—' }} g</dd>
<dt>Salt</dt><dd>{{ product.salt_100|default_if_none:'—' }} g</dd>
</dl></details>
{% if product.source == 'openfoodfacts' %}<p class="food-attribution">Product data from <a href="https://world.openfoodfacts.org/product/{{ product.barcode }}" rel="noopener noreferrer">Open Food Facts</a>.</p>{% endif %}
<p><a href="{% url 'food:product-edit' product.pk %}">Edit product nutrition</a></p>
</section>
<form method="post" class="food-card" hx-post="{% url 'food:add' %}" hx-target="#food-workspace" hx-swap="outerHTML">
{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="product" value="{{ product.pk }}"><input type="hidden" name="submission_id" value="{{ submission_id }}">
@@ -50,11 +52,11 @@
<div id="food-recents-list"><h2>Recent</h2>{% include 'food/partials/product_list.html' with products=recents %}</div>
{% else %}{% include 'food/partials/product_list.html' with products=products %}{% endif %}
<div class="food-actions"><a class="button" href="{% url 'food:manual' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">Create a food manually</a>
<a class="button" href="{% url 'food:scanner' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">Scan barcode</a>
<a class="button button--secondary" href="{% url 'food:external-search' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}&amp;q={{ query|urlencode }}">Search Open Food Facts</a></div>
<form method="post" action="{% url 'food:import-product' %}" class="food-barcode-form">{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="meal" value="{{ meal }}"><label for="food-barcode">Barcode</label><input id="food-barcode" name="barcode" inputmode="numeric" pattern="[0-9]+" required><button class="button button--secondary" type="submit">Look up barcode</button></form>
<p class="food-attribution">External product data from <a href="https://world.openfoodfacts.org/" rel="noopener noreferrer">Open Food Facts</a>.</p>
{% if not is_demo_account %}<a class="button" href="{% url 'food:scanner' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">Scan barcode</a>
<a class="button button--secondary" href="{% url 'food:external-search' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}&amp;q={{ query|urlencode }}">Search Open Food Facts</a>{% endif %}</div>
{% if not is_demo_account %}<form method="post" action="{% url 'food:import-product' %}" class="food-barcode-form">{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="meal" value="{{ meal }}"><label for="food-barcode">Barcode</label><input id="food-barcode" name="barcode" inputmode="numeric" pattern="[0-9]+" required><button class="button button--secondary" type="submit">Look up barcode</button></form>{% endif %}
{% if not is_demo_account %}<p class="food-attribution">External product data from <a href="https://world.openfoodfacts.org/" rel="noopener noreferrer">Open Food Facts</a>.</p>{% endif %}
{% endif %}
</div>
{% if product %}<script src="{% static 'food/portions.js' %}" defer></script>{% endif %}
{% if not product %}<nav class="food-mobile-switch" aria-label="Add food method"><span aria-current="page">Search</span><a href="{% url 'food:scanner' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">Barcode</a></nav>{% endif %}
{% if not product and not is_demo_account %}<nav class="food-mobile-switch" aria-label="Add food method"><span aria-current="page">Search</span><a href="{% url 'food:scanner' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">Barcode</a></nav>{% endif %}
@@ -9,6 +9,21 @@
<form method="post" class="food-card food-entry-form" hx-post="{% url 'food:edit' entry.pk %}" hx-target="#food-workspace" hx-swap="outerHTML">{% csrf_token %}
{% include 'food/partials/portion_fields.html' %}
<div class="form-field">{{ form.quantity.label_tag }}{{ form.quantity }}{{ form.quantity.errors }}<small>Multiplies the selected portion. For example, 2 means two of that portion.</small></div>
<details class="entry-nutrition-fields" {% if form.edit_nutrition.value or form.calories_kcal.errors or form.carbohydrates_g.errors or form.protein_g.errors or form.fat_g.errors or form.fibre_g.errors or form.sugars_g.errors or form.salt_g.errors %}open{% endif %}>
<summary>Correct nutrition for this entry</summary>
<p>Values are for one logged portion ({{ entry.amount|floatformat:-3 }} {{ entry.unit }}), before the quantity multiplier. Leave a value blank if unknown. This does not change the saved product.</p>
<div class="form-field">{{ form.edit_nutrition.label_tag }}{{ form.edit_nutrition }}{{ form.edit_nutrition.errors }}<small>Without this selection, nutrition scales automatically when the portion amount changes.</small></div>
<div class="nutrition-field-grid">
<div class="form-field">{{ form.calories_kcal.label_tag }}{{ form.calories_kcal }}{{ form.calories_kcal.errors }}</div>
<div class="form-field">{{ form.carbohydrates_g.label_tag }}{{ form.carbohydrates_g }}{{ form.carbohydrates_g.errors }}</div>
<div class="form-field">{{ form.protein_g.label_tag }}{{ form.protein_g }}{{ form.protein_g.errors }}</div>
<div class="form-field">{{ form.fat_g.label_tag }}{{ form.fat_g }}{{ form.fat_g.errors }}</div>
<div class="form-field">{{ form.fibre_g.label_tag }}{{ form.fibre_g }}{{ form.fibre_g.errors }}</div>
<div class="form-field">{{ form.sugars_g.label_tag }}{{ form.sugars_g }}{{ form.sugars_g.errors }}</div>
<div class="form-field">{{ form.salt_g.label_tag }}{{ form.salt_g }}{{ form.salt_g.errors }}</div>
</div>
</details>
{% if product %}<p><a href="{% url 'food:product-edit' product.pk %}">Edit saved product nutrition for future logs</a></p>{% endif %}
<button class="button" type="submit">Save changes</button>
</form>
<form method="post" action="{% url 'food:delete' entry.pk %}" onsubmit="return confirm('Delete this food entry?')" hx-post="{% url 'food:delete' entry.pk %}" hx-target="#food-workspace" hx-swap="outerHTML">{% csrf_token %}<button type="submit" class="button button--secondary">Delete entry</button></form>
@@ -1,5 +1,5 @@
<div class="food-actions inventory-product-actions">
<a class="button" href="{% url 'food:scanner' %}?mode=inventory">Scan barcode</a>
<a class="button button--secondary" href="{% url 'food:inventory-external' %}?q={{ query|urlencode }}">Search Open Food Facts</a>
{% if not is_demo_account %}<a class="button" href="{% url 'food:scanner' %}?mode=inventory">Scan barcode</a>
<a class="button button--secondary" href="{% url 'food:inventory-external' %}?q={{ query|urlencode }}">Search Open Food Facts</a>{% endif %}
<a class="button button--secondary" href="{% url 'food:inventory-manual' %}">Create manual product</a>
</div>
@@ -0,0 +1,21 @@
<fieldset class="nutrition-fields">
<legend>Nutrition</legend>
<p>Enter values for the basis amount and unit below. Leave a value blank when it is unknown; zero means the label says zero.</p>
<div class="form-field">{{ form.basis_amount.label_tag }}{{ form.basis_amount }}{{ form.basis_amount.errors }}</div>
<div class="form-field">{{ form.base_unit.label_tag }}{{ form.base_unit }}{{ form.base_unit.errors }}{% if form.base_unit.field.disabled %}<small>The nutrition unit is fixed for an existing product.</small>{% endif %}</div>
<div class="nutrition-field-grid">
<div class="form-field">{{ form.energy_kcal_100.label_tag }}{{ form.energy_kcal_100 }}{{ form.energy_kcal_100.errors }}</div>
<div class="form-field">{{ form.carbohydrates_100.label_tag }}{{ form.carbohydrates_100 }}{{ form.carbohydrates_100.errors }}</div>
<div class="form-field">{{ form.protein_100.label_tag }}{{ form.protein_100 }}{{ form.protein_100.errors }}</div>
<div class="form-field">{{ form.fat_100.label_tag }}{{ form.fat_100 }}{{ form.fat_100.errors }}</div>
</div>
<details {% if form.saturated_fat_100.errors or form.fibre_100.errors or form.sugars_100.errors or form.salt_100.errors %}open{% endif %}>
<summary>More nutrients</summary>
<div class="nutrition-field-grid">
<div class="form-field">{{ form.saturated_fat_100.label_tag }}{{ form.saturated_fat_100 }}{{ form.saturated_fat_100.errors }}</div>
<div class="form-field">{{ form.fibre_100.label_tag }}{{ form.fibre_100 }}{{ form.fibre_100.errors }}</div>
<div class="form-field">{{ form.sugars_100.label_tag }}{{ form.sugars_100 }}{{ form.sugars_100.errors }}</div>
<div class="form-field">{{ form.salt_100.label_tag }}{{ form.salt_100 }}{{ form.salt_100.errors }}</div>
</div>
</details>
</fieldset>
@@ -0,0 +1,5 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Edit product nutrition · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}?v=20261021-nutrition"><div class="food-form-page"><a href="{% url 'food:inventory' %}">← Kitchen Inventory</a><h1>Edit {{ product.product_name }}</h1><p>Changes to this product affect future food logs. Existing Food Diary entries keep their recorded nutrition; edit an entry to correct its own values.</p>{% if product.source == 'openfoodfacts' %}<p>Imported from Open Food Facts{% if product.raw_data.manual_nutrition_override %}; nutrition has been corrected manually{% endif %}.</p>{% endif %}<form method="post" class="food-card product-form">{% csrf_token %}{{ form.non_field_errors }}
{% for field in form %}{% if field.name == 'product_name' or field.name == 'brand' or field.name == 'barcode' %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endif %}{% endfor %}
{% include 'food/partials/product_nutrition_fields.html' %}<button class="button" type="submit">Save product</button></form><p><a href="{% url 'food:inventory' %}">Kitchen Inventory</a> · <a href="{% url 'food:add' %}?product={{ product.pk }}">Log this food</a></p></div>{% endblock %}