# Path: core/database/models.py
# class Question(db.Model):
#     __tablename__ = 'questions'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(STRING_MAX))
#     description = db.Column(db.Text)
#     prompt = db.Column(db.Text)
#     user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
# 
#     user = db.relationship("User", backref=db.backref('questions', order_by=id))
# 
#     created = db.Column(db.DateTime(timezone=True), default=datetime.utcnow)
#     updated = db.Column(db.DateTime(timezone=True), onupdate=datetime.utcnow)
# 
# class Essay(db.Model):
#     __tablename__ = 'essays'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     text = db.Column(db.Text)
#     actual_score = db.Column(db.Float)
#     info = db.Column(db.Text)
# 
#     predicted_score = db.Column(db.Float)
#     model_id = db.Column(db.Integer, db.ForeignKey('models.id'))
#     model = db.relationship("Model", backref=db.backref('essays', order_by=id))
# 
#     question_id = db.Column(db.Integer, db.ForeignKey('questions.id'))
#     question = db.relationship("Question", backref=db.backref('essays', order_by=id))
# 
#     created = db.Column(db.DateTime(timezone=True), default=datetime.utcnow)
#     updated = db.Column(db.DateTime(timezone=True), onupdate=datetime.utcnow)


from flask_wtf import Form
from werkzeug import secure_filename
from flask_wtf.file import FileField, FileRequired, FileAllowed
from wtforms import FloatField, IntegerField, TextField, StringField, TextAreaField
from wtforms.validators import Required, Optional
from core.database.models import Question, Essay
from flask.ext.login import current_user
        from app import db
        from app import db
        from app import db
import csv

class QuestionForm(Form):
    name = StringField('Name', [Required()], description="The name you want to give this question.", )
    prompt = TextAreaField('Prompt', [Optional()], description="The prompt for this question (optional).")

    def save(self):
        q = Question(user=current_user)
        self.populate_obj(q)
        db.session.add(q)
        db.session.commit()

class EssayForm(Form):
    text = TextAreaField('Text', [Required()], description="The text of the essay.")
    actual_score = FloatField('Score (optional)', [Optional()],  description="The score the essay got, if it has a score.")
    info = TextAreaField("Additional Info (optional)", [Optional()], description="Any additional info you want to store with this essay.")

    def save(self, question):

# Path: core/database/models.py
# class Question(db.Model):
#     __tablename__ = 'questions'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(STRING_MAX))
#     description = db.Column(db.Text)
#     prompt = db.Column(db.Text)
#     user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
# 
#     user = db.relationship("User", backref=db.backref('questions', order_by=id))
# 
#     created = db.Column(db.DateTime(timezone=True), default=datetime.utcnow)
#     updated = db.Column(db.DateTime(timezone=True), onupdate=datetime.utcnow)
# 
# class Essay(db.Model):
#     __tablename__ = 'essays'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     text = db.Column(db.Text)
#     actual_score = db.Column(db.Float)
#     info = db.Column(db.Text)
# 
#     predicted_score = db.Column(db.Float)
#     model_id = db.Column(db.Integer, db.ForeignKey('models.id'))
#     model = db.relationship("Model", backref=db.backref('essays', order_by=id))
# 
#     question_id = db.Column(db.Integer, db.ForeignKey('questions.id'))
#     question = db.relationship("Question", backref=db.backref('essays', order_by=id))
# 
#     created = db.Column(db.DateTime(timezone=True), default=datetime.utcnow)
#     updated = db.Column(db.DateTime(timezone=True), onupdate=datetime.utcnow)


# Path: core/web/forms.py
from flask_wtf import Form
from werkzeug import secure_filename
from flask_wtf.file import FileField, FileRequired, FileAllowed
from wtforms import FloatField, IntegerField, TextField, StringField, TextAreaField
from wtforms.validators import Required, Optional
from core.database.models import Question, Essay
from flask.ext.login import current_user
        from app import db
        from app import db
        from app import db
import csv


class QuestionForm(Form):
    name = StringField('Name', [Required()], description="The name you want to give this question.", )
    prompt = TextAreaField('Prompt', [Optional()], description="The prompt for this question (optional).")

    def save(self):
        q = Question(user=current_user)
        self.populate_obj(q)
        db.session.add(q)
        db.session.commit()

class EssayForm(Form):
    text = TextAreaField('Text', [Required()], description="The text of the essay.")
    actual_score = FloatField('Score (optional)', [Optional()],  description="The score the essay got, if it has a score.")
    info = TextAreaField("Additional Info (optional)", [Optional()], description="Any additional info you want to store with this essay.")

    def save(self, question):

        e = Essay(question=question)