There will be a short maintenance break on Wed 27.10. at 12:00. Estimated time 30 minutes.

Commit 5bc65185 authored by Ossi Laine's avatar Ossi Laine
Browse files

Cleaning codebase, removed unnecessary migrations folder

parent ef9a7efa
......@@ -29,9 +29,10 @@ from app.forms import (
create_blueprint = Blueprint("create", __name__,
template_folder='templates',
#static_folder='static',
# static_folder='static',
url_prefix='/create')
@create_blueprint.route('/experiment', methods=['GET', 'POST'])
@login_required
def create_experiment():
......@@ -43,24 +44,12 @@ def create_experiment():
the_time = datetime.now()
the_time = the_time.replace(microsecond=0)
new_exp = experiment(name=request.form['name'], instruction=request.form['instruction'], language=request.form['language'], status='Hidden', randomization='Off', single_sentence_instruction=request.form['single_sentence_instruction'], short_instruction=request.form['short_instruction'], creator_name=request.form['creator_name'], is_archived='False', creation_time=the_time, stimulus_size='7', consent_text=request.form['consent_text'], use_forced_id='Off')
new_exp = experiment(name=request.form['name'], instruction=request.form['instruction'], language=request.form['language'], status='Hidden', randomization='Off', single_sentence_instruction=request.form['single_sentence_instruction'],
short_instruction=request.form['short_instruction'], creator_name=request.form['creator_name'], is_archived='False', creation_time=the_time, stimulus_size='7', consent_text=request.form['consent_text'], use_forced_id='Off')
db.session.add(new_exp)
db.session.commit()
exp_id = new_exp.idexperiment
#data = request.form.to_dict()
#for key, value in data.items():
#tähän db insertit
#flash(key)
#flash(value)
#flash('{}'.format(form.name.data))
#Input registration page answers to database
# participant_background_question_answers = background_question_answer(answer_set_idanswer_set=session['answer_set'], answer=value, background_question_idbackground_question=key)
# db.session.add(participant_background_question_answers)
# db.session.commit()
return redirect(url_for('create.experiment_bgquestions', exp_id=exp_id))
return render_template('create_experiment.html', form=form)
......@@ -76,25 +65,27 @@ def experiment_bgquestions():
if request.method == 'POST' and form.validate():
str = form.bg_questions_and_options.data
#Split the form data into a list that separates questions followed by the corresponding options
# Split the form data into a list that separates questions followed by the corresponding options
str_list = str.split('/n')
#Iterate through the questions and options list
# Iterate through the questions and options list
for a in range(len(str_list)):
#Split the list cells further into questions and options
# Split the list cells further into questions and options
list = str_list[a].split(';')
#Input the first item of the list as a question in db and the items followed by that as options for that question
# Input the first item of the list as a question in db and the items followed by that as options for that question
for x in range(len(list)):
if x == 0:
add_bgquestion = background_question(background_question=list[x], experiment_idexperiment=exp_id)
add_bgquestion = background_question(
background_question=list[x], experiment_idexperiment=exp_id)
db.session.add(add_bgquestion)
db.session.commit()
else:
add_bgq_option = background_question_option(background_question_idbackground_question=add_bgquestion.idbackground_question, option=list[x])
add_bgq_option = background_question_option(
background_question_idbackground_question=add_bgquestion.idbackground_question, option=list[x])
db.session.add(add_bgq_option)
db.session.commit()
......@@ -120,22 +111,24 @@ def experiment_questions():
list = str_list[a].split(';')
#If there are the wrong amount of values for any of the the slider input values
#redirect back to the form
# If there are the wrong amount of values for any of the the slider input values
# redirect back to the form
if len(list) != 3:
flash("Error Each slider must have 3 parameters separated by ; Some slider has:")
flash(
"Error Each slider must have 3 parameters separated by ; Some slider has:")
flash(len(list))
return redirect(url_for('create.experiment_questions', exp_id=exp_id))
#If all the slider inputs were of length 3 items
#we can input them to db
# If all the slider inputs were of length 3 items
# we can input them to db
for a in range(len(str_list)):
list = str_list[a].split(';')
add_question = question(experiment_idexperiment=exp_id, question=list[0], left=list[1], right=list[2])
add_question = question(
experiment_idexperiment=exp_id, question=list[0], left=list[1], right=list[2])
db.session.add(add_question)
db.session.commit()
......@@ -152,21 +145,22 @@ def experiment_upload_stimuli():
if request.method == 'POST' and form.validate():
#If stimulus type is text lets parse the information and insert it to database
# If stimulus type is text lets parse the information and insert it to database
if form.type.data == 'text':
string = form.text.data
str_list = string.split('/n')
for a in range(len(str_list)):
add_text_stimulus = page(experiment_idexperiment=exp_id, type='text', text=str_list[a], media='none')
add_text_stimulus = page(
experiment_idexperiment=exp_id, type='text', text=str_list[a], media='none')
db.session.add(add_text_stimulus)
db.session.commit()
return redirect(url_for('experiment.view', exp_id=exp_id))
else:
#Upload stimuli into /static/experiment_stimuli/exp_id folder
#Create the pages for the stimuli by inserting experiment_id, stimulus type, text and names of the stimulus files (as a path to the folder)
# Upload stimuli into /static/experiment_stimuli/exp_id folder
# Create the pages for the stimuli by inserting experiment_id, stimulus type, text and names of the stimulus files (as a path to the folder)
path = 'static/experiment_stimuli/' + str(exp_id)
target = os.path.join(APP_ROOT, path)
......@@ -174,28 +168,26 @@ def experiment_upload_stimuli():
if not os.path.isdir(target):
os.mkdir(target)
#This returns a list of filenames: request.files.getlist("file")
# This returns a list of filenames: request.files.getlist("file")
for file in request.files.getlist("file"):
#save files in the correct folder
# save files in the correct folder
filename = file.filename
destination = "/".join([target, filename])
file.save(destination)
#add pages to the db
# add pages to the db
db_path = path + str('/') + str(filename)
new_page = page(experiment_idexperiment=exp_id, type=form.type.data, media=db_path)
new_page = page(experiment_idexperiment=exp_id,
type=form.type.data, media=db_path)
db.session.add(new_page)
db.session.commit()
#flash("Succes!")
# flash("Succes!")
return redirect(url_for('experiment.view', exp_id=exp_id))
return redirect(url_for('create.experiment_upload_stimuli', exp_id=exp_id))
return render_template('create_experiment_upload_stimuli.html', form=form)
# EOF
\ No newline at end of file
......@@ -731,7 +731,6 @@ def remove_embody():
# Stimuli:
@experiment_blueprint.route('/add_stimuli', methods=['GET', 'POST'])
@login_required
def add_stimuli():
......@@ -1045,13 +1044,11 @@ def remove_rows(rows):
@socketio.on('connect', namespace="/create_embody")
def start_create_embody():
print('io connected')
emit('success', {'connection': 'on'})
@socketio.on('draw', namespace="/create_embody")
def create_embody(meta):
print("draw initialized")
page = meta["page"]
embody = meta["embody"]
img_path = embody_plot.get_coordinates(page, embody)
......@@ -1061,7 +1058,6 @@ def create_embody(meta):
@socketio.on('connect', namespace="/download_csv")
def start_download_csv():
print('io connected')
emit('success', {'connection': 'Start generating CSV file'})
......
......@@ -19,19 +19,18 @@ class LoginForm(FlaskForm):
class RegisterForm(Form):
questions1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send")
class TaskForm(Form):
__name__= 'slider'
__name__ = 'slider'
categories1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send")
class StringForm(Form):
__name__= 'embody'
__name__ = 'embody'
text = StringField()
submit = SubmitField("Send")
......@@ -39,12 +38,13 @@ class StringForm(Form):
class ContinueTaskForm(FlaskForm):
participant_id = StringField('participant_id', validators=[DataRequired()])
submit = SubmitField( _l('Continue rating') )
submit = SubmitField(_l('Continue rating'))
class StartWithIdForm(FlaskForm):
participant_id = StringField('participant_id', validators=[DataRequired()])
submit = SubmitField( _l('Start rating') )
submit = SubmitField(_l('Start rating'))
class Questions(FlaskForm):
......@@ -54,7 +54,8 @@ class Questions(FlaskForm):
class Answers(FlaskForm):
background_question_idbackground_question = SelectField(coerce=int, validators=[InputRequired])
background_question_idbackground_question = SelectField(
coerce=int, validators=[InputRequired])
class BackgroundQuestionForm(Form):
......@@ -82,14 +83,16 @@ class TestForm2(Form):
questions1 = SelectField()
#Forms for editing functions
# Forms for editing functions
class CreateExperimentForm(Form):
name = StringField('Name', [validators.DataRequired()])
creator_name = StringField('Creator_name', [validators.DataRequired()])
single_sentence_instruction = StringField('Single_sentence_instruction', [validators.DataRequired()])
short_instruction = TextAreaField('Short_instruction', [validators.DataRequired()])
single_sentence_instruction = StringField(
'Single_sentence_instruction', [validators.DataRequired()])
short_instruction = TextAreaField(
'Short_instruction', [validators.DataRequired()])
instruction = TextAreaField('Instruction', [validators.DataRequired()])
consent_text = TextAreaField('Instruction', [validators.DataRequired()])
language = StringField('Language', [validators.DataRequired()])
......@@ -102,19 +105,31 @@ class EditExperimentForm(Form):
creator_name = StringField('Creator_name', [validators.DataRequired()])
instruction = TextAreaField('Instruction', [validators.DataRequired()])
consent_text = TextAreaField('Instruction', [validators.DataRequired()])
short_instruction = TextAreaField('Short_instruction', [validators.DataRequired()])
single_sentence_instruction = StringField('Single_sentece_instruction', [validators.DataRequired()])
short_instruction = TextAreaField(
'Short_instruction', [validators.DataRequired()])
single_sentence_instruction = StringField(
'Single_sentece_instruction', [validators.DataRequired()])
language = SelectField('Language', choices=[
('Afrikanns', 'Afrikanns'), ('Albanian', 'Albanian'), ('Arabic', 'Arabic'), ('Armenian', 'Armenian'), ('Basque', 'Basque'), ('Bengali', 'Bengali'), ('Bulgarian', 'Bulgarian'),
('Catalan', 'Catalan'), ('Cambodian', 'Cambodian'), ('Chinese', 'Chinese'), ('Croation', 'Croation'), ('Czech', 'Czech'), ('Danish', 'Danish'),
('Dutch', 'Dutch'), ('English', 'English'), ('Estonian', 'Estonian'), ('Fiji', 'Fiji'), ('Finnish', 'Finnish'), ('French', 'French'), ('Georgian', 'Georgian'),
('German', 'German'), ('Greek', 'Greek'), ('Gujarati', 'Gujarati'), ('Hebrew', 'Hebrew'), ('Hindi', 'Hindi'), ('Hungarian', 'Hungarian'), ('Icelandic', 'Icelandic'),
('Indonesian', 'Indonesian'), ('Irish', 'Irish'), ('Italian', 'Italian'), ('Japanese', 'Japanese'), ('Javanese', 'Javanese'), ('Korean', 'Korean'), ('Latin', 'Latin'),
('Latvian', 'Latvian'), ('Lithuanian', 'Lithuanian'), ('Macedonian', 'Macedonian'), ('Malay', 'Malay'), ('Malayalam', 'Malayalam'), ('Maltese', 'Maltese'), ('Maori', 'Maori'),
('Marathi', 'Marathi'), ('Mongolian', 'Mongolian'), ('Nepali', 'Nepali'), ('Norwegian', 'Norwegian'), ('Persian', 'Persian'), ('Polish', 'Polish'), ('Portuguese', 'Portuguese'),
('Punjabi', 'Punjabi'), ('Quechua', 'Quechua'), ('Romanian', 'Romanian'), ('Russian', 'Russian'), ('Samoan', 'Samoan'), ('Serbian', 'Serbian'), ('Slovak', 'Slovak'),
('Slovenian', 'Slovenian'), ('Spanish', 'Spanish'), ('Swahili', 'Swahili'), ('Swedish ', 'Swedish '), ('Tamil', 'Tamil'), ('Tatar', 'Tatar'), ('Telugu', 'Telugu'),
('Thai', 'Thai'), ('Tibetan', 'Tibetan'), ('Tonga', 'Tonga'), ('Turkish', 'Turkish'), ('Ukranian', 'Ukranian'), ('Urdu', 'Urdu'), ('Uzbek', 'Uzbek'), ('Vietnamese', 'Vietnamese'),
('Afrikanns', 'Afrikanns'), ('Albanian', 'Albanian'), ('Arabic', 'Arabic'), ('Armenian',
'Armenian'), ('Basque', 'Basque'), ('Bengali', 'Bengali'), ('Bulgarian', 'Bulgarian'),
('Catalan', 'Catalan'), ('Cambodian', 'Cambodian'), ('Chinese',
'Chinese'), ('Croation', 'Croation'), ('Czech', 'Czech'), ('Danish', 'Danish'),
('Dutch', 'Dutch'), ('English', 'English'), ('Estonian', 'Estonian'), ('Fiji',
'Fiji'), ('Finnish', 'Finnish'), ('French', 'French'), ('Georgian', 'Georgian'),
('German', 'German'), ('Greek', 'Greek'), ('Gujarati', 'Gujarati'), ('Hebrew',
'Hebrew'), ('Hindi', 'Hindi'), ('Hungarian', 'Hungarian'), ('Icelandic', 'Icelandic'),
('Indonesian', 'Indonesian'), ('Irish', 'Irish'), ('Italian', 'Italian'), ('Japanese',
'Japanese'), ('Javanese', 'Javanese'), ('Korean', 'Korean'), ('Latin', 'Latin'),
('Latvian', 'Latvian'), ('Lithuanian', 'Lithuanian'), ('Macedonian', 'Macedonian'), ('Malay',
'Malay'), ('Malayalam', 'Malayalam'), ('Maltese', 'Maltese'), ('Maori', 'Maori'),
('Marathi', 'Marathi'), ('Mongolian', 'Mongolian'), ('Nepali', 'Nepali'), ('Norwegian',
'Norwegian'), ('Persian', 'Persian'), ('Polish', 'Polish'), ('Portuguese', 'Portuguese'),
('Punjabi', 'Punjabi'), ('Quechua', 'Quechua'), ('Romanian', 'Romanian'), ('Russian',
'Russian'), ('Samoan', 'Samoan'), ('Serbian', 'Serbian'), ('Slovak', 'Slovak'),
('Slovenian', 'Slovenian'), ('Spanish', 'Spanish'), ('Swahili', 'Swahili'), ('Swedish ',
'Swedish '), ('Tamil', 'Tamil'), ('Tatar', 'Tatar'), ('Telugu', 'Telugu'),
('Thai', 'Thai'), ('Tibetan', 'Tibetan'), ('Tonga', 'Tonga'), ('Turkish', 'Turkish'), ('Ukranian',
'Ukranian'), ('Urdu', 'Urdu'), ('Uzbek', 'Uzbek'), ('Vietnamese', 'Vietnamese'),
('Welsh', 'Welsh'), ('Xhosa', 'Xhosa')])
stimulus_size = SelectField('Stimulus_size', choices=[
('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12')])
......@@ -124,20 +139,23 @@ class EditExperimentForm(Form):
class CreateBackgroundQuestionForm(Form):
bg_questions_and_options = TextAreaField('Background questions and options', [validators.DataRequired()])
bg_questions_and_options = TextAreaField(
'Background questions and options', [validators.DataRequired()])
submit = SubmitField('Send')
class EditBackgroundQuestionForm(Form):
bg_questions_and_options = TextAreaField('Background questions and options')
bg_questions_and_options = TextAreaField(
'Background questions and options')
new_values = TextAreaField('New values', [validators.DataRequired()])
submit = SubmitField('Send')
class CreateQuestionForm(Form):
questions_and_options = TextAreaField('Questions and options', [validators.DataRequired()])
questions_and_options = TextAreaField(
'Questions and options', [validators.DataRequired()])
submit = SubmitField('Send')
......@@ -157,7 +175,8 @@ class EditQuestionForm(Form):
class UploadStimuliForm(Form):
type = RadioField('type', choices=[('text', 'text'), ('picture', 'picture'), ('video', 'video'), ('audio', 'audio')])
type = RadioField('type', choices=[
('text', 'text'), ('picture', 'picture'), ('video', 'video'), ('audio', 'audio')])
text = TextAreaField('Text stimulus')
media = TextAreaField('Media filename')
file = FileField('Upload file')
......@@ -172,7 +191,8 @@ class UploadResearchBulletinForm(Form):
class EditPageForm(Form):
type = RadioField('type', choices=[('text', 'text'), ('picture', 'picture'), ('video', 'video'), ('audio', 'audio')])
type = RadioField('type', choices=[
('text', 'text'), ('picture', 'picture'), ('video', 'video'), ('audio', 'audio')])
text = TextAreaField('Text stimulus')
media = TextAreaField('Media filename')
file = FileField('Upload file')
......@@ -189,4 +209,3 @@ class GenerateIdForm(Form):
number = IntegerField('number', [validators.DataRequired()])
string = StringField('string', [validators.DataRequired()])
submit = SubmitField('Submit')
......@@ -3,16 +3,13 @@ from flask import session
from app import db
from sqlalchemy import Column, Integer, String, Text, Boolean
from flask_wtf import FlaskForm
from wtforms_sqlalchemy.fields import QuerySelectField, QuerySelectMultipleField
from wtforms_sqlalchemy.fields import QuerySelectField
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin
from app import login
from datetime import datetime
"""DATABASE CLASSES"""
class background_question(db.Model):
__tablename__ = "background_question"
idbackground_question = db.Column(db.Integer, primary_key=True)
......
......@@ -198,14 +198,10 @@ def register():
data = request.form.to_dict()
for key, value in data.items():
# tähän db insertit
# flash(key)
# flash(value)
# Input registration page answers to database
participant_background_question_answers = background_question_answer(
answer_set_idanswer_set=session['answer_set'], answer=value, background_question_idbackground_question=key)
answer_set_idanswer_set=session['answer_set'],
answer=value, background_question_idbackground_question=key)
db.session.add(participant_background_question_answers)
db.session.commit()
......@@ -253,7 +249,8 @@ def begin_with_id():
else:
# save the participant ID in session list for now, this is deleted after the session has been started in participant_session-view
session['begin_with_id'] = form.participant_id.data
return render_template('consent.html', exp_id=exp_id, experiment_info=experiment_info, instruction_paragraphs=instruction_paragraphs, consent_paragraphs=consent_paragraphs)
return render_template('consent.html', exp_id=exp_id, experiment_info=experiment_info,
instruction_paragraphs=instruction_paragraphs, consent_paragraphs=consent_paragraphs)
return render_template('begin_with_id.html', exp_id=exp_id, form=form)
......@@ -294,7 +291,9 @@ def instructions():
instruction_paragraphs = str(instructions.instruction)
instruction_paragraphs = instruction_paragraphs.split('<br>')
return render_template('instructions.html', instruction_paragraphs=instruction_paragraphs, participant_id=participant_id)
return render_template('instructions.html',
instruction_paragraphs=instruction_paragraphs,
participant_id=participant_id)
@app.route('/researcher_login', methods=['GET', 'POST'])
......@@ -312,9 +311,6 @@ def login():
login_user(user_details, remember=form.remember_me.data)
return redirect(url_for('index'))
# flash('Login requested for user {}, remember_me={}'.format(
# form.username.data, form.remember_me.data))
# return redirect('/index')
return render_template('researcher_login.html', title='Sign In', form=form)
......@@ -326,12 +322,12 @@ def logout():
@app.route('/view_research_notification')
def view_research_notification():
exp_id = request.args.get('exp_id', None)
image = experiment.query.filter_by(idexperiment=exp_id).first()
research_notification_filename = image.research_notification_filename
return render_template('view_research_notification.html', research_notification_filename=research_notification_filename)
return render_template('view_research_notification.html',
research_notification_filename=research_notification_filename)
@app.route('/researcher_info')
......
......@@ -36,8 +36,6 @@ $(document).ready(function () {
drawButtons.click(function (event) {
event.preventDefault();
console.log("SADATDS");
// Init socket
var socket = io.connect(getDrawingURI);
initConnection(socket);
......
import math
import json
from datetime import datetime
......@@ -15,7 +12,7 @@ from flask import (
url_for,
Blueprint
)
from flask_cors import CORS,cross_origin
from flask_cors import CORS, cross_origin
from sqlalchemy import and_
from sqlalchemy import exc
......@@ -45,7 +42,8 @@ def add_slider_answer(key, value, page_id=None):
the values are inputted for session['current_idpage']. Otherwise the values
are set for the corresponding id found in the trial randomization table"""
participant_answer = answer(question_idquestion=key, answer_set_idanswer_set=session['answer_set'], answer=value, page_idpage=page_id)
participant_answer = answer(
question_idquestion=key, answer_set_idanswer_set=session['answer_set'], answer=value, page_idpage=page_id)
db.session.add(participant_answer)
db.session.commit()
......@@ -55,8 +53,10 @@ def update_answer_set_page():
the_time = datetime.now()
the_time = the_time.replace(microsecond=0)
update_answer_counter = answer_set.query.filter_by(idanswer_set=session['answer_set']).first()
update_answer_counter.answer_counter = int(update_answer_counter.answer_counter) + 1
update_answer_counter = answer_set.query.filter_by(
idanswer_set=session['answer_set']).first()
update_answer_counter.answer_counter = int(
update_answer_counter.answer_counter) + 1
update_answer_counter.last_answer_time = the_time
db.session.commit()
......@@ -67,7 +67,8 @@ def update_answer_set_type(answer_type):
the_time = datetime.now()
the_time = the_time.replace(microsecond=0)
updated_answer_set = answer_set.query.filter_by(idanswer_set=session['answer_set']).first()
updated_answer_set = answer_set.query.filter_by(
idanswer_set=session['answer_set']).first()
updated_answer_set.answer_type = answer_type
updated_answer_set.last_answer_time = the_time
db.session.commit()
......@@ -77,13 +78,15 @@ def select_form_type():
"""Select form type based on the value in answer_set->answer_type"""
form = None
answer_set_type = answer_set.query.filter_by(idanswer_set=session['answer_set']).first().answer_type
answer_set_type = answer_set.query.filter_by(
idanswer_set=session['answer_set']).first().answer_type
if answer_set_type == 'slider':
form = TaskForm()
# Get sliders from this experiment
categories = question.query.filter_by(experiment_idexperiment=session['exp_id']).all()
categories = question.query.filter_by(
experiment_idexperiment=session['exp_id']).all()
categories_and_scales = {}
for cat in categories:
scale_list = [(cat.left, cat.right)]
......@@ -100,9 +103,11 @@ def check_if_answer_exists(answer_type, page_id):
check_answer = None
if answer_type == 'embody':
check_answer = embody_answer.query.filter(and_(embody_answer.answer_set_idanswer_set==session['answer_set'], embody_answer.page_idpage==page_id)).first()
check_answer = embody_answer.query.filter(and_(
embody_answer.answer_set_idanswer_set == session['answer_set'], embody_answer.page_idpage == page_id)).first()
elif answer_type == 'slider':
check_answer = answer.query.filter(and_(answer.answer_set_idanswer_set==session['answer_set'], answer.page_idpage==page_id)).first()
check_answer = answer.query.filter(and_(
answer.answer_set_idanswer_set == session['answer_set'], answer.page_idpage == page_id)).first()
return check_answer
......@@ -110,10 +115,10 @@ def check_if_answer_exists(answer_type, page_id):
def next_page(pages):
# If no more pages left -> complete task
if not pages.has_next:
return redirect ( url_for('task.completed'))
return redirect(url_for('task.completed'))
# If user has answered to all questions, then move to next page
return redirect( url_for('task.task', page_num=pages.next_num))
return redirect(url_for('task.task', page_num=pages.next_num))
def get_experiment_info():
......@@ -124,6 +129,7 @@ def get_experiment_info():
flash("No valid session found")
return redirect('/')
def embody_on():
"""Check from session[exp_id] if embody questions are enabled"""
experiment_info = get_experiment_info()
......@@ -136,7 +142,8 @@ def embody_on():
def slider_on():
"""Check from session[exp_id] if there are slider questions in this session"""
experiment_info = get_experiment_info()
questions = question.query.filter_by(experiment_idexperiment=experiment_info.idexperiment).all()
questions = question.query.filter_by(
experiment_idexperiment=experiment_info.idexperiment).all()
if len(questions) == 0:
return False
......@@ -149,7 +156,8 @@ def task_embody(page_num):
'''Save embody drawing to database.'''
form = StringForm(request.form)
pages = page.query.filter_by(experiment_idexperiment=session['exp_id']).paginate(per_page=1, page=page_num, error_out=True)
pages = page.query.filter_by(experiment_idexperiment=session['exp_id']).paginate(
per_page=1, page=page_num, error_out=True)
page_id = pages.items[0].idpage
if form.validate():
......@@ -160,7 +168,7 @@ def task_embody(page_num):
if session['randomization'] == 'On':
page_id = get_randomized_page(page_id).randomized_idpage
check_answer = check_if_answer_exists('embody',page_id)
check_answer = check_if_answer_exists('embody', page_id)
# Add answer to DB
if check_answer is None:
......@@ -172,7 +180,7 @@ def task_embody(page_num):
# Check if there are unanswered slider questions -> if true redirect to same page
if slider_on():
update_answer_set_type('slider')
return redirect( url_for('task.task', page_num=page_num))
return redirect(url_for('task.task', page_num=page_num))
update_answer_set_page()
return next_page(pages)
......@@ -195,7 +203,8 @@ def task_answer(page_num):
'''Save slider answers to database'''
form = TaskForm(request.form)
pages = page.query.filter_by(experiment_idexperiment=session['exp_id']).paginate(per_page=1, page=page_num, error_out=True)
pages = page.query.filter_by(experiment_idexperiment=session['exp_id']).paginate(
per_page=1, page=page_num, error_out=True)
page_id = pages.items[0].idpage
if form.validate():
......@@ -204,7 +213,7 @@ def task_answer(page_num):
if session['randomization'] == 'On':
page_id = get_randomized_page(page_id).randomized_idpage
check_answer = check_if_answer_exists('slider',page_id)
check_answer = check_if_answer_exists('slider', page_id)
if check_answer is None:
data = request.form.to_dict()
......@@ -224,15 +233,16 @@ def task_answer(page_num):
@task_blueprint.route('/<int:page_num>', methods=['GET'])
def task(page_num):
"""Get selected task page"""
randomized_stimulus=""
randomized_stimulus = ""
experiment_info = get_experiment_info()
#for text stimuli the size needs to be calculated since the template element utilises h1-h6 tags.
#A value of stimulus size 12 gives h1 and value of 1 gives h6
# for text stimuli the size needs to be calculated since the template element utilises h1-h6 tags.
# A value of stimulus size 12 gives h1 and value of 1 gives h6
stimulus_size = experiment_info.stimulus_size
stimulus_size_text = 7-math.ceil((int(stimulus_size)/2))