diff --git a/slaeforms/app.py b/slaeforms/app.py index 8d02c11..0bf2e2a 100644 --- a/slaeforms/app.py +++ b/slaeforms/app.py @@ -32,21 +32,21 @@ configfile2.close() # get the questions: questions = list(config) - # create the model for the response table class Response(db.Model): - id = db.Column(db.Integer, primary_key=True) - session_user_id = db.Column(db.String(36)) + 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, default=datetime.today()) + date_created = db.Column(db.DateTime) def __repr__(self) -> str: return "" % self.id class User(db.Model): user_id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False) - device_id = db.Column(UUID(as_uuid=True), primary_key=True) + device_id = db.Column(db.UUID(as_uuid=True), nullable=False) question_order = db.Column(db.String(60)) date_created = db.Column(db.DateTime, default=datetime.today()) def __repr__(self) -> str: @@ -56,22 +56,58 @@ class User(db.Model): with app.app_context(): db.create_all() - +@app.route("/send", methods=["GET", "POST"]) +def sendpage(): + if request.method == "POST": + 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") #url_for("datapage") + #except: + #return "There was a problem while adding the response to the Database" @app.route("/form", methods=["GET", "POST"]) # / should not even be needed right? def formpage(): #user is not yet registered and should not be here if not "slaeform_user_id" in session: return redirect("/start") + #TODO fill in code that determins at which question the user is + print("form starts, the sessionorder rn:") + print(session["question_order"]) + if not session["question_order"]: + print("---------------question order is empty------------") + return redirect("/data") + + print("pop the first element") + current_question = session["question_order"].pop(0) + session["current_question"] = current_question + print(current_question) + print("the new sessionorder rn:") + print(session["question_order"]) + session["question_order"] = session["question_order"] + print("has this changed sth?:") + print(session["question_order"]) + + return render_template( "layout2.html", config=config, - videotype=config["question 1"]["type"], - video_url= config["question 1"]["video1"], - blocks = config["question 1"]["blocks"] + current_question = current_question, + videotype=config[current_question]["type"], + video_url= config[current_question]["video1"], + blocks = config[current_question]["blocks"] ) @@ -91,28 +127,33 @@ def startpage(): # get a random question order if random_order: - order = random.shuffle(questions) + order = questions + random.shuffle(order) else: order = questions - + session["question_order"] = order + #save the new user to the database and the session session["agreed_to_tos"] = True new_user_id = uuid.uuid4() session["slaeform_user_id"] = new_user_id device_id = session["slaeform_device_id"] - user_id = session["slaeform_user_id"] + user_id = new_user_id question_order = str(order) - new_user = User(user_id=user_id, device_id=device_id, question_order=question_order) + date = datetime.today() + new_user = User(user_id=user_id, device_id=device_id,question_order=question_order,date_created = date) #,question_order=question_order + db.session.add(new_user) + db.session.commit() + return redirect("/form") + """ try: db.session.add(new_user) - print("add was ok") db.session.commit() - print("commit was ok") return redirect("/form") except: - return "There was a problem while adding the user to the Database" + return "There was a problem while adding the user to the Database" """ return render_template( "startpage.html" @@ -138,10 +179,14 @@ def delete_all_entries(): try: # Query all entries entries = Response.query.all() + entries2 = User.query.all() # Delete each entry for entry in entries: db.session.delete(entry) + + for entry in entries2: + db.session.delete(entry) # Commit changes db.session.commit() diff --git a/slaeforms/singleformconfig.json b/slaeforms/singleformconfig.json index 539fa33..00ab628 100644 --- a/slaeforms/singleformconfig.json +++ b/slaeforms/singleformconfig.json @@ -44,7 +44,7 @@ "question 3":{ "type": "single", "video1": "https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6", - "scales": { + "blocks": { "block1":{ "type": "likert", "numberofpoints": "3", diff --git a/slaeforms/templates/data.html b/slaeforms/templates/data.html index 4700d38..12014f4 100644 --- a/slaeforms/templates/data.html +++ b/slaeforms/templates/data.html @@ -17,8 +17,9 @@ {% endfor %}

Responses

{% for response in responses%} -

user_id: {{response.id}}

-

session_user_id: {{response.session_user_id}}

+

id: {{response.id}}

+

question_title: {{response.question_title}}

+

user_id: {{response.user_id}}

Likert score: {{response.likert_result}}

Feedback: {{response.notes}}

time: {{response.date_created}}

diff --git a/slaeforms/templates/layout2.html b/slaeforms/templates/layout2.html index 6e5b02c..af65cb0 100644 --- a/slaeforms/templates/layout2.html +++ b/slaeforms/templates/layout2.html @@ -8,7 +8,7 @@ -

Task number 1

+

Question: {{ current_question }}

{% if (videotype == "single")%}

Video 1

@@ -37,7 +37,7 @@ {% else %}

Error: No Videotype could be matched or was given!

{% endif %} -
+ {% for block in config["question 1"]["blocks"] %} {% if (config["question 1"]["blocks"][block]["type"] == "likert") %}