Some Bug fixes, block 3 TaskTemplate can now be displayed

This commit is contained in:
Jan 2024-05-30 13:01:51 +02:00
parent e22b1c0737
commit 6e6868e230
3 changed files with 52 additions and 61 deletions

View File

@ -170,10 +170,11 @@ def teststartpage():
session["current_stimulus_index"] = 0 session["current_stimulus_index"] = 0
session["current_block_name"] = session["block_names"][session["current_block_index"]] session["current_block_name"] = session["block_names"][session["current_block_index"]]
session["number_of_blocks"] = len(session["block_names"]) session["number_of_blocks"] = len(session["block_names"])
current_block = config[session["current_block_name"]]
# if the block has stimuli, get how many # if the block has stimuli, get how many
if "stimuli" in config[session["current_block_name"]]: if "stimuli" in current_block:
session["number_of_stimuli"] = len(list(config[session["current_block_name"]]["list"])) session["number_of_stimuli"] = len(list(current_block["stimuli"]["list"]))
print("number of blocks: ",len(session["block_names"])) print("number of blocks: ",len(session["block_names"]))
@ -182,11 +183,12 @@ def teststartpage():
for name in block_names: for name in block_names:
if config[name]["type"] == "TaskTemplate": if config[name]["type"] == "TaskTemplate":
match config[name]["stimulus"]["type"]: match config[name]["stimuli"]["type"]:
case "single_video": case "single_video":
order = list(config[name]["stimulus"]["list"]) # order = list of simuli keys order = list(config[name]["stimuli"]["list"]) # order = list of simuli keys
if config[name]["stimulus"]["order"] == "random": print("order: ",order)
random.shuffle(order[name]) #in random order if config[name]["stimuli"]["order"] == "random":
random.shuffle(order) #in random order
session["block_order"][name] = order session["block_order"][name] = order
#save the new user to the database and the session #save the new user to the database and the session
@ -240,19 +242,19 @@ def jsonform():
# ansonsten, templates: # ansonsten, templates:
current_block_order = session["block_order"][current_block] current_block_order = session["block_order"][session["current_block_name"]]
current_block_stimuli = config[current_block]["stimuli"] current_block_stimuli = current_block["stimuli"]
current_stimulus = current_block_order[0] current_stimulus = current_block_order[session["current_stimulus_index"]]
stimulus_type=current_stimulus["type"] stimulus_type=current_block["stimuli"]["type"]
stimulus_configuration = config[current_block]["stimulus"]["configuration"] stimulus_configuration = current_block["stimuli"]["configuration"] # dict with the config
if current_block[type] == "TaskTemplate": if current_block["type"] == "TaskTemplate":
print("case: TaskTemplate") print("case: TaskTemplate")
match stimulus_type: match stimulus_type:
case "single_video": case "single_video":
stimulus_configuration["video_url"] = config[current_block]["stimuli"]["list"] stimulus_configuration["video_url"] = config[session["current_block_name"]]["stimuli"]["list"][current_stimulus]
print("-------------videourl: ", stimulus_configuration["video_url"])
return render_template( return render_template(
"standard_template.html", "standard_template.html",
stimuli=current_block_stimuli, stimuli=current_block_stimuli,

View File

@ -1,4 +1,21 @@
{ {
"Block 3":{
"type": "TaskTemplate",
"tempalte": "standard_template.html",
"number_of_pages":"3",
"stimuli":{
"type":"single_video",
"order": "random",
"list":{
"video_1":"https://www.youtube-nocookie.com/embed/VtnwHmabyzo?si=H3rrG-GHtlSymR70",
"video_2":"https://www.youtube-nocookie.com/embed/EL76Ok4r0aQ?si=hqUm8eUUfX39NN4L",
"video_3":"https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6"
},
"configuration":{
"embed":"yt"
}
}
},
"Block_1":{ "Block_1":{
"type": "SinglePage", "type": "SinglePage",
"template": "test_page0.html" "template": "test_page0.html"
@ -16,32 +33,5 @@
} }
} }
} }
},
"Block 3":{
"type": "TaskTemplate",
"tempalte": "tempaltetest1.html",
"number_of_pages":"3",
"stimuli":{
"type":"single_video",
"order": "random",
"list":{
"video_1":"https://www.youtube-nocookie.com/embed/VtnwHmabyzo?si=H3rrG-GHtlSymR70",
"video_2":"https://www.youtube-nocookie.com/embed/EL76Ok4r0aQ?si=hqUm8eUUfX39NN4L",
"video_3":"https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6"
},
"configuration":{
"embed":"yt"
}
},
"database_table" :{
"table_name": "tempaltetest1_responses",
"fields": {
"accepted":{
"type": "string",
"size": "7",
"nullable": "false"
}
}
}
} }
} }

View File

@ -1,6 +1,25 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
{% macro single_video(video_url, embed="yt", title="",width="560", height="315", class="center", code="<p>No code given</p>") -%}
{% if (embed == "yt") %}
<div class={{center}}>
{% if (title != "") %}
<h3>{{title}}</h3>
{% endif %}
<iframe width={{width}} height={{height}} 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>
{% else %}
{{code}}
{% endif %}
{%- endmacro %}
{% macro input(name, value='', type='text', size=20) -%}
<input type="{{ type }}" name="{{ name }}" value="{{
value|e }}" size="{{ size }}">
{%- endmacro %}
<head> <head>
<meta charset="utf-8" /> <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')}}--> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" /> <!-- styles.css {{ url_for('static', filename='styles.css')}}-->
@ -37,23 +56,3 @@
</body> </body>
</html> </html>
{% macro single_video(video_url, embed="yt", title="",width="560", height="315", class="center", code=<p>No code given</p>) -%}
{% if (embed == "yt") %}
<div class={{center}}>
{% if (title != "") %}
<h3>{{title}}</h3>
{% endif %}
<iframe width={{width}} height={{height}} 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>
{% else %}
{{code}}
{% endif %}
{%- endmacro %}
{% macro input(name, value='', type='text', size=20) -%}
<input type="{{ type }}" name="{{ name }}" value="{{
value|e }}" size="{{ size }}">
{%- endmacro %}