changes now with saving of drawings plus saved page

main
joak 2 years ago
parent 3d1950f4f1
commit c9196d9afe

@ -8,19 +8,26 @@ APP = Flask(__name__)
@APP.route('/2ndpage', methods=['GET', 'POST']) @APP.route('/2ndpage', methods=['GET', 'POST'])
def drawPlz(): def drawPlz():
title = "Lost Stories" 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': if request.method == 'POST':
args =request.args print("hello")
print(args.get("msg"))
id = args.get("id")
image = request.form["data"] image = request.form["data"]
print(image) 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 }") 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) 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']) @APP.route('/', methods=['GET', 'POST'])
def index(): def index():
@ -36,14 +43,6 @@ def index():
text = request.form.get('text', 'haha') text = request.form.get('text', 'haha')
print(text) 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: with open('database/'+ str(id) +'.txt', 'w') as db:
db.write(f"{ name } \n{ text } \n") db.write(f"{ name } \n{ text } \n")

@ -95,10 +95,12 @@ var updateSvgPath = function () {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
function sender(){ 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"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
someStuff=document.getElementById("svgElement").innerHTML; someStuff=document.getElementById("svgElement").innerHTML;
xhr.send("data="+someStuff); xhr.send("data="+someStuff);
console.log(someStuff); console.log(someStuff);
console.log("I'm sending"); console.log("I'm sending");
window.location.replace("/saver")
} }

@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block content %}
<h1>SAVED</h1>
{% endblock %}
Loading…
Cancel
Save