From c9196d9afe7c2e99a01ad9f167f9b8c7a69a5d03 Mon Sep 17 00:00:00 2001 From: joak Date: Tue, 7 Feb 2023 18:03:54 +0100 Subject: [PATCH] changes now with saving of drawings plus saved page --- app.py | 29 ++++++++++++++--------------- static/main.js | 4 +++- templates/saver.html | 6 ++++++ 3 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 templates/saver.html diff --git a/app.py b/app.py index 2477350..d49ad10 100644 --- a/app.py +++ b/app.py @@ -8,18 +8,25 @@ APP = Flask(__name__) @APP.route('/2ndpage', methods=['GET', 'POST']) def drawPlz(): title = "Lost Stories" - - name = request.form.get('lostobject') - msg = "Sorry that you lost {name}. But {name} will be having fun somewhere." if request.method == 'POST': - args =request.args - print(args.get("msg")) - id = args.get("id") + print("hello") image = request.form["data"] print(image) - with open('database/'+ str(id) +'.txt', 'a+') as db: + idi = request.args.get('id') + print(idi) + with open('database/'+ str(idi) +'.txt', 'a+') as db: db.write(f"{ image }") + return redirect(url_for('saver')) + name = request.form.get('lostobject') + msg = "Sorry that you lost {name}. But {name} will be having fun somewhere." return render_template("drawing.html", title=title, msg=msg) + + +@APP.route('/saver', methods=['GET', 'POST']) +def saver(): + return render_template("saver.html") + + @APP.route('/', methods=['GET', 'POST']) def index(): @@ -36,14 +43,6 @@ def index(): text = request.form.get('text', 'haha') print(text) - # date = request.form['dd-mm-yyyy'] Q.How can I include date? Or maybe general date input? Sometimes ppl do remember when they lose sth. and somethimes they do not know. - - # Write the submitted data to a file, which is - # in this case a "csv" (comma seperated values) file - # that you can also open with spreadsheet software. - # Note that the file is opened in the mode "a+" - # which means that the Flask application will append values - # (and not overwrite the csv file). with open('database/'+ str(id) +'.txt', 'w') as db: db.write(f"{ name } \n{ text } \n") diff --git a/static/main.js b/static/main.js index 36c35e3..e0c7834 100644 --- a/static/main.js +++ b/static/main.js @@ -95,10 +95,12 @@ var updateSvgPath = function () { var xhr = new XMLHttpRequest(); function sender(){ - xhr.open("POST", "/2ndpage", true); + const queryString = window.location.search; + xhr.open("POST", "/2ndpage"+queryString, true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); someStuff=document.getElementById("svgElement").innerHTML; xhr.send("data="+someStuff); console.log(someStuff); console.log("I'm sending"); + window.location.replace("/saver") } diff --git a/templates/saver.html b/templates/saver.html new file mode 100644 index 0000000..6b1ecc8 --- /dev/null +++ b/templates/saver.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} +{% block content %} + +

SAVED

+ +{% endblock %}