Exceptionhandling, underpay warning

This commit is contained in:
elpatron68
2024-05-27 10:20:25 +02:00
parent 9050ec7c03
commit ff84b5ec40
2 changed files with 18 additions and 8 deletions

16
app.py
View File

@@ -17,10 +17,11 @@ item3 = 0
item4 = 0 item4 = 0
item5 = 0 item5 = 0
item6 = 0 item6 = 0
background = "bg-white"
@app.route("/", methods=["GET", "POST"]) @app.route("/", methods=["GET", "POST"])
def index(): def index():
global gesamtwert, item1, item2, item3, item4, item5, item6, sum, givenfloat, change, given global gesamtwert, item1, item2, item3, item4, item5, item6, sum, givenfloat, change, given, background
if request.method == "POST": if request.method == "POST":
# wert = float(request.form["wert"]) # wert = float(request.form["wert"])
@@ -41,6 +42,7 @@ def index():
item4 = 0 item4 = 0
item5 = 0 item5 = 0
item6 = 0 item6 = 0
background = "bg-white"
# summarize value # summarize value
elif wertfloat != -2: elif wertfloat != -2:
gesamtwert += wertfloat gesamtwert += wertfloat
@@ -62,10 +64,17 @@ def index():
if wertfloat == .2: if wertfloat == .2:
item6 += 1 item6 += 1
if givenfloat > 0: if givenfloat > 0:
gesamtwert = session['summefloat'] try:
gesamtwert = session['summefloat'] or 0
sum = str(gesamtwert) + "0" sum = str(gesamtwert) + "0"
change = str(round((givenfloat - gesamtwert) * -1, 2)) + "0" change = str(round((givenfloat - gesamtwert) * -1, 2)) + "0"
logging.info('Sum %s, given %s, change %s', sum, givenfloat, change) logging.info('Sum %s, given %s, change %s', sum, givenfloat, change)
except:
logging.warning("Failed to read sum")
if givenfloat - gesamtwert < 0:
background = "bg-danger"
else:
background = "bg-white"
session['item1'] = item1 session['item1'] = item1
session['item2'] = item2 session['item2'] = item2
@@ -87,6 +96,7 @@ def index():
item4=session.get('item4', 0), item4=session.get('item4', 0),
item5=session.get('item5', 0), item5=session.get('item5', 0),
item6=session.get('item6', 0), item6=session.get('item6', 0),
background=background,
) )
@app.route('/favicon.ico') @app.route('/favicon.ico')
@@ -100,5 +110,5 @@ def favicon():
# 'about.html') # 'about.html')
if __name__ == "__main__": if __name__ == "__main__":
logging.info('Starting erdbeerhannah v1.0.2') logging.info('Starting erdbeerhannah v1.0.3')
app.run(debug=True, host='0.0.0.0') app.run(debug=True, host='0.0.0.0')

View File

@@ -84,14 +84,14 @@
<button type="submit" name="wert" value="-2" class="btn btn-xl btn-primary custom-btn-size-med">🧾</button> <button type="submit" name="wert" value="-2" class="btn btn-xl btn-primary custom-btn-size-med">🧾</button>
</div> </div>
</td> </td>
<td class="bold-row">🪙 {{ change }}€</td> <td class="bold-row {{ background }}">🪙 {{ change }}€</td>
</tr> </tr>
<tr> <tr>
<td colspan="3"><button type="submit" name="wert" value="0" id="reset" class="btn btn-xl btn-dark custom-btn-size">Reset 🦭</button></td> <td colspan="3"><button type="submit" name="wert" value="0" id="reset" class="btn btn-xl btn-dark custom-btn-size">Reset 🦭</button></td>
</tr> </tr>
<tr> <tr>
<td colspan="3">Made with ♥️, marmalade and zero kowledge in Kiel Strawberry City.<br> <td colspan="3">Made with ♥️, marmalade and zero kowledge in Kiel Strawberry City.<br>
Version: 1.0.2/2024-05-26<br> Version: 1.0.3/2024-05-27<br>
<a href="https://gitea.elpatron.me/elpatron/erdbeerhannah/src/branch/main/README.md" target="_blank">Weitere Infos</a></td> <a href="https://gitea.elpatron.me/elpatron/erdbeerhannah/src/branch/main/README.md" target="_blank">Weitere Infos</a></td>
</tr> </tr>
</tbody> </tbody>