Ulepsane forme

This commit is contained in:
rglst 2023-02-17 03:23:06 +01:00
parent 2090b77ce4
commit b3b591db36
7 changed files with 50 additions and 31 deletions

View File

@ -7,6 +7,7 @@ from .utils import get_all_recipes
@app.get("/") @app.get("/")
@app.get("/recipes")
def index(): def index():
data = {"recipes": get_all_recipes()} data = {"recipes": get_all_recipes()}
return render_template("pages/index.html", data=data) return render_template("pages/index.html", data=data)
@ -36,7 +37,7 @@ def add_new_ingredient():
except Exception as e: except Exception as e:
return "greska, vec postoji sastojak" return "greska, vec postoji sastojak"
return "napravljeno" return redirect("/ingredients")
@app.get("/ingredients/edit/<int:id>") @app.get("/ingredients/edit/<int:id>")
@ -57,14 +58,14 @@ def edit_ingredient(id):
db.session.flush() db.session.flush()
db.session.commit() db.session.commit()
return "updated" return redirect("/ingredients")
@app.get("/ingredients/delete/<int:id>") @app.get("/ingredients/delete/<int:id>")
def delete_ingredient(id): def delete_ingredient(id):
Ingredient.query.filter_by(id=id).delete() Ingredient.query.filter_by(id=id).delete()
db.session.commit() db.session.commit()
return "Deleted" return redirect("/ingredients")
# Recipes CRUD # Recipes CRUD
@ -108,7 +109,7 @@ def create_recipe_in_db():
assoc.ingredient_ammount = ammount assoc.ingredient_ammount = ammount
db.session.add(recipe) db.session.add(recipe)
db.session.commit() db.session.commit()
return "created" return redirect("/recipes")
@app.get("/recipes/edit/<int:id>") @app.get("/recipes/edit/<int:id>")
@ -165,7 +166,7 @@ def edit_recipe_in_db(id):
db.session.add(old_recipe) db.session.add(old_recipe)
db.session.commit() db.session.commit()
return "ok" return redirect("/recipes")
@app.get("/calculate") @app.get("/calculate")

View File

@ -1,9 +1,11 @@
<form @submit.prevent method="POST"> <form @submit.prevent method="POST">
<select x-model.number="recipe_id" name="recipe_id"> <div class="form-group">
<select class="form-control" x-model.number="recipe_id" name="recipe_id">
{% for recipe in data["recipes"] %} {% for recipe in data["recipes"] %}
<option value="{{recipe.id}}">{{recipe.name}}</option> <option value="{{recipe.id}}">{{recipe.name}}</option>
{% endfor %} {% endfor %}
</select> </select>
<input @input.debounce.300="getResults()" x-model.number="ammount" type="number" step="1" name="ammount" placeholder="Koliko obroka"> <input @input.debounce.300="getResults()" x-model.number="ammount" type="number" step="1" name="ammount" placeholder="Koliko obroka">
</div>
<!--<button @click="getResults()" type="submit">Izracunaj</button> --> <!--<button @click="getResults()" type="submit">Izracunaj</button> -->
</form> </form>

View File

@ -1,11 +1,15 @@
<form method="POST"> <form method="POST">
<div class="form-group">
<label for="ingredient_name">Naziv</label> <label for="ingredient_name">Naziv</label>
<input id="ingredient_name" type="text" required name="name" value="{{ingredient.name}}"> <input class="form-control" id="ingredient_name" type="text" required name="name" value="{{ingredient.name}}">
<br> </div>
<div class="form-group">
<label for="ingredient_price">Cena</label> <label for="ingredient_price">Cena</label>
<input id="ingredient_price" type="number" required name="price" value="{{ingredient.price}}"> <input class="form-control" id="ingredient_price" type="number" required name="price" value="{{ingredient.price}}">
<br> </div>
<button> <div class="form-group">
<button class="btn btn-danger">
Dodaj Sastojak Dodaj Sastojak
</button> </button>
</div>
</form> </form>

View File

@ -1,15 +1,20 @@
<form method="POST"> <form method="POST">
<div class="form-group">
<label for="recipe_name">Naziv: </label> <label for="recipe_name">Naziv: </label>
<input type="text" name="recipe_name" value='{{data["recipe"].name}}'> <input class="form-control" type="text" name="recipe_name" value='{{data["recipe"].name}}'>
<br> </div>
{% for ingredient in data["ingredients_inside"] %} {% for ingredient in data["ingredients_inside"] %}
<input checked type="checkbox" id="{{ingredient.name}}" name="ingredients" value="{{ingredient.id}}"> <label for="{{ingredient.name}}">{{ingredient.name}}</label> <input type="number" name="{{ingredient.id}}_ammount" placeholder="kg/L" value="{{ingredient.ammount}}"> <div class="form-group">
<br> <input class="form-check-input" checked type="checkbox" id="{{ingredient.name}}" name="ingredients" value="{{ingredient.id}}"> <label class="form-check-label"for="{{ingredient.name}}">{{ingredient.name}}</label> <input class="form-control" type="number" name="{{ingredient.id}}_ammount" placeholder="kg/L" value="{{ingredient.ammount}}">
</div>
{% endfor %} {% endfor %}
<hr> <hr>
{% for ingredient in data["ingredients_rest"] %} {% for ingredient in data["ingredients_rest"] %}
<input type="checkbox" id="{{ingredient.name}}" name="ingredients" value="{{ingredient.id}}"> <label for="{{ingredient.name}}">{{ingredient.name}}</label> <input type="number" name="{{ingredient.id}}_ammount" placeholder="kg/L"> <div class="form-group">
<br> <input class="form-check-input" type="checkbox" id="{{ingredient.name}}" name="ingredients" value="{{ingredient.id}}"> <label class="form-check-label" for="{{ingredient.name}}">{{ingredient.name}}</label> <input class="form-control" type="number" name="{{ingredient.id}}_ammount" placeholder="kg/L">
</div>
{% endfor %} {% endfor %}
<button>Dodaj recept</button> <div class="form-group">
<button class="btn btn-danger">Dodaj recept</button>
</div>
</form> </form>

View File

@ -1,11 +1,13 @@
<form method="POST"> <form method="POST">
<div class="form-group">
<label for="ingredient_name">Naziv</label> <label for="ingredient_name">Naziv</label>
<input id="ingredient_name" type="text" required name="name" placeholder="Naziv..."> <input class="form-control" id="ingredient_name" type="text" required name="name" placeholder="Naziv...">
<br> </div>
<div class="form-group">
<label for="ingredient_price">Cena</label> <label for="ingredient_price">Cena</label>
<input id="ingredient_price" type="number" required name="price" placeholder="Cena..."> <input class="form-control" id="ingredient_price" type="number" required name="price" placeholder="Cena...">
<br> </div>
<button> <button class="btn btn-danger">
Dodaj Sastojak Dodaj Sastojak
</button> </button>
</form> </form>

View File

@ -1,10 +1,12 @@
<form method="POST"> <form method="POST">
<div class="form-group">
<label for="recipe_name">Naziv: </label> <label for="recipe_name">Naziv: </label>
<input type="text" name="recipe_name"> <input class="form-control" type="text" name="recipe_name">
<br> </div>
{% for ingredient in data["ingredients"] %} {% for ingredient in data["ingredients"] %}
<input type="checkbox" id="{{ingredient.name}}" name="ingredients" value="{{ingredient.id}}"> <label for="{{ingredient.name}}">{{ingredient.name}}</label> <input step="0.01"type="number" name="{{ingredient.id}}_ammount" placeholder="kg/L"> <div class="form-group">
<br> <input class="form-check-input"type="checkbox" id="{{ingredient.name}}" name="ingredients" value="{{ingredient.id}}"> <label class="form-check-label" for="{{ingredient.name}}">{{ingredient.name}}</label> <input class="form-control" step="0.01" type="number" name="{{ingredient.id}}_ammount" placeholder="kg/L">
</div>
{% endfor %} {% endfor %}
<button>Dodaj recept</button> <button class="btn btn-danger">Dodaj recept</button>
</form> </form>

View File

@ -2,9 +2,12 @@
{% block content %} {% block content %}
<div class="row"> <div class="row">
<a href="/recipes/new" class="btn btn-danger">Dodaj recept</a>
{% for recipe in data["recipes"] %} {% for recipe in data["recipes"] %}
<li> <li>
<h3>{{recipe.recipe.name}}</h3> <h3>{{recipe.recipe.name}}</h3>
<a href="/recipes/edit/{{recipe.recipe.id}}" class="btn btn-danger">Izmeni</a>
<a href="/recipes/delete/{{recipe.recipe.id}}" class="btn btn-dark">Obrisi</a>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>