Exemplo n.º 1
0
class Board(db.Model):
    __tablename__ = "boards"
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(70), unique=True)
    description = db.Column(db.String(210))
    color = db.Column(db.Integer)
    tasks = db.relationship('Task', backref='board', lazy='dynamic')
    lists = db.relationship('List', backref='board', lazy='dynamic')

    def __init__(self, title, description, color=Color.GRAY.value):
        self.title = title
        self.description = description
        self.color = color

    def get_lists(self):
        return list(self.lists.order_by(List.order))

    def get_num_tasks(self):
        return len(list(Task.query.filter(Task.board_id == self.id)))

    def set_template(self, template):
        if template == 1:
            TEMPLATE = Template.BASIC
        else:
            return

        for idx, (name, icon, tasks) in enumerate(TEMPLATE):
            new_list = List(name, icon, self.id, idx)
            self.lists.append(new_list)

    def __repr__(self):
        return "<Board(id='{}', title='{}', description='{}', color='{}')>".format(
            self.id, self.title, self.description, self.color)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
class Tag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), unique=True)
    color = db.Column(db.Integer)
    categories = db.relationship('Category', backref='tag', lazy='dynamic')

    def __init__(self, name, color=Color.GREY):
        self.name = name
        self.color = color.value
    
    def style(self):
        color = Color(self.color)
        return "tagged tag-%s" % color.name.lower()
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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()