From 10275695e4d804f11ac5ecdc4ec11442eca90635 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Thu, 18 Apr 2024 19:47:05 +0200 Subject: [PATCH] Added error popup to 404 error on set lookup --- app.py | 21 +++++++---- templates/create.html | 82 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 8e2c6df..0c7fc34 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, request, redirect, jsonify, render_template, Response +from flask import Flask, request, redirect, jsonify, render_template, Response,url_for import json from pprint import pprint as pp from pathlib import Path @@ -42,10 +42,10 @@ def create(): if request.method == 'POST': set_num = request.form['inputField'] - add_duplicate = request.form.get('addDuplicate', False) == 'true' + # add_duplicate = request.form.get('addDuplicate', False) == 'true' # Do something with the input value and the checkbox value - print("Input value:", set_num) - print("Add duplicate:", add_duplicate) + # print("Input value:", set_num) + # print("Add duplicate:", add_duplicate) # You can perform any further processing or redirect to another page if '-' not in set_num: @@ -59,10 +59,16 @@ def create(): unique_set_id = generate_unique_set_unique() # Get Set info and add to SQL - response = json.loads(rebrick.lego.get_set(set_num).read()) - count+=1 - print(response) + response = '' + try: + response = json.loads(rebrick.lego.get_set(set_num).read()) + except Exception as e: + print(e.code) + if e.code == 404: + return render_template('create.html',error=set_num) + count+=1 + cursor.execute('''INSERT INTO sets ( set_num, name, @@ -242,6 +248,7 @@ def create(): conn.commit() conn.close() + print(count) return redirect('/') conn.close() diff --git a/templates/create.html b/templates/create.html index 6d1d632..cc382cf 100644 --- a/templates/create.html +++ b/templates/create.html @@ -45,6 +45,88 @@ + {% if error is defined %} + + {% else %} + + {% endif %} + + + + + + + +