class Chapter(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) synopsis = db.Column(db.Text) number = db.Column(db.Integer, default=0) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) events = db.relationship('Event', backref='chapter', lazy='dynamic', order_by="Event.event_occurs_percent") book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=True) def __init__(self, title, synopsis, user_id, book_id): self.title = title self.synopsis = synopsis self.user_id = user_id if not book_id == '-1': self.book_id = book_id def wordcount(self): c = 0 for event in self.events: c = c + event.wordcount() return c def style(self): if self.book is not None: return self.book.style() else: return "tagged tag-grey" def __repr__(self): return self.title
class Task(db.Model): __tablename__ = "tasks" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(70)) description = db.Column(db.String(140)) color = db.Column(db.Integer) order = db.Column(db.Integer) board_id = db.Column(db.Integer, db.ForeignKey('boards.id')) list_id = db.Column(db.Integer, db.ForeignKey('lists.id')) def __init__(self, title, description, list_id, board_id, order, color=Color.GRAY.value): self.title = title self.description = description self.color = color self.order = order self.list_id = list_id self.board_id = board_id def __repr__(self): return "<Task(id='{}', title='{}', description='{}', color='{}', order='{}', list_id='{}', board_id='{}')>".format( self.id, self.title, self.description, self.color, self.order, self.list_id, self.board_id)
class EventChar(db.Model): id = db.Column(db.Integer, primary_key=True) castmember_id = db.Column(db.Integer, db.ForeignKey('castmember.id')) event_id = db.Column(db.Integer, db.ForeignKey('event.id')) def __init__(self, castmember_id, event_id): self.castmember_id = castmember_id self.event_id = event_id
class Storyline(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(70)) description = db.Column(db.String(210)) tag_id = db.Column(db.Integer, db.ForeignKey('tag.id')) events = db.relationship('Event', backref='storyline', lazy='dynamic') user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __init__(self, user_id, title, description, tag_id): self.title = title self.description = description self.tag_id = tag_id self.user_id = user_id
class Event(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(70)) description = db.Column(db.Text) status = db.Column(db.Integer, default=1) storyline_id = db.Column(db.Integer, db.ForeignKey('storyline.id'), nullable=True) chapter_id = db.Column(db.Integer, db.ForeignKey('chapter.id'), nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) event_occurs_percent = db.Column(db.Float, default=0.0) cast = relationship("Castmember", secondary=EventChar.__table__, backref="events") def __init__(self, user_id, title, description, storyline_id='-1', castmember_id='-1', chapter_id='-1', event_occurs_percent=0): self.title = title self.description = description self.status = Status.TO_DO.value if not storyline_id == '-1': self.storyline_id = storyline_id if not castmember_id == '-1': self.castmember_id = castmember_id if not chapter_id == '-1': self.chapter_id = chapter_id self.event_occurs_percent = event_occurs_percent self.user_id = user_id def style(self): if self.storyline is not None: return self.storyline.tag.style() else: return "tagged tag-grey" def wordcount(self): c = self.description.split().__len__() return c def __repr__(self): return "{} ({}: {})".format(self.title, self.chapter.title, self.event_occurs_percent)
class Book(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) synopsis = db.Column(db.Text) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) chapters = db.relationship('Chapter', backref='book', lazy='dynamic', order_by="Chapter.number") def __init__(self, title, synopsis, user_id): self.title = title self.synopsis = synopsis self.user_id = user_id def style(self): color = Color(1 + self.id % 4) return "tagged tag-%s" % color.name.lower() def wordcount(self): c = 0 for chapter in self.chapters: c = c + chapter.wordcount() return c def __repr__(self): return self.title
class Castmember(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30)) initials = db.Column(db.String(3)) color = db.Column(db.Integer) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return "{} ({})".format(self.name, self.initials) def __init__(self, user_id, name="Unassigned", initials="U", color=Color.GREY): self.name = name self.color = color.value self.initials = initials self.user_id = user_id def getEvents(self): Events = [] EventChars = EventChar.query.filter_by(castmember_id=self.id).all() for e in EventChars: Events.append(Event.query.filter_by(event_id=e.event_id).first()) return Events def style(self): color = CastmemberColor(self.color) return "tagged tag-%s" % color.name.lower() def bgcol(self): color = CastmemberColor(self.color) return "bg-%s" % color.name.lower()
class List(db.Model): __tablename__ = "lists" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(70)) icon = db.Column(db.Integer) color = db.Column(db.Integer) order = db.Column(db.Integer) board_id = db.Column(db.Integer, db.ForeignKey('boards.id')) tasks = db.relationship('Task', backref='list', lazy='dynamic') def __init__(self, title, icon, board_id, order, color=Color.GRAY.value): self.title = title self.icon = icon self.board_id = board_id self.order = order self.color = color def get_num_lists(self): return len(List.query.filter(List.board_id == self.board_id).all()) def get_tasks(self): return list(self.tasks.order_by(Task.order)) def __repr__(self): return "<List(id='{}', title='{}', icon='{}', color='{}', order='{}', board_id='{}')>".format( self.id, self.title, self.icon, self.color, self.order, self.board_id)
class Task(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(70)) outcome = db.Column(db.String(140)) description = db.Column(db.String(140)) status = db.Column(db.Integer) benefit_id = db.Column(db.Integer, db.ForeignKey('benefit.id')) benefit_value = db.Column(db.String(140)) category_id = db.Column(db.Integer, db.ForeignKey('category.id')) def __init__(self, title, outcome, description, benefit_id, benefit_value, category_id): self.title = title self.outcome = outcome self.description = description self.benefit_id = benefit_id self.benefit_value = benefit_value self.status = Status.PROPOSED.value self.category_id = category_id
class LogEntry(db.Model): id = db.Column(db.Integer, primary_key=True) timestamp = db.Column(db.String(30)) message = db.Column(db.String(140)) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __init__(self, message, uid): self.message = message self.timestamp = strftime("%d-%m-%Y %H:%M:%S") self.user_id = uid
class Category(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(70), unique=True) description = db.Column(db.String(210)) tag_id = db.Column(db.Integer, db.ForeignKey('tag.id')) tasks = db.relationship('Task', backref='category', lazy='dynamic') def __init__(self, title, description, tag_id): self.title = title self.description = description self.tag_id = tag_id
class Task(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(70)) description = db.Column(db.String(140)) status = db.Column(db.Integer) mission_id = db.Column(db.Integer, db.ForeignKey('mission.id')) def __init__(self, title, description, mission_id): self.title = title self.description = description self.status = Status.TO_DO.value self.mission_id = mission_id
class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20)) color = db.Column(db.Integer) storylines = db.relationship('Storyline', backref='tag', lazy='dynamic') user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __init__(self, user_id, name, color=Color.GREY): self.name = name self.color = color.value self.user_id = user_id def style(self): color = Color(self.color) return "tagged tag-%s" % color.name.lower()