class Annotation(db.Model, CRUD): __tablename__ = 'annotations' id = db.Column(db.Integer, primary_key=True, autoincrement=True) assignment_id = db.Column(db.Integer, db.ForeignKey('assignments.id')) submissionName = db.Column(db.String) submissionID = db.Column(db.Integer, db.ForeignKey('submissions.submissionID')) sentenceIndex = db.Column(db.Integer) sentence = db.Column(db.Text) selectedTheme = db.Column(db.Integer, db.ForeignKey('themes.id')) annotatorID = db.Column(db.Integer, db.ForeignKey('users.id')) annotatorName = db.Column(db.String) __table_args__ = (db.UniqueConstraint('assignment_id', 'submissionID', 'sentenceIndex', 'annotatorID'), ) def __init__(self, assignment_id, submissionID, sentenceIndex, selectedTheme, annotatorID, sentence, submissionName=None, annotatorName=None): self.assignment_id = assignment_id self.submissionID = submissionID self.sentenceIndex = sentenceIndex self.selectedTheme = selectedTheme self.annotatorID = annotatorID self.sentence = sentence self.annotatorName = annotatorName self.submissionName = submissionName
class Concepts(db.Model, CRUD): __tablename__ = 'concepts' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), nullable=False, unique=True) help_text = db.Column(db.String(255)) created_on = db.Column(db.DateTime, nullable=False) edited_on = db.Column(db.DateTime, nullable=False) creator_id = db.Column(db.Integer, db.ForeignKey('users.id')) creator = db.relationship("User", back_populates="concepts") creator_name = db.Column(db.String(255), nullable=False) concept_type = db.Column(db.String(20), default='bipolar', nullable=False) input_terms = db.Column(JSON) def __init__(self, name, creator_id, concept_type, input_terms, creator_name): self.name = name self.creator_id = creator_id self.concept_type = concept_type self.input_terms = input_terms self.created_on = datetime.datetime.now() self.edited_on = datetime.datetime.now() self.creator_name = creator_name def get_id(self): return self.id def __repr__(self): return '<id {}>'.format(self.id)
class Assignment(db.Model, CRUD): __tablename__ = 'assignments' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), nullable=False, unique=True) title = db.Column(db.String(255)) description = db.Column(db.Text) created_on = db.Column(db.DateTime, nullable=False) edited_on = db.Column(db.DateTime, nullable=False) creator_id = db.Column(db.Integer, db.ForeignKey('users.id')) creator = db.relationship("User", back_populates="assignments") creator_name = db.Column(db.String(255), nullable=False) submissions = db.relationship('Submission', backref='assignments') #lazy=True themes = db.relationship('Theme', backref='assignments') #submissions = db.relationship('Address', lazy='select', backref=db.backref('person', lazy='joined')) def __init__(self, name, title, desc, creator_id, creator_name): self.name = name self.title = title self.description = desc self.creator_id = creator_id self.created_on = datetime.datetime.now() self.edited_on = datetime.datetime.now() self.creator_name = creator_name def get_id(self): return self.id def __repr__(self): return '<id {}>'.format(self.id)
class Comment(db.Model): __tablename__ = 'comments' approveDate = db.Column(db.String) commentBody = db.Column(db.String) commentID = db.Column(db.Integer, primary_key=True) commentSequence = db.Column(db.Integer) commentTitle = db.Column(db.String) commentType = db.Column(db.String) createDate = db.Column(db.String) depth = db.Column(db.Integer) editorsSelection = db.Column(db.Boolean) parentID = db.Column(db.Integer, db.ForeignKey('comments.commentID')) parentUserDisplayName = db.Column(db.String) permID = db.Column(db.String) picURL = db.Column(db.String) recommendations = db.Column(db.Integer) replies = db.relationship("Comment") replyCount = db.Column(db.Integer) reportAbuseFlag = db.Column(db.String) status = db.Column(db.String) trusted = db.Column(db.Integer) updateDate = db.Column(db.String) userID = db.Column(db.Integer) userDisplayName = db.Column(db.String) userTitle = db.Column(db.String) userURL = db.Column(db.String) userLocation = db.Column(db.String) assetID = db.Column(BIGINT, db.ForeignKey('articles.id')) article = db.relationship("Article", back_populates="comments") def __init__(self, apiResult, assetID): try: if 'replies' in apiResult: del apiResult['replies'] self.assetID = assetID for key, value in apiResult.iteritems(): setattr(self, key, value) except Exception as e: pdb.set_trace() print apiResult print e def __repr__(self): return '<Commentid {}>'.format(self.commentID)
class Submission(db.Model, CRUD): __tablename__ = 'submissions' submissionDate = db.Column(db.String) submissionName = db.Column(db.String) submissionBody = db.Column(db.Text) submissionID = db.Column(db.Integer, primary_key=True, autoincrement=True) userID = db.Column(db.Integer, db.ForeignKey('users.id')) userDisplayName = db.Column(db.String) assignmentID = db.Column(db.Integer, db.ForeignKey('assignments.id')) assignment = db.relationship("Assignment", back_populates="submissions") def __init__(self, name, body, assignment, userID, username): self.submissionDate = datetime.datetime.now() self.submissionName = name self.submissionBody = body self.userID = userID self.assignmentID = assignment self.userDisplayName = username def __repr__(self): return '<Submissionid {}>'.format(self.submissionID)
class Theme(db.Model, CRUD): __tablename__ = 'themes' id = db.Column(db.Integer, primary_key=True, autoincrement=True) assignment_id = db.Column(db.Integer, db.ForeignKey('assignments.id')) themeName = db.Column(db.String, unique=True) color = db.Column(db.String) themeSentences = db.Column(db.Text) __table_args__ = (db.UniqueConstraint('assignment_id', 'color'), ) #themeSentences = db.relationship('ThemeSentence', backref='themes') def __init__(self, themeName, themeSentences, assignment_id, color): self.themeName = themeName self.themeSentences = themeSentences self.assignment_id = assignment_id self.color = color