From dfa7156b9fced5622647b16ce645eae90f9f8688 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 25 Apr 2024 16:51:08 +0200 Subject: [PATCH] some testing prep, but probably obsolete --- slaeforms/app.py | 50 +++++++++++++++++++++-- slaeforms/dbtables.py | 12 ++++++ slaeforms/test.json | 92 +++++-------------------------------------- 3 files changed, 69 insertions(+), 85 deletions(-) create mode 100644 slaeforms/dbtables.py diff --git a/slaeforms/app.py b/slaeforms/app.py index d90615e..b3f9ee0 100644 --- a/slaeforms/app.py +++ b/slaeforms/app.py @@ -12,6 +12,9 @@ from sqlalchemy.dialects.postgresql import UUID from datetime import datetime import uuid +# get all dbtables that the user created +from dbtables import * + random_order = True # activate environment: cd C:\Users\Jan\Google Drive\Master Stuff\Code\SLAEForms Testing\.venv\Scripts\ @@ -33,9 +36,17 @@ config = json.load(configfile) config2 = json.load(configfile2) configfile.close() configfile2.close() -# get the questions: +# get the questions: Questions is a list that contains the keys of the dictionary questions = list(config) +# JSON TEST------------------------------------------- +configtest = open("test.json") +config = json.load(configtest) #convert json to dict +configtest.close() +blocks = list(config) # get the block names, aka a list of all keys + + + # create the model for the response table class Response(db.Model): id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False) @@ -47,8 +58,8 @@ class Response(db.Model): def __repr__(self) -> str: return "" % self.id - -class User(db.Model): +# This table is created always +class User(db.Model): user_id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False) device_id = db.Column(db.UUID(as_uuid=True), nullable=False) question_order = db.Column(db.String(60)) @@ -61,6 +72,39 @@ with app.app_context(): db.create_all() +@app.route("/customsend/", methods=["POST"]) +def customsend(): + + + + + + + session_user_id = session["slaeform_user_id"] + likert_score = request.form["likertscale"] + text_input = request.form["feedback"] + question_title = session["current_question"] + new_id = uuid.uuid4() + date = datetime.today() + print("new idea: {new_id} ".format(new_id=new_id)) + new_response = Response(id=new_id,user_id = session_user_id, question_title = question_title,likert_result = likert_score,notes = text_input, date_created = date) + + try: + db.session.add(new_response) + db.session.commit() + return redirect("/form") + except: + return "There was a problem while adding the response to the Database" + +@app.route("/custom") +def custom(): + + + + return render_template( + "templatetest1.html" + ) + @app.route("/video", methods=["GET", "POST"]) def videopage(): diff --git a/slaeforms/dbtables.py b/slaeforms/dbtables.py new file mode 100644 index 0000000..e81fd66 --- /dev/null +++ b/slaeforms/dbtables.py @@ -0,0 +1,12 @@ + +from app import db + +class Response(db.Model): + id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False) + user_id = db.Column(db.UUID(as_uuid=True), nullable=False) + question_title = db.Column(db.String(30)) + likert_result = db.Column(db.Integer, nullable=False) + notes = db.Column(db.String(200)) + date_created = db.Column(db.DateTime) + def __repr__(self) -> str: + return "" % self.id \ No newline at end of file diff --git a/slaeforms/test.json b/slaeforms/test.json index 04a0449..434224f 100644 --- a/slaeforms/test.json +++ b/slaeforms/test.json @@ -1,87 +1,15 @@ { - "question 1":{ - "type": "single", - "video1": "https://www.youtube-nocookie.com/embed/VtnwHmabyzo?si=H3rrG-GHtlSymR70", - "blocks": { - "block1":{ - "type": "likert", - "numberofpoints": "5", - "points":{ - "point1": "1", - "point2": "2", - "point3": "3", - "point4": "4", - "point5": "5" - } - }, - "block2":{ - "type": "likert", - "numberofpoints": "5", - "points":{ - "point1": "1", - "point2": "2", - "point3": "3", - "point4": "4", - "point5": "5" - } - }, - "block3":{ - "type": "textinput", - "length": "200" - }, - "block4":{ - "type": "likert", - "numberofpoints": "5", - "points":{ - "point1": "1", - "point2": "2", - "point3": "3", - "point4": "4", - "point5": "5" - } - } - } + "Block 1":{ + "type": "SinglePage", + "template": "startpage.html" }, - "question 2":{ - "type": "single", - "video1": "https://www.youtube-nocookie.com/embed/EL76Ok4r0aQ?si=hqUm8eUUfX39NN4L", - "blocks": { - "block1":{ - "type": "likert", - "numberofpoints": "5", - "points":{ - "point1": "1", - "point2": "2", - "point3": "3", - "point4": "4", - "point5": "5" - } - }, - "block2":{ - "type": "likert", - "numberofpoints": "5", - "points":{ - "point1": "1", - "point2": "2", - "point3": "3", - "point4": "4", - "point5": "5" - } - }, - "block3":{ - "type": "textinput", - "length": "200" - }, - "block4":{ - "type": "likert", - "numberofpoints": "5", - "points":{ - "point1": "1", - "point2": "2", - "point3": "3", - "point4": "4", - "point5": "5" - } + "Block 2":{ + "type": "TaskTemplate", + "tempalte": "tempaltetest1.html", + "name" : "Block2Responses" + "databasetable": { + "question_title" : { + "type:" } } },