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

Cleaning codebase, removed unnecessary migrations folder

parent ef9a7efa
......@@ -2,13 +2,13 @@ import os
from datetime import datetime
from flask import (
Flask,
render_template,
request,
session,
flash,
redirect,
url_for,
Flask,
render_template,
request,
session,
flash,
redirect,
url_for,
Blueprint
)
......@@ -23,44 +23,33 @@ from app.models import background_question_option
from app.models import answer_set, answer, forced_id
from app.models import user, trial_randomization
from app.forms import (
CreateExperimentForm, CreateBackgroundQuestionForm,
CreateExperimentForm, CreateBackgroundQuestionForm,
CreateQuestionForm, UploadStimuliForm
)
create_blueprint = Blueprint("create", __name__,
template_folder='templates',
#static_folder='static',
url_prefix='/create')
create_blueprint = Blueprint("create", __name__,
template_folder='templates',
# static_folder='static',
url_prefix='/create')
@create_blueprint.route('/experiment', methods=['GET', 'POST'])
@login_required
def create_experiment():
form = CreateExperimentForm(request.form)
form = CreateExperimentForm(request.form)
if request.method == 'POST' and form.validate():
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()
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)
......@@ -69,36 +58,38 @@ def create_experiment():
@create_blueprint.route('/experiment_bgquestions', methods=['GET', 'POST'])
@login_required
def experiment_bgquestions():
exp_id = request.args.get('exp_id', None)
form = CreateBackgroundQuestionForm(request.form)
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()
return redirect(url_for('create.experiment_questions', exp_id=exp_id))
return redirect(url_for('create.experiment_questions', exp_id=exp_id))
return render_template('create_experiment_bgquestions.html', form=form, exp_id=exp_id)
......@@ -107,7 +98,7 @@ def experiment_bgquestions():
@login_required
def experiment_questions():
"""Add slider questions"""
exp_id = request.args.get('exp_id', None)
form = CreateQuestionForm(request.form)
......@@ -116,86 +107,87 @@ def experiment_questions():
str = form.questions_and_options.data
str_list = str.split('/n')
for a in range(len(str_list)):
for a in range(len(str_list)):
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
for a in range(len(str_list)):
# 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()
return redirect(url_for('create.experiment_upload_stimuli', exp_id=exp_id))
return redirect(url_for('create.experiment_upload_stimuli', exp_id=exp_id))
@create_blueprint.route('/experiment_upload_stimuli', methods=['GET', 'POST'])
@login_required
def experiment_upload_stimuli():
"""Upload stimuli"""
exp_id = request.args.get('exp_id', None)
form = UploadStimuliForm(request.form)
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))
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)
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
db_path = path + str('/') + str(filename)
new_page = page(experiment_idexperiment=exp_id, type=form.type.data, media=db_path)
# 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)
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,46 +19,47 @@ 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")
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):
questions = StringField()
class Answers(FlaskForm):
background_question_idbackground_question = SelectField(coerce=int, validators=[InputRequired])
background_question_idbackground_question = SelectField(
coerce=int, validators=[InputRequired])
class BackgroundQuestionForm(Form):
idbackground_question_option = StringField()
background_question_idbackground_question = StringField()
option = StringField()
......@@ -66,13 +67,13 @@ class BackgroundQuestionForm(Form):
class TestForm(Form):
question_name = StringField()
options1 = SelectField()
class TestForm1(Form):
questions1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send")
......@@ -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()])
creator_name = StringField('Creator_name', [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,53 +105,68 @@ 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'),
('Welsh', 'Welsh'), ('Xhosa', 'Xhosa')])
('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')])
('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12')])
submit = SubmitField('Send')
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')
class CreateEmbodyForm(Form):
question = TextAreaField('Question')
picture = FileField('Upload picture')
submit = SubmitField('Send')
class EditQuestionForm(Form):
class EditQuestionForm(Form):
left = StringField('left_scale', [validators.DataRequired()])
right = StringField('right_scale', [validators.DataRequired()])
......@@ -156,8 +174,9 @@ 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')
......@@ -165,28 +184,28 @@ class UploadStimuliForm(Form):
class UploadResearchBulletinForm(Form):
file = FileField('Upload file')
submit = SubmitField('Send')
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')
submit = SubmitField('Send')
class RemoveExperimentForm(Form):
remove = TextAreaField('Remove')
submit = SubmitField('Send')
class GenerateIdForm(Form):
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