Make the back end accept n text fields

This commit is contained in:
TT-392 2025-10-31 15:31:00 +00:00
parent eb1056144c
commit e41695e256
2 changed files with 40 additions and 42 deletions

80
app.py
View file

@ -180,56 +180,54 @@ def text_form():
check_for_new_user(session) check_for_new_user(session)
if request.method == 'POST': if request.method == 'POST':
print(request.form) line_count = int(request.form["lineCount"])
#session["text1"] = { lines = []
# "string": request.form["string1"], for i in range(0, line_count):
# "size": int(request.form["size1"]), lines.append({
# "pos": int(request.form["pos1"]), "string": request.form["text" + str(i)],
# "bold": "bold1" in request.form, "size": int(request.form["size" + str(i)]),
#} "pos": int(request.form["y_pos" + str(i)]),
#session["text2"] = { "bold": False
# "string": request.form["string2"], })
# "size": int(request.form["size2"]),
# "pos": int(request.form["pos2"]), # Clear previously saved font
# "bold": "bold2" in request.form, for font in session["fonts"]:
#} session["fonts"][font]["selected"] = False
## Clear previously saved font # If an invalid font has been submitted, just default to the first one
#for font in session["fonts"]: chosen_font = request.form["font"]
# session["fonts"][font]["selected"] = False if chosen_font in session["fonts"]:
session["fonts"][chosen_font]["selected"] = True
else:
first_font = next(iter(session["fonts"]))
session["fonts"][first_font]["selected"] = True
## If an invalid font has been submitted, just default to the first one # Select the first font that has been marked as selected
#chosen_font = request.form["font"] chosen_font = None
#if chosen_font in session["fonts"]: for font in session["fonts"]:
# session["fonts"][chosen_font]["selected"] = True f = session["fonts"][font]
#else: if f["selected"]:
# first_font = next(iter(session["fonts"])) chosen_font = f
# session["fonts"][first_font]["selected"] = True
## Select the first font that has been marked as selected # If the font is still None, something has gone wrong
#chosen_font = None if chosen_font is None:
#for font in session["fonts"]: return
# f = session["fonts"][font]
# if f["selected"]:
# chosen_font = f
## If the font is still None, something has gone wrong print(chosen_font)
#if chosen_font is None:
# return
#message, status, img = gen_image(label_width, session["text1"], session["text2"], chosen_font) message, status, img = gen_image(label_width, lines, chosen_font)
#if status == "Error": if status == "Error":
# session["text image path"] = None session["text image path"] = None
# return render_text_template(message, "red") return render_text_template(message, "red")
#get_folder_path(session) get_folder_path(session)
#session["text image path"] = text_image_filename session["text image path"] = text_image_filename
#img.save(get_file_path(session, session["text image path"])) img.save(get_file_path(session, session["text image path"]))
#print() print()
#print(session["text image path"]) print(session["text image path"])
return render_text_template(scrollDown = True) return render_text_template(scrollDown = True)

View file

@ -67,5 +67,5 @@ Text3 = {
"bold": False, "bold": False,
} }
gen_image(200, [Text1, Text2, Text3], fonts()["CYBER"])[2].save("aaa.png") #gen_image(200, [Text1, Text2, Text3], fonts()["CYBER"])[2].save("aaa.png")