more cleanup and deleting unnecessary code
This commit is contained in:
parent
c9c3bfce12
commit
23c05823ac
154
slaeforms/app.py
154
slaeforms/app.py
@ -108,7 +108,6 @@ def create_json_tables():
|
||||
print(config)
|
||||
for block_key, block_content in config.items():
|
||||
if "database_table" in block_content:
|
||||
print("debug")
|
||||
if not (block_content["database_table"]["table_name"] in db_tables):
|
||||
print("New table: \n {table}".format(table=block_content["database_table"]["table_name"]))
|
||||
db_tables[block_content["database_table"]["table_name"]]=create_model_class(block_content["database_table"])
|
||||
@ -125,7 +124,7 @@ def create_model_class(schema):
|
||||
|
||||
# id as key and date as standard fields
|
||||
attributes["id"] = Column("id",db.UUID(as_uuid=True), primary_key=True, nullable=False)
|
||||
attributes["user_id"] = Column("user_id",db.UUID(as_uuid=True), primary_key=True, nullable=False)
|
||||
attributes["user_id"] = Column("user_id",db.UUID(as_uuid=True), nullable=False)
|
||||
attributes["date_created"] = db.Column("date_created",db.DateTime)
|
||||
attributes["stimulus_name"] = db.Column("stimulus_name",db.String(30))
|
||||
|
||||
@ -156,8 +155,8 @@ try:
|
||||
except SQLAlchemyError as e:
|
||||
print("Error occurred during database creation:", str(e))
|
||||
|
||||
@app.route("/teststart", methods=["GET", "POST"])
|
||||
def teststartpage():
|
||||
@app.route("/start", methods=["GET", "POST"])
|
||||
def startpage():
|
||||
session.permanent = False
|
||||
if not "slaeform_device_id" in session:
|
||||
# If this device was not seen, remember it.
|
||||
@ -242,22 +241,22 @@ def teststartpage():
|
||||
|
||||
except:
|
||||
return "There was a problem while adding the user to the Database"
|
||||
return redirect("/jsonform")
|
||||
return redirect("/form")
|
||||
|
||||
return render_template(
|
||||
"teststartpage.html"
|
||||
)
|
||||
|
||||
|
||||
@app.route("/jsonform")
|
||||
def jsonform():
|
||||
@app.route("/form")
|
||||
def form():
|
||||
#user is not yet registered and should not be here
|
||||
if not "slaeform_user_id" in session:
|
||||
return redirect("/teststart") #TODO replace this later with actual startpage
|
||||
return redirect("/start") #TODO replace this later with actual startpage
|
||||
|
||||
|
||||
current_block = config[session["current_block_name"]]
|
||||
print("jsonform")
|
||||
print("form")
|
||||
print("current_block_name: {current_block_name}".format(current_block_name=session["current_block_name"]))
|
||||
print("current_block_index: {current_block_order}".format(current_block_order=session["current_block_index"]))
|
||||
print("current_stimulus: {current_stimulus}".format(current_stimulus=session["current_stimulus_index"]))
|
||||
@ -319,16 +318,16 @@ def jsonform():
|
||||
return "Error, none of the Blocks triggered"
|
||||
|
||||
|
||||
@app.route("/send_json", methods=["POST"])
|
||||
def sendpage_json():
|
||||
print("send_json")
|
||||
@app.route("/send", methods=["POST"])
|
||||
def sendpage():
|
||||
print("send")
|
||||
# Do I need to write to a table at all?
|
||||
# I can figure it out by checking if the current block has a database field, that is best
|
||||
if not ("database_table" in config[session["current_block_name"]]): #it has no database field, so nothing to receive
|
||||
# so just move on
|
||||
print("no database table")
|
||||
update_session()
|
||||
return redirect("/jsonform")
|
||||
return redirect("/form")
|
||||
|
||||
# now to if it has a database field
|
||||
|
||||
@ -372,7 +371,7 @@ def sendpage_json():
|
||||
# Now move to the next stimulus or block
|
||||
update_session()
|
||||
print("now redirect and reload the page")
|
||||
return redirect("/jsonform")
|
||||
return redirect("/form")
|
||||
|
||||
def update_session():
|
||||
if "stimuli" in config[session["current_block_name"]]:
|
||||
@ -409,133 +408,6 @@ def update_session():
|
||||
print("current_block_name: ", session["current_block_name"])
|
||||
print("current_stimulus_index: ", session["current_stimulus_index"])
|
||||
print("Current number_of_stimuli: ", session["number_of_stimuli"])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Actual main code for Form etc --------------------------------------------------------------
|
||||
|
||||
@app.route("/video")
|
||||
def videopage():
|
||||
|
||||
return render_template(
|
||||
#"videorecorder3.html"
|
||||
"myvideotemplate.html"
|
||||
)
|
||||
|
||||
@app.route("/send_video", methods=["POST"])
|
||||
def send_video():
|
||||
data_url = request.json['dataUrl']
|
||||
data = data_url.split(',')[1]
|
||||
with open('video.webm', 'wb') as f:
|
||||
f.write(base64.b64decode(data))
|
||||
return jsonify({'message': 'Video saved successfully'})
|
||||
|
||||
|
||||
|
||||
@app.route("/send", methods=["POST"])
|
||||
def sendpage():
|
||||
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"
|
||||
|
||||
|
||||
#TODO this is bugged rn, it will skip to the next question when refreshed.
|
||||
#Move the removal of the first element to the send function to fix this
|
||||
@app.route("/form", methods=["GET", "POST"])
|
||||
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"])
|
||||
|
||||
return render_template(
|
||||
"layout2.html",
|
||||
config=testconfig,
|
||||
current_question = current_question,
|
||||
videotype=testconfig[current_question]["type"],
|
||||
video_url= testconfig[current_question]["video1"],
|
||||
blocks = testconfig[current_question]["blocks"]
|
||||
)
|
||||
|
||||
|
||||
@app.route("/start", methods=["GET", "POST"])
|
||||
def startpage():
|
||||
if not "slaeform_device_id" in session:
|
||||
# If this device was not seen, remember it.
|
||||
new_device_id = uuid.uuid4()
|
||||
session["slaeform_device_id"] = new_device_id
|
||||
session["agreed_to_tos"] = False
|
||||
|
||||
if request.method == "POST":
|
||||
#right now if a user that has an active session goes to the startpage again and accepts tos
|
||||
#it will just start another session and discard the previous session
|
||||
|
||||
# get a random question order
|
||||
if random_order:
|
||||
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 = new_user_id
|
||||
question_order = str(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)
|
||||
db.session.commit()
|
||||
return redirect("/form")
|
||||
except:
|
||||
return "There was a problem while adding the user to the Database" """
|
||||
|
||||
return render_template(
|
||||
"startpage.html"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ document.getElementById("question_form").addEventListener("submit", function (ev
|
||||
|
||||
// Use fetch to send the form data and video to the backend
|
||||
console.log("try to send the form and video");
|
||||
fetch("/send_json", {
|
||||
fetch("/send", {
|
||||
method: "POST",
|
||||
body: formData
|
||||
}).then(response => {
|
||||
|
@ -102,7 +102,7 @@ step={{question["step"]}}
|
||||
<p>Error: Block {{ stimulus["type"] }} could not be loaded!</p>
|
||||
{% endif %}
|
||||
|
||||
<form class="formlayout" id="question_form" action="http://localhost:5000/send_json" method="post">
|
||||
<form class="formlayout" id="question_form" action="http://localhost:5000/send" method="post">
|
||||
|
||||
{% for question in questions %}
|
||||
{% if (questions[question]["type"] == "likert") %}
|
||||
|
@ -19,7 +19,7 @@
|
||||
If you have further questions, please send an email to testemail@notarealemail.deee
|
||||
</p>
|
||||
</div>
|
||||
<form class="dsgvoform" action="http://localhost:5000/teststart" method="post">
|
||||
<form class="dsgvoform" action="http://localhost:5000/start" method="post">
|
||||
<label for="terms-and-conditions">
|
||||
<input class="inline" id="terms-and-conditions" type="checkbox" required name="terms-and-conditions" /> I accept the +terms and conditions
|
||||
</label>
|
||||
|
Loading…
Reference in New Issue
Block a user