forked from svitvojimilioni/kuhkal
Obrisan javascript
This commit is contained in:
parent
2ec9506216
commit
d90825a818
@ -169,15 +169,17 @@ def edit_recipe_in_db(id):
|
||||
return redirect("/recipes")
|
||||
|
||||
|
||||
@app.get("/calculate")
|
||||
def calculator():
|
||||
@app.route("/calculate", methods=["GET", "POST"])
|
||||
def calculator_form():
|
||||
if request.method == "GET":
|
||||
data = {"recipes": Recipe.query.all()}
|
||||
return render_template("pages/calculate.html", data=data)
|
||||
|
||||
|
||||
@app.post("/calculate")
|
||||
def calculate():
|
||||
req_data = request.get_json()
|
||||
return render_template("pages/calculate_form.html", data=data)
|
||||
elif request.method == "POST":
|
||||
## breakpoint()
|
||||
print("123")
|
||||
#data = {"recipes": Recipe.query.all()}
|
||||
req_data = request.form
|
||||
print(req_data)
|
||||
recipe_id = req_data["recipe_id"]
|
||||
recipe = Recipe.query.get(recipe_id)
|
||||
ingredients_inside = []
|
||||
@ -196,9 +198,37 @@ def calculate():
|
||||
ingredients_inside.append(ingr_dict)
|
||||
price = calculate_price(ingredients_inside)
|
||||
data = {"ingredients": ingredients_inside, "price": price}
|
||||
##breakpoint()
|
||||
return render_template("pages/calculate_results.html", data=data)
|
||||
|
||||
return jsonify(data)
|
||||
|
||||
#@app.post("/calculate")
|
||||
def calculate():
|
||||
breakpoint()
|
||||
req_data = request.form
|
||||
##recipe_id = req_data["recipe_id"]
|
||||
recipe_id = int(req_data[0][1])
|
||||
recipe = Recipe.query.get(recipe_id)
|
||||
ingredients_inside = []
|
||||
##ammount = req_data["ammount"]
|
||||
ammount = int(req_data[1][1])
|
||||
for ingredient in recipe.ingredients:
|
||||
ingr = Ingredient.query.get(ingredient.ingredient_id)
|
||||
ingr_dict = {
|
||||
"name": ingr.name,
|
||||
"price": ingr.price,
|
||||
"ammount": ingredient.ingredient_ammount,
|
||||
"calculated_ammount": float(ingredient.ingredient_ammount)
|
||||
* (int(ammount) / 10),
|
||||
"calculated_price": float(ingr.price) * (int(ammount) / 10),
|
||||
"id": ingr.id,
|
||||
}
|
||||
ingredients_inside.append(ingr_dict)
|
||||
price = calculate_price(ingredients_inside)
|
||||
data = {"ingredients": ingredients_inside, "price": price}
|
||||
|
||||
#return jsonify(data)
|
||||
return data
|
||||
|
||||
def calculate_price(ingredients: list) -> float:
|
||||
price = 0
|
||||
|
@ -1,11 +1,11 @@
|
||||
<form @submit.prevent method="POST">
|
||||
<form action="/calculate" method="POST">
|
||||
<div class="form-group">
|
||||
<select class="form-control" x-model.number="recipe_id" name="recipe_id">
|
||||
<select class="form-control" name="recipe_id">
|
||||
{% for recipe in data["recipes"] %}
|
||||
<option value="{{recipe.id}}">{{recipe.name}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input @input.debounce.300="getResults()" x-model.number="ammount" type="number" step="1" name="ammount" placeholder="Koliko obroka">
|
||||
<input type="number" step="1" name="ammount" placeholder="Koliko obroka">
|
||||
</div>
|
||||
<!--<button @click="getResults()" type="submit">Izracunaj</button> -->
|
||||
<button type="submit">Izracunaj</button>
|
||||
</form>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<th>Kolicina</th>
|
||||
<th>Cena</th>
|
||||
</thead>
|
||||
<template x-for="ingredient in results['ingredients']">
|
||||
{% for ingredient in data['ingredients'] %}
|
||||
<tr>
|
||||
<td x-text="ingredient['name']"></td>
|
||||
<td x-text="ingredient['calculated_ammount']"></td>
|
||||
<td x-text="ingredient['calculated_price'] + ' RSD'"></td>
|
||||
<td>{{ingredient['name']}}</td>
|
||||
<td>{{ingredient['calculated_ammount']}}</td>
|
||||
<td>{{ingredient['calculated_price']}} RSD</td>
|
||||
</tr>
|
||||
</template>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<p>Cena: <b x-text="results['price']"></b> RSD</p>
|
||||
<p>Cena: <b> {data['price']}}</b> RSD</p>
|
||||
</div>
|
||||
|
@ -1,23 +1,7 @@
|
||||
{% extends "layouts/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div x-data="{ results: {},
|
||||
recipe_id: 1,
|
||||
ammount:40,
|
||||
async getResults() {
|
||||
this.results = await (await fetch('https://solidarna.cyberdeck.xyz/calculate', {
|
||||
method:'POST',
|
||||
body: JSON.stringify({
|
||||
recipe_id: this.recipe_id,
|
||||
ammount: this.ammount
|
||||
}),
|
||||
headers: {
|
||||
'Content-type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
})).json();
|
||||
console.log(this.results);
|
||||
}
|
||||
} ">
|
||||
<div>
|
||||
{% include "includes/calculate_form.html" %}
|
||||
{% include "includes/calculate_results.html" %}
|
||||
</div>
|
||||
|
5
kuhkal/templates/pages/calculate_form.html
Normal file
5
kuhkal/templates/pages/calculate_form.html
Normal file
@ -0,0 +1,5 @@
|
||||
{% extends "layouts/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% include "includes/calculate_form.html" %}
|
||||
{% endblock content %}
|
5
kuhkal/templates/pages/calculate_results.html
Normal file
5
kuhkal/templates/pages/calculate_results.html
Normal file
@ -0,0 +1,5 @@
|
||||
{% extends "layouts/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% include "includes/calculate_results.html" %}
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user