Compare commits

..

14 commits

Author SHA1 Message Date
Benjamin b123a010a3 Refactor forms 2023-03-19 18:49:45 +01:00
Benjamin 4925e1caab Add license header to source files 2023-03-19 18:16:45 +01:00
Benjamin 2085008504 Add url patterns 2023-03-19 18:16:44 +01:00
Benjamin 564f538708 Add views 2023-03-19 18:16:44 +01:00
Benjamin ba196d046c Add HTML templates 2023-03-19 18:16:44 +01:00
Benjamin 846c5cf1f6 Add forms 2023-03-19 18:16:44 +01:00
Benjamin 7b1c9b0f45 Register models to admin 2023-03-19 18:16:44 +01:00
Benjamin 35da38858f Add models 2023-03-19 18:16:44 +01:00
Benjamin f13cf3d6c7 Add links to recipes add to nav list and index 2023-03-19 18:16:43 +01:00
Benjamin a860cf9406 Add recipes/ url pattern 2023-03-19 18:16:43 +01:00
Benjamin 208c4581d6 Start App Recipes 2023-03-19 18:16:43 +01:00
Benjamin 94a49a494e User form.as_div instead of tables 2023-03-19 18:16:43 +01:00
Benjamin 900e01da1b Add link to source code 2023-03-19 18:16:43 +01:00
Benjamin fb4bd446d4 Add license header to source files 2023-03-19 18:16:43 +01:00
14 changed files with 41 additions and 157 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,5 @@
{#
{% extends "base_main.html" %}
{% comment %}
Barn Web App - A collection of web-apps for my family's personal use,
including a recipe database.
Copyright © 2023 Benjamin Stadlbauer
@ -15,8 +16,7 @@
This program comes with a copy of the GNU Affero General Public License
file at the root of this project.
#}
{% extends "base_main.html" %}
{% endcomment %}
{% block title %}{{ recipe.title }}{% endblock %}
{% block main %}
<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))
ingredients_formset = IngredientFormSet(queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX)
return render(request, 'add-recipe.html', {'recipe_form': recipe_form, 'version_form': version_form, 'ingredients_formset': ingredients_formset})
return render(request, 'recipe-form.html', {'recipe_form': recipe_form, 'version_form': version_form, 'ingredients_formset': ingredients_formset})
@login_required
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))
ingredients_formset = IngredientFormSet(queryset=Ingredient.objects.none(), prefix=INGREDIENTS_FORMSET_PREFIX)
return render(request, 'add-version.html', {'version_form': version_form, 'ingredients_formset': ingredients_formset})
return render(request, 'recipe-form.html', {'version_form': version_form, 'ingredients_formset': ingredients_formset})
@login_required
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))
ingredients_formset = IngredientFormSet(queryset=version.ingredients.all(), prefix=INGREDIENTS_FORMSET_PREFIX) # type: ignore
return render(request, 'edit-version.html', {'version_form': version_form, 'ingredients_formset': ingredients_formset})
return render(request, 'recipe-form.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,
including a recipe database.
Copyright © 2023 Benjamin Stadlbauer
@ -15,7 +15,7 @@
This program comes with a copy of the GNU Affero General Public License
file at the root of this project.
#}
{% endcomment %}
<!DOCTYPE html>
<html lang="en">

View file

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

View file

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

View file

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

View file

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

View file

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