quantity fields in food log and recipe upload drop zone

This commit is contained in:
Joren de Graaf
2026-10-15 20:35:56 +02:00
parent f36f05b9bc
commit 86e3afaca7
25 changed files with 420 additions and 67 deletions
+3 -3
View File
@@ -1,13 +1,13 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}{% if creating %}New recipe{% else %}Edit {{ recipe.title }}{% endif %} · Tasknest{% endblock %}
{% block page_class %}recipes-page-content{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'recipes/vendor/toastui-editor.min.css' %}"><link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=4">
{% block content %}<link rel="stylesheet" href="{% static 'recipes/vendor/toastui-editor.min.css' %}"><link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=11">
<div class="recipes-layout recipes-layout--form"><header class="recipes-form-header"><a href="{% if creating %}{% url 'recipes:list' %}{% else %}{% url 'recipes:detail' recipe.api_id %}{% endif %}">← Back to recipes</a><h1>{% if creating %}New recipe{% else %}Edit recipe{% endif %}</h1><p>Keep ingredients structured and instructions in Markdown.</p></header>
<form method="post" enctype="multipart/form-data" class="recipes-edit-card" data-recipe-form data-autosave-url="{% if creating %}{% url 'recipes:autosave-new' %}{% else %}{% url 'recipes:autosave' recipe.api_id %}{% endif %}"{% if creating %} data-draft-id="{{ new_draft_id }}"{% endif %}>{% csrf_token %}
{% if creating %}<input type="hidden" name="draft_id" value="{{ new_draft_id }}">{% endif %}
{% if form.non_field_errors %}<div class="recipes-form-error" role="alert">{{ form.non_field_errors }}</div>{% endif %}
<section><h2>Recipe details</h2><div class="recipes-form-grid">{% for field in form %}{% if field.name == 'markdown_revision' %}{{ field }}{% elif field.name != 'remove_photo' %}<div class="recipes-field recipes-field--{{ field.name }}"><label for="{{ field.id_for_label }}">{{ field.label }}</label>{{ field }}{% if field.name == 'instructions_markdown' or field.name == 'notes_markdown' %}<div class="recipes-markdown-editor" data-markdown-editor="{{ field.name }}" aria-label="{{ field.label }} editor"></div>{% endif %}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{% if field.errors %}<div class="recipes-form-error" role="alert">{{ field.errors }}</div>{% endif %}</div>{% endif %}{% endfor %}{% if recipe.photo %}<div class="recipes-field recipes-field--remove_photo"><img src="{% url 'recipes:photo' recipe.api_id %}" alt="Current recipe photo" class="recipes-current-photo"><label class="recipes-checkbox">{{ form.remove_photo }} Remove current photo</label></div>{% endif %}</div></section>
<section><h2>Recipe details</h2><div class="recipes-form-grid">{% for field in form %}{% if field.name == 'markdown_revision' %}{{ field }}{% elif field.name == 'photo' %}<div class="recipes-field recipes-field--photo"><span class="recipes-photo-field-label">Recipe photo</span><div class="recipe-photo-editor" data-photo-editor><label class="recipe-photo-editor__zone" for="{{ field.id_for_label }}">{% if existing_photo %}<img src="{% url 'recipes:photo' recipe.api_id %}" alt="Current recipe photo" data-photo-preview>{% else %}<img alt="Selected recipe photo preview" data-photo-preview hidden>{% endif %}<span class="recipe-photo-editor__prompt" data-photo-prompt>{% if existing_photo %}Click or drop to replace photo{% else %}Click or drop a photo here{% endif %}<small>JPEG, PNG or WebP · up to 5 MB</small></span>{{ field }}</label><button type="button" class="recipe-photo-editor__remove" data-photo-remove aria-label="Remove current recipe photo"{% if not existing_photo %} hidden{% endif %}>×</button></div><label class="recipes-checkbox recipe-photo-editor__checkbox" hidden>{{ form.remove_photo }} Remove current photo on save</label><p class="recipe-photo-editor__status" data-photo-edit-status role="status" aria-live="polite"></p>{% if field.errors %}<div class="recipes-form-error" role="alert">{{ field.errors }}</div>{% endif %}</div>{% elif field.name != 'remove_photo' %}<div class="recipes-field recipes-field--{{ field.name }}"><label for="{{ field.id_for_label }}">{{ field.label }}</label>{{ field }}{% if field.name == 'instructions_markdown' or field.name == 'notes_markdown' %}<div class="recipes-markdown-editor" data-markdown-editor="{{ field.name }}" aria-label="{{ field.label }} editor"></div>{% endif %}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{% if field.errors %}<div class="recipes-form-error" role="alert">{{ field.errors }}</div>{% endif %}</div>{% endif %}{% endfor %}</div></section>
<section><div class="recipes-section-heading"><div><h2>Ingredients</h2><p>Add measured ingredients now; product matching can be refined later.</p></div><button type="button" class="recipes-outline-button" data-add-ingredient>+ Add ingredient</button></div>{{ ingredients.management_form }}{% if ingredients.non_form_errors %}<div class="recipes-form-error" role="alert">{{ ingredients.non_form_errors }}</div>{% endif %}<div class="recipes-ingredient-forms" data-ingredient-forms>{% for ingredient in ingredients %}{% include 'recipes/ingredient_row.html' %}{% endfor %}</div><template id="recipe-empty-ingredient">{% with ingredient=ingredients.empty_form %}{% include 'recipes/ingredient_row.html' %}{% endwith %}</template></section>
<section><div class="recipes-section-heading"><div><h2>Subrecipes</h2><p>Include an independently editable recipe as a component.</p></div><button type="button" class="recipes-outline-button" data-add-subrecipe>+ Add subrecipe</button></div>{{ subrecipes.management_form }}{% if subrecipes.non_form_errors %}<div class="recipes-form-error" role="alert">{{ subrecipes.non_form_errors }}</div>{% endif %}<div class="recipes-ingredient-forms" data-subrecipe-forms>{% for subrecipe in subrecipes %}{% include 'recipes/subrecipe_row.html' %}{% endfor %}</div><template id="recipe-empty-subrecipe">{% with subrecipe=subrecipes.empty_form %}{% include 'recipes/subrecipe_row.html' %}{% endwith %}</template></section>
<div class="recipes-form-actions"><button type="submit" class="button">Save recipe</button><a href="{% if creating %}{% url 'recipes:list' %}{% else %}{% url 'recipes:detail' recipe.api_id %}{% endif %}">Cancel</a><span class="recipes-save-status" data-save-status role="status" aria-live="polite">{% if creating %}Add a title to start autosave.{% else %}Saved{% endif %}</span></div>
</form></div><script defer src="{% static 'recipes/vendor/toastui-editor-all.min.js' %}"></script><script defer src="{% static 'recipes/editor-adapter.js' %}?v=4"></script><script defer src="{% static 'recipes/form.js' %}?v=5"></script>{% endblock %}
</form></div><script defer src="{% static 'recipes/vendor/toastui-editor-all.min.js' %}"></script><script defer src="{% static 'recipes/editor-adapter.js' %}?v=4"></script><script defer src="{% static 'recipes/form.js' %}?v=6"></script><script defer src="{% static 'recipes/photo_upload.js' %}?v=1"></script>{% endblock %}
+3 -3
View File
@@ -2,7 +2,7 @@
{% block title %}Recipes · Tasknest{% endblock %}
{% block page_class %}recipes-page-content{% endblock %}
{% block content %}
<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=7">
<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=8">
<div class="recipes-layout {% if explicit_detail %}recipes-layout--detail{% else %}recipes-layout--list{% endif %}">
<aside class="recipes-browser" aria-label="Recipe browser">
<div class="recipes-browser__heading">
@@ -40,7 +40,7 @@
{% if selected %}
<div class="recipes-detail__top"><a class="recipes-back" href="{% url 'recipes:list' %}">← Back to recipes</a><div class="recipes-detail__top-actions"><form method="post" action="{% url 'recipes:favourite' selected.api_id %}">{% csrf_token %}<button type="submit" class="recipes-heart" aria-label="{% if selected.is_favourite %}Remove {{ selected.title }} from favourites{% else %}Add {{ selected.title }} to favourites{% endif %}" aria-pressed="{% if selected.is_favourite %}true{% else %}false{% endif %}">{% if selected.is_favourite %}♥{% else %}♡{% endif %}</button></form><a class="recipes-outline-button" href="{% url 'recipes:edit' selected.api_id %}">Edit</a></div></div>
<div class="recipes-hero">
{% if selected.photo %}<img src="{% url 'recipes:photo' selected.api_id %}" alt="Photo of {{ selected.title }}">{% else %}<div class="recipes-photo-placeholder" role="img" aria-label="No recipe photo yet"><span>No photo yet</span></div>{% endif %}
{% if selected.photo %}<img src="{% url 'recipes:photo' selected.api_id %}" alt="Photo of {{ selected.title }}">{% else %}<form class="recipe-photo-upload" method="post" enctype="multipart/form-data" action="{% url 'recipes:photo-upload' selected.api_id %}" data-photo-upload>{% csrf_token %}<label class="recipes-photo-placeholder" for="recipe-detail-photo"><span class="recipe-photo-upload__icon" aria-hidden="true">↑</span><strong>Add a recipe photo</strong><span>Click or drop a JPEG, PNG or WebP image</span><input id="recipe-detail-photo" name="photo" type="file" accept="image/jpeg,image/png,image/webp" required></label><button class="recipe-photo-submit" type="submit">Upload photo</button><span class="recipe-photo-upload__status" data-photo-status role="status" aria-live="polite"></span></form>{% endif %}
<div class="recipes-hero__copy"><p class="recipes-eyebrow">{% if selected.status == 'draft' %}Draft recipe{% else %}Recipe{% endif %}</p><h2>{{ selected.title }}</h2><p class="recipes-hero__meta">{{ selected.total_minutes }} min total · {{ selected.default_servings|floatformat:-2 }} servings</p><div class="recipes-chips">{% if selected.category %}<span>{{ selected.category }}</span>{% endif %}{% for value in selected.tags %}<span>{{ value }}</span>{% endfor %}</div>{% if selected.description %}<p class="recipes-hero__description">{{ selected.description }}</p>{% endif %}</div>
</div>
<form class="recipes-serving-form" method="get" action="{% url 'recipes:detail' selected.api_id %}"><label for="recipe-servings">Servings</label><input id="recipe-servings" type="number" name="servings" min="0.01" max="99999.99" step="0.01" value="{{ analysis.servings|floatformat:-2 }}"><label class="recipes-checkbox"><input type="checkbox" name="optional" value="1"{% if analysis.include_optional %} checked{% endif %}> Include optional ingredients</label><button type="submit" class="recipes-outline-button">Update</button></form>
@@ -63,5 +63,5 @@
<section class="recipes-panel"><h3>Actions</h3><a class="recipes-action" href="{% url 'recipes:edit' selected.api_id %}">Edit recipe</a><form method="post" action="{% url 'recipes:create-variation' selected.api_id %}" class="recipes-action-form">{% csrf_token %}<button type="submit" class="recipes-action">Create variation</button></form>{% if last_use %}<form method="post" action="{% url 'recipes:stock-undo' last_use.pk %}" class="recipes-action-form">{% csrf_token %}<button type="submit" class="recipes-action">Undo last inventory use</button></form>{% endif %}<a class="recipes-action recipes-action--danger" href="{% url 'recipes:delete' selected.api_id %}">Delete recipe</a></section>
</aside>{% endif %}
</div>
<script src="{% static 'planner/responsive_filters.js' %}?v=1" defer></script>
<script src="{% static 'planner/responsive_filters.js' %}?v=1" defer></script><script src="{% static 'recipes/photo_upload.js' %}?v=1" defer></script>
{% endblock %}