Commit e1cbc7e6 authored by Timo Heikkilä's avatar Timo Heikkilä
Browse files

add initial commit

parent 3e612671
__pycache__/
/migrations
/venv
app.db
cmd.txt
DB_inserts.txt
dumb.sql
scrap_script.py
*.pyc
from flask import Flask
from flask_bootstrap import Bootstrap
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_babel import Babel
app = Flask(__name__)
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
babel = Babel(app)
@babel.localeselector
def get_locale():
return 'fin'
#mariabd mysql portti 3306 tarkista?
Bootstrap(app)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
login.login_view = 'login'
app.secret_key = 'random string'
"""app.secret_key = os.urandom(24)"""
from app import routes, models
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField
from wtforms.validators import DataRequired, InputRequired
from wtforms_sqlalchemy.fields import QuerySelectField
from flask_bootstrap import Bootstrap
from app.models import background_question
from wtforms import Form, TextField, TextAreaField, SubmitField, FieldList, FormField
from wtforms import Form, BooleanField, StringField, PasswordField, validators, RadioField
from flask_wtf.file import FileField, FileAllowed, FileRequired
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Remember Me')
submit = SubmitField('Sign In')
class RegisterForm(Form):
questions1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send")
class TaskForm(Form):
categories1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send")
class ContinueTaskForm(FlaskForm):
participant_id = StringField('participant_id', validators=[DataRequired()])
submit = SubmitField('Continue rating')
class StartWithIdForm(FlaskForm):
participant_id = StringField('participant_id', validators=[DataRequired()])
submit = SubmitField('Start rating')
class Questions(FlaskForm):
questions = StringField()
class Answers(FlaskForm):
background_question_idbackground_question = SelectField(coerce=int, validators=[InputRequired])
class BackgroundQuestionForm(Form):
idbackground_question_option = StringField()
background_question_idbackground_question = StringField()
option = StringField()
submit = SubmitField('Register')
class TestForm(Form):
question_name = StringField()
options1 = SelectField()
class TestForm1(Form):
questions1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send")
class TestForm2(Form):
questions1 = SelectField()
#Forms for editing functions
class CreateExperimentForm(Form):
name = StringField('Name', [validators.DataRequired()])
instruction = StringField('Instruction', [validators.DataRequired()])
language = StringField('Language', [validators.DataRequired()])
submit = SubmitField('Send')
class EditExperimentForm(Form):
name = StringField('Name', [validators.DataRequired()])
instruction = StringField('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 (Mandarin)', 'Chinese (Mandarin)'), ('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')])
submit = SubmitField('Send')
class CreateBackgroundQuestionForm(Form):
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')
new_values = TextAreaField('New values', [validators.DataRequired()])
submit = SubmitField('Send')
class CreateQuestionForm(Form):
questions_and_options = TextAreaField('Questions and options', [validators.DataRequired()])
submit = SubmitField('Send')
class EditQuestionForm(Form):
left = StringField('left_scale', [validators.DataRequired()])
right = StringField('right_scale', [validators.DataRequired()])
question = StringField('question', [validators.DataRequired()])
class UploadStimuliForm(Form):
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 EditPageForm(Form):
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')
# Translations template for PROJECT.
# Copyright (C) 2018 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-11-04 17:30+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n"
from app import db
from sqlalchemy import Column, Integer, String
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm
from wtforms_sqlalchemy.fields import QuerySelectField, QuerySelectMultipleField
from flask_bootstrap import Bootstrap
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin
from app import login
"""DATABASE CLASSES"""
class background_question(db.Model):
__tablename__ = "background_question"
idbackground_question = db.Column(db.Integer, primary_key=True)
background_question = db.Column(db.String(120))
answers = db.relationship('background_question_answer', backref='question', lazy='dynamic')
experiment_idexperiment = db.Column(db.Integer)
def __repr__(self):
return "<idbackground_question = '%s', background_question = '%s'>" % (self.idbackground_question, self.background_question)
class background_question_option(db.Model):
__tablename__ = "background_question_option"
idbackground_question_option = db.Column(db.Integer, primary_key=True)
background_question_idbackground_question = db.Column(db.Integer, db.ForeignKey('background_question.idbackground_question'))
option = db.Column(db.String(120))
def __repr__(self):
return "<idbackground_question_option = '%s', background_question_idbackground_question = '%s', option = '%s'>" % (self.idbackground_question_option, self.background_question_idbackground_question, self.option)
class experiment (db.Model):
__tablename__ = "experiment"
idexperiment = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120), index=True)
instruction = db.Column(db.String(120), index=True)
directoryname = db.Column(db.String(120), index=True, unique=True)
language = db.Column(db.String(120))
status = db.Column(db.String(120))
randomization = db.Column(db.String(120))
def __repr__(self):
return "<idexperiment = '%s', name='%s', instruction='%s', directoryname='%s', language='%s', status='%s', randomization='%s'>" % (self.idexperiment, self.name, self.instruction, self.directoryname, self.language, self.status, self.randomization)
class answer_set (db.Model):
__tablename__ = "answer_set"
idanswer_set = db.Column(db.Integer, primary_key=True)
experiment_idexperiment = db.Column(db.Integer, db.ForeignKey('experiment.idexperiment'))
session = db.Column(db.String(120))
agreement = db.Column(db.String(120))
answer_counter = db.Column(db.Integer)
def __repr__(self):
return "<idanswer_set = '%s', experiment_idexperiment = '%s', session = '%s', agreement = '%s', answer_counter = '%s'>" % (self.idanswer_set, self.experiment_idexperiment, self.session, self.agreement, self.answer_counter)
class background_question_answer(db.Model):
__tablename__ = "background_question_answer"
idbackground_question_answer = db.Column(db.Integer, primary_key=True)
answer_set_idanswer_set = db.Column(db.Integer, db.ForeignKey('answer_set.idanswer_set'))
answer = db.Column(db.String(120))
background_question_idbackground_question = db.Column(db.Integer, db.ForeignKey('background_question.idbackground_question'))
def __repr__(self):
return "<idbackground_question_answer = '%s', answer_set_idanswer_set = '%s', answer = '%s', background_question_idbackground_question = '%s'>" % (self.idbackground_question_answer, self.answer_set_idanswer_set, self.answer, self.background_question_idbackground_question)
"""
def __repr__(self):
return '<answer {}>'.format(self.answer)
"""
def background_question_answer_query():
return background_question_answer.query
"""
class ChoiceForm(FlaskForm):
opts = QuerySelectField(query_factory=background_question_answer_query, allow_blank=True)
"""
"""
u = background_question.query.get(1)
vastaukset = u.answers.all()
## pitää sisällään kysymyksen 1 vastaukset
"""
class question (db.Model):
__tablename__ = "question"
idquestion = db.Column(db.Integer, primary_key=True)
experiment_idexperiment = db.Column(db.Integer, db.ForeignKey('experiment.idexperiment'))
question = db.Column(db.String(120))
left = db.Column(db.String(120))
right = db.Column(db.String(120))
def __repr__(self):
return "<idquestion = '%s', experiment_idexperiment = '%s', question = '%s', left = '%s', right = '%s'>" % (self.idquestion, self.experiment_idexperiment, self.question, self.left, self.right)
class page (db.Model):
__tablename__ = "page"
idpage = db.Column(db.Integer, primary_key=True)
experiment_idexperiment = db.Column(db.Integer, db.ForeignKey('experiment.idexperiment'))
type = db.Column(db.String(120), index=True)
text = db.Column(db.String(120), index=True)
media = db.Column(db.String(120), index=True)
"""
def __repr__(self):
return "<idpage = '%s', experiment_idexperiment = '%s', type = '%s', text = '%s', media = '%s'>" % (self.idpage, self.experiment_idexperiment, self.type, self.text, self.media)
def __repr__(self):
return '{}'.format(self.text)
"""
def __repr__(self):
return "<idpage = '%s', experiment_idexperiment = '%s', type = '%s', text = '%s', media = '%s'>" % (self.idpage, self.experiment_idexperiment, self.type, self.text, self.media)
class answer (db.Model):
__tablename__ = "answer"
idanswer = db.Column(db.Integer, primary_key=True)
question_idquestion = db.Column(db.Integer, db.ForeignKey('question.idquestion'))
answer_set_idanswer_set = db.Column(db.Integer, db.ForeignKey('answer_set.idanswer_set'))
answer = db.Column(db.String(120))
page_idpage = db.Column(db.Integer, db.ForeignKey('page.idpage'))
def __repr__(self):
return "<idanswer = '%s', question_idquestion = '%s', answer_set_idanswer_set = '%s', answer = '%s', page_idpage = '%s'>" % (self.idanswer, self.question_idquestion, self.answer_set_idanswer_set, self.answer, self.page_idpage)
class trial_randomization (db.Model):
__tablename__ = "trial_randomization"
idtrial_randomization = db.Column(db.Integer, primary_key=True)
page_idpage = db.Column(db.Integer)
randomized_idpage = db.Column(db.Integer)
answer_set_idanswer_set = db.Column(db.Integer)
experiment_idexperiment = db.Column(db.Integer)
def __repr__(self):
return "<idtrial_randomization = '%s', page_idpage = '%s', randomized_idpage = '%s', answer_set_idanswer_set = '%s', experiment_idexperiment = '%s'>" % (self.idtrial_randomization, self.page_idpage, self.randomized_idpage, self.answer_set_idanswer_set, self.experiment_idexperiment)
class user(UserMixin, db.Model):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
password_hash = db.Column(db.String(128))
def __repr__(self):
return '<user {}>'.format(self.username)
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
@login.user_loader
def load_user(id):
return user.query.get(int(id))
\ No newline at end of file
from app import app, db, babel
from app.models import background_question, background_question_option
from app.models import experiment
from app.models import answer_set
from app.models import background_question_answer
from app.models import question, page, answer
from app.models import user, trial_randomization
@app.shell_context_processor
def make_shell_context():
return {'db': db,
'background_question': background_question,
'background_question_option': background_question_option,
'experiment': experiment,
'answer_set': answer_set,
'background_question_answer': background_question_answer,
'question': question,
'page': page,
'answer': answer,
'user': user,
'trial_randomization': trial_randomization
}
"""
from app import app, db
from app.models import Background_question, Background_question_answer
from app.models import Experiment, Question, Answer_set
from app.models import Page, Answer
@app.shell_context_processor
def make_shell_context():
return {'db': db,
'Background_question': Background_question,
'Background_question_answer': Background_question_answer,
'Experiment': Experiment,
'Question': Question,
'Answer_set': Answer_set,
'Page': Page,
'Answer': Answer,
}
"""
\ No newline at end of file
This diff is collapsed.
.btn {
border-radius: 0px;
}
.navbar-custom{
background-color:red;
border-color: green;
}
body {
background-color: darkgrey;
font-family: Helvetica, Arial, sans-serif;
}
container {
text-decoration-color: #4EB1BA;
margin-left: auto;
margin-right: auto;
}
#header{
background-color: darkslategrey;
color: white;
text-align: center;
}
#nav{
}
#main{
}
\ No newline at end of file
This diff is collapsed.
{% macro render_field(field) %}
<dt>{{ field.label }}
<dd>{{ field(**kwargs)|safe }}
{% if field.errors %}
<ul class=errors>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</dd>
{% endmacro %}
\ No newline at end of file
{% extends "base.html" %}
{% block content %}
<h1 class="container mt-5 display-4 text-center"><br>Add background questions:</h1>
<br>
<p class="lead">Please paste the background questions followed by the list of options for that question separated by ; into the field below.
Mark the last option of the question with a /n after which you can again input a new question followed by a list of options.
<br>
<br>
<b>Here is an example input of two background questions:</b>
<br>
<br>
How many hours did you sleep last night?;6;7;8;9;10/n
Do you normally listen to audio books?;Yes;No
</p>
{% from "_formhelpers.html" import render_field %}
<form action="" method="post" role="form">
<div class="form-group">
<label for="Background questions">Background questions and options:</label>
<textarea class="form-control" rows="15" id="bg_questions_and_options" name="bg_questions_and_options"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<a class="btn btn-primary" href="{{ request.referrer }}" role="button">Cancel</a>
</form>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% block content %}
<h1 class="container mt-5 display-4 text-center"><br>Add sliders:</h1>
<br>
<p class="lead">Please paste the slider set questions followed by the left and right ends of the scales separated with a ; Place a /n after the right scale to input another question
followed by the corresponding scales. Make sure you do not input the /n after the last question.
<br>
<br>
<b>Here is an example input of two questions followed by their left (first) and right (second) ends of the scales:</b>
<br>
<br>
Did the stimulus make you feel angry?; No; Yes /n
Did the stimulus make you feel happy; Not at all; Yes, alot
</p>
{% from "_formhelpers.html" import render_field %}
<form action="" method="post" role="form">
<div class="form-group">
<label for="questions_and_options">Question;left scale;right scale/n</label>
<textarea class="form-control" rows="15" id="questions_and_options" name="questions_and_options"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<a class="btn btn-primary" href="{{ request.referrer }}" role="button">Cancel</a>
</form>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% block content %}
<h1 class="container mt-5 display-4 text-center"><br>Add more stimuli:</h1>
<br>
<p class="lead"></p>
{% from "_formhelpers.html" import render_field %}
<form id="EditPageForm" action="" method="POST" role="form" enctype="multipart/form-data">
{% if stimulus_type == 'text' %}
<div class="form-group">
<legend>Paste the new texts to the textarea and mark the end of each stimulus with a /n. Do not place the marker at the end of the last text. Example: Text1/n Text2/n Text3</legend>
<textarea class="form-control" rows="10" id="text" name="text"></textarea>
</div>
{% else %}
<div class="input-group mb-3">
<legend>Add files:</legend>
<div class="input-group-prepend">
<span class="input-group-text">Upload:</span>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input" id="file" name="file" accept="audio/*,video/*,image/*" multiple>
<label class="custom-file-label" for="upload_file">Choose file</label>
</div>
</div>
{% endif %}
<br>
<button type="submit" class="btn btn-primary">Submit</button>
<a class="btn btn-primary" href="{{ request.referrer }}" role="button">Cancel</a>
</form>
{% endblock %}
{% import "bootstrap/wtf.html" as wtf %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content=""&