Compare commits

..

13 commits

14 changed files with 157 additions and 41 deletions

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,15 +15,16 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block title %}{{ recipe.title }}{% endblock %} {% block title %}{{ recipe.title }}{% endblock %}
{% block main %} {% block main %}
<form action="" method="post" id="version-form"> <form action="" method="post" id="add-version-form">
{%csrf_token %} {%csrf_token %}
{% if recipe_form %} {{ recipe_form.as_div }}
{{ recipe_form.as_div }} <table>
{% endif %} {{ version_form.as_table }}
{{ version_form.as_div }} </table>
{{ ingredients_formset.management_form }} {{ ingredients_formset.management_form }}
{% for ingredient_form in ingredients_formset %} {% for ingredient_form in ingredients_formset %}
{{ ingredient_form.as_div }} {{ ingredient_form.as_div }}
@ -36,7 +36,7 @@
<script> <script>
let firstIngredientDiv = document.querySelector("input[id^=id_ingredient][id$=text]").parentElement; let firstIngredientDiv = document.querySelector("input[id^=id_ingredient][id$=text]").parentElement;
let addIngredientButton = document.querySelector("#add-ingredient"); let addIngredientButton = document.querySelector("#add-ingredient");
let form = document.querySelector("#version-form"); let form = document.querySelector("#add-version-form");
let totalIngredientFormsInput = document.querySelector("#id_ingredient-TOTAL_FORMS"); let totalIngredientFormsInput = document.querySelector("#id_ingredient-TOTAL_FORMS");
addIngredientButton.addEventListener('click', addIngredient); addIngredientButton.addEventListener('click', addIngredient);

View file

@ -0,0 +1,58 @@
{#
Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database.
Copyright © 2023 Benjamin Stadlbauer
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
General Public License for more details.
This program comes with a copy of the GNU Affero General Public License
file at the root of this project.
#}
{% extends "base_main.html" %}
{% block title %}{{ recipe.title }}{% endblock %}
{% block main %}
<form action="" method="post" id="add-version-form">
{%csrf_token %}
<table>
{{ version_form.as_table }}
</table>
{{ ingredients_formset.management_form }}
{% for ingredient_form in ingredients_formset %}
{{ ingredient_form.as_div }}
{% endfor %}
<button id="add-ingredient" type="button">Add Ingredient</button>
<input type="submit" value="Submit">
</form>
<script>
let firstIngredientDiv = document.querySelector("input[id^=id_ingredient][id$=text]").parentElement;
let addIngredientButton = document.querySelector("#add-ingredient");
let form = document.querySelector("#add-version-form");
let totalIngredientFormsInput = document.querySelector("#id_ingredient-TOTAL_FORMS");
addIngredientButton.addEventListener('click', addIngredient);
function addIngredient(e) {
let nextIngredientIndex = document.querySelectorAll("input[id^=id_ingredient][id$=text]").length
e.preventDefault();
let newIngredientDiv = firstIngredientDiv.cloneNode(true);
let formRegex = new RegExp('ingredient-(\\d){1}-', 'g');
newIngredientDiv.innerHTML = newIngredientDiv.innerHTML.replace(formRegex, `ingredient-${nextIngredientIndex}-`);
form.insertBefore(newIngredientDiv, addIngredientButton);
totalIngredientFormsInput.setAttribute('value', `${nextIngredientIndex + 1}`);
}
</script>
{% endblock %}

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block title %}{{ recipe.title }}{% endblock %} {% block title %}{{ recipe.title }}{% endblock %}
{% block main %} {% block main %}
<form action="" method="post"> <form action="" method="post">

View file

@ -0,0 +1,58 @@
{#
Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database.
Copyright © 2023 Benjamin Stadlbauer
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
General Public License for more details.
This program comes with a copy of the GNU Affero General Public License
file at the root of this project.
#}
{% extends "base_main.html" %}
{% block title %}{{ recipe.title }}{% endblock %}
{% block main %}
<form action="" method="post" id="edit-version-form"> {# TODO refactor with add-version.html#}
{%csrf_token %}
<table>
{{ version_form.as_table }}
</table>
{{ ingredients_formset.management_form }}
{% for ingredient_form in ingredients_formset %}
{{ ingredient_form.as_div }}
{% endfor %}
<button id="add-ingredient" type="button">Add Ingredient</button>
<input type="submit" value="Submit">
</form>
<script>
let firstIngredientDiv = document.querySelector("input[id^=id_ingredient][id$=text]").parentElement;
let addIngredientButton = document.querySelector("#add-ingredient");
let form = document.querySelector("#edit-version-form");
let totalIngredientFormsInput = document.querySelector("#id_ingredient-TOTAL_FORMS");
addIngredientButton.addEventListener('click', addIngredient);
function addIngredient(e) {
let nextIngredientIndex = document.querySelectorAll("input[id^=id_ingredient][id$=text]").length
e.preventDefault();
let newIngredientDiv = firstIngredientDiv.cloneNode(true);
let formRegex = new RegExp('ingredient-(\\d){1}-', 'g');
newIngredientDiv.innerHTML = newIngredientDiv.innerHTML.replace(formRegex, `ingredient-${nextIngredientIndex}-`);
form.insertBefore(newIngredientDiv, addIngredientButton);
totalIngredientFormsInput.setAttribute('value', `${nextIngredientIndex + 1}`);
}
</script>
{% endblock %}

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block title %}{{ recipe.title }}{% endblock %} {% block title %}{{ recipe.title }}{% endblock %}
{% block main %} {% block main %}
<h1>{{ recipe.title }}</h1> <h1>{{ recipe.title }}</h1>

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block title %}Recipes{% endblock %} {% block title %}Recipes{% endblock %}
{% block main %} {% block main %}
<h1>Recipes</h1> <h1>Recipes</h1>

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block title %}{{ recipe.title }}{% endblock %} {% block title %}{{ recipe.title }}{% endblock %}
{% block main %} {% block main %}
<h1>{{ version.recipe.title }}{% if has_multiple_versions %} ({{ version.label }}){% endif %}</h1> <h1>{{ version.recipe.title }}{% if has_multiple_versions %} ({{ version.label }}){% endif %}</h1>

View file

@ -85,7 +85,7 @@ def add_recipe(request):
version_form = VersionForm(prefix=VERSION_FORM_PREFIX, author_placeholder=get_name_of_user(request.user)) version_form = VersionForm(prefix=VERSION_FORM_PREFIX, author_placeholder=get_name_of_user(request.user))
ingredients_formset = IngredientFormSet(queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX) ingredients_formset = IngredientFormSet(queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX)
return render(request, 'recipe-form.html', {'recipe_form': recipe_form, 'version_form': version_form, 'ingredients_formset': ingredients_formset}) return render(request, 'add-recipe.html', {'recipe_form': recipe_form, 'version_form': version_form, 'ingredients_formset': ingredients_formset})
@login_required @login_required
def edit_recipe(request, slug): def edit_recipe(request, slug):
@ -135,7 +135,7 @@ def add_version(request, slug):
version_form = VersionForm(prefix=VERSION_FORM_PREFIX, initial=version_initial, author_placeholder=get_name_of_user(request.user)) version_form = VersionForm(prefix=VERSION_FORM_PREFIX, initial=version_initial, author_placeholder=get_name_of_user(request.user))
ingredients_formset = IngredientFormSet(queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX) ingredients_formset = IngredientFormSet(queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX)
return render(request, 'recipe-form.html', {'version_form': version_form, 'ingredients_formset': ingredients_formset}) return render(request, 'add-version.html', {'version_form': version_form, 'ingredients_formset': ingredients_formset})
@login_required @login_required
def edit_version(request, slug_recipe, slug_version): def edit_version(request, slug_recipe, slug_version):
@ -164,4 +164,4 @@ def edit_version(request, slug_recipe, slug_version):
version_form = VersionForm(instance=version, prefix=VERSION_FORM_PREFIX, author_placeholder=get_name_of_user(request.user)) version_form = VersionForm(instance=version, prefix=VERSION_FORM_PREFIX, author_placeholder=get_name_of_user(request.user))
ingredients_formset = IngredientFormSet(queryset=version.ingredients.all(), prefix=INGREDIENTS_FORMSET_PREFIX) # type: ignore ingredients_formset = IngredientFormSet(queryset=version.ingredients.all(), prefix=INGREDIENTS_FORMSET_PREFIX) # type: ignore
return render(request, 'recipe-form.html', {'version_form': version_form, 'ingredients_formset': ingredients_formset}) return render(request, 'edit-version.html', {'version_form': version_form, 'ingredients_formset': ingredients_formset})

View file

@ -1,4 +1,4 @@
{% comment %} {#
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -15,7 +15,7 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">

View file

@ -1,5 +1,4 @@
{% extends "base.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base.html" %}
{% block head %} {% block head %}
{% load static %} {% load static %}

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block title %}Barn{% endblock %} {% block title %}Barn{% endblock %}
{% block main %} {% block main %}
<h1>Barn</h1> <h1>Barn</h1>

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block main %} {% block main %}

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block main %} {% block main %}
{% if form.errors %} {% if form.errors %}

View file

@ -1,5 +1,4 @@
{% extends "base_main.html" %} {#
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use, Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database. including a recipe database.
Copyright © 2023 Benjamin Stadlbauer Copyright © 2023 Benjamin Stadlbauer
@ -16,7 +15,8 @@
This program comes with a copy of the GNU Affero General Public License This program comes with a copy of the GNU Affero General Public License
file at the root of this project. file at the root of this project.
{% endcomment %} #}
{% extends "base_main.html" %}
{% block title %}Profile {{ user.username }}{% endblock %} {% block title %}Profile {{ user.username }}{% endblock %}
{% block main %} {% block main %}
<h1>Profile {{ user.username }}</h1> <h1>Profile {{ user.username }}</h1>