Can create forms from json now, but not final

This commit is contained in:
Jan 2024-03-22 16:23:53 +01:00
parent 955726bae0
commit 3959bd6295
8 changed files with 6154 additions and 18 deletions

View File

@ -1,4 +1,5 @@
import sys
import json
from flask import Flask, redirect, url_for, request, session, make_response
from flask import render_template
from flask_sqlalchemy import SQLAlchemy
@ -16,13 +17,26 @@ db = SQLAlchemy(app)
#set the secret key (TODO change this for final deployment)
app.secret_key = b"29fe9e8edd407c5491d4f1c05632d9fa33e26ed8734a3f5e080ebac3772a555a"
#open the json file with the config
configfile = open("singleformconfig.json")
configfile2 = open("pairwiseformconfig.json")
#convert it to dict
config = json.load(configfile)
config2 = json.load(configfile2)
configfile.close()
configfile2.close()
print(config["question 1"])
print("\n")
print(config["question 1"]["type"])
print("\n")
# 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))
likert_result = db.Column(db.Integer, nullable=False)
notes = db.Column(db.String(200))
date_created = db.Column(db.DateTime, default=datetime.today())
def __repr__(self) -> str:
return "<Task %r>" % self.id
@ -31,26 +45,40 @@ with app.app_context():
db.create_all()
print("Table created")
print(config["question 1"]["blocks"])
print(config["question 1"]["blocks"].keys())
@app.route("/form", methods=["GET", "POST"]) # /<username> should not even be needed right?
def formpage():
#TODO fill in code that determins at which question the user is
return render_template(
"layout2.html",
config=config,
videotype=config["question 1"]["type"],
video_url= config["question 1"]["video1"],
blocks = config["question 1"]["blocks"]
)
#just testing
@app.route("/", methods=["GET", "POST"])
def testpage():
user_cookie = request.cookies.get('sleaformcookie')
if user_cookie:
# If the cookie exists
return f'Hello, returning user! Your cookie value is {user_cookie}'
else:
if not "slaeform_user_id" in session:
# If the cookie doesn't exist
response = make_response('Hello, new user! Setting cookie...')
print('Hello, new user! Setting cookie...')
user_id = str(uuid.uuid4())
print('Setting cookie with your user id: {user_id}'.format(user_id=user_id))
response.set_cookie('sleaformcookie', user_id)
return response
new_user_id = str(uuid.uuid4())
session["slaeform_user_id"] = new_user_id
if request.method == "POST":
session_user_id = session["slaeform_user_id"]
likert_score = request.form["likertscale"]
text_input = request.form["feedback"]
print("new response: {likert_score_1} {text_input_1}".format(likert_score_1 = likert_score, text_input_1 = text_input))
new_response = Response(likert_result = likert_score, notes = text_input)
print("new response: {session_user_id} {likert_score_1} {text_input_1}".format(session_user_id = session_user_id, likert_score_1 = likert_score, text_input_1 = text_input))
new_response = Response(session_user_id = session_user_id,likert_result = likert_score, notes = text_input)
try:
db.session.add(new_response)
@ -70,3 +98,26 @@ def datapage():
"data.html",
responses = responses
)
# Route to delete all entries
@app.route('/delete_all_entries', methods=['GET'])
def delete_all_entries():
try:
# Query all entries
entries = Response.query.all()
# Delete each entry
for entry in entries:
db.session.delete(entry)
# Commit changes
db.session.commit()
return 'All entries deleted successfully'
except Exception as e:
# Rollback changes if any error occurs
db.session.rollback()
return f'Error occurred: {str(e)}', 500
finally:
# Close the session
db.session.close()

4688
slaeforms/gruene css Normal file

File diff suppressed because it is too large Load Diff

1210
slaeforms/gruene.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,17 @@
{
"question 1":{
"type": "pairwise",
"video1": "https://www.youtube-nocookie.com/embed/VtnwHmabyzo?si=H3rrG-GHtlSymR70",
"video2": "https://www.youtube-nocookie.com/embed/PdvSPBdX2T0?si=8R2ZAMnPuoe50X-7"
},
"question 2":{
"type": "pairwise",
"video1": "https://www.youtube-nocookie.com/embed/EL76Ok4r0aQ?si=hqUm8eUUfX39NN4L",
"video2": "https://www.youtube-nocookie.com/embed/xIkdJeXkQIU?si=7a5WmlVtZy00JaNX"
},
"question 3":{
"type": "pairwise",
"video1": "https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6",
"video2": "https://www.youtube-nocookie.com/embed/keEKlr2dG-I?si=NZ4Q-aL56d3baz0t"
}
}

View File

@ -0,0 +1,110 @@
{
"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"
}
}
}
},
"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"
}
}
}
},
"question 3":{
"type": "single",
"video1": "https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6",
"scales": {
"block1":{
"type": "likert",
"numberofpoints": "3",
"points":{
"point1": "left",
"point2": "none",
"point3": "right"
}
},
"block2":{
"type": "textinput",
"length": "200"
},
"block3":{
"type": "video"
}
}
}
}

View File

@ -10,10 +10,9 @@
<body>
<h2>Task number 1 responses</h2>
{% for response in responses%}
<p>Likert score:</p>
{{response.likert_result}}
<p>Feedback:</p>
{{response.notes}}
<p>Likert score: {{response.likert_result}}</p>
<p>Feedback: {{response.notes}}</p>
<p>session_user_id: {{response.session_user_id}}</p>
<p>-------------------------------------------------------------------------</p>
{% endfor %}
</body>

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" /> <!-- styles.css {{ url_for('static', filename='styles.css')}}-->
<title>Testform</title>
</head>
<body>
<h2>Task number 1</h2>
{% if (videotype == "single")%} <!-- first figure out what video type we have -->
<div class="center">
<h3>Video 1</h3>
<iframe width="560" height="315" class="center" src="{{ video_url }}" title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></iframe>
</div>
{% elif (videotype == "pairwise")%}
<div class="columncontainer">
<div class="columnleft center">
<h3>Video 1</h3>
<iframe width="560" height="315" class="center" src="{{ video_url_left }}" title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></iframe>
</div>
<div class="columnright">
<h3>Video 2</h3>
<iframe width="560" height="315" src="{{ video_url_right }}" title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></iframe>
</div>
</div>
{% else %}
<p>Error: No Videotype could be matched or was given!</p>
{% endif %}
<form action="http://localhost:5000/{{ user_id }}" method="post"></form>
{% for block in config["question 1"]["blocks"] %}
{% if (config["question 1"]["blocks"][block]["type"] == "likert") %}
<div class="likercontainer">
<div class="likert">
<label><input name="likertscale" type="radio" value="1" /><span>I dont like it at all</span></label>
<label><input name="likertscale" type="radio" value="2" /><span>I dont like it</span></label>
<label><input name="likertscale" type="radio" value="3" /><span>I am indifferent</span></label>
<label><input name="likertscale" type="radio" value="4" /><span>I like it</span></label>
<label><input name="likertscale" type="radio" value="5" /><span>I like it a lot</span></label>
</div>
</div>
{% elif (config["question 1"]["blocks"][block]["type"] == "textinput") %}
<label for="feedback">Additional Feedback: </label>
<textarea id="feedback" name="feedback" rows="3" cols="30" maxlength="200"></textarea>
{% else %}
<p>Error: A block could not be loaded!</p>
{% endif %}
{% endfor %}
</body>
</html>

View File