Exemplo n.º 1
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    view_count = db.Column(db.Integer, nullable=True, default=0)
    type = db.Column(db.String(100),
                     nullable=False)  # notion, suggestion, response
    department = db.Column(db.String(200), nullable=False)
    topic = db.Column(db.String(200), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    company_id = db.Column(db.String(4),
                           db.ForeignKey('company.id'),
                           nullable=False)
    likes = db.relationship('PostLike',
                            backref='post',
                            lazy='dynamic',
                            cascade='all,delete')
    dislikes = db.relationship('PostDisLike',
                               backref='post',
                               lazy='dynamic',
                               cascade='all,delete')
    responses = db.relationship('Post', lazy=True, cascade='all,delete')
Exemplo n.º 2
0
class PollItem(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    poll_id = db.Column(db.Integer, db.ForeignKey('poll.id'), nullable=False)
    votes = db.relationship('ItemVote',
                            backref='poll_item',
                            lazy='dynamic',
                            cascade='all,delete')
Exemplo n.º 3
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    type = db.Column(db.String(100),
                     nullable=False)  # support, agree, recognize, disagree
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    feedback_id = db.Column(db.Integer,
                            db.ForeignKey('feedback.id'),
                            nullable=False)
Exemplo n.º 4
0
class Step(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    number = db.Column(db.Integer, nullable=False)
    content = db.Column(db.Text, nullable=False)
    complete = db.Column(db.Boolean, nullable=False, default=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    decision_id = db.Column(db.Integer,
                            db.ForeignKey('decision.id'),
                            nullable=False)
Exemplo n.º 5
0
class Poll(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    department = db.Column(db.String(200), nullable=False)
    topic = db.Column(db.String(200), nullable=False)
    poll_items = db.relationship('PollItem',
                                 backref='poll',
                                 lazy=True,
                                 cascade='all,delete')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    company_id = db.Column(db.String(4),
                           db.ForeignKey('company.id'),
                           nullable=False)
Exemplo n.º 6
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    role = db.Column(db.String(120), nullable=False)  #owner, admin, or member
    username = db.Column(db.String(20), unique=True, nullable=False)
    first_name = db.Column(db.String(120), nullable=False)
    last_name = db.Column(db.String(120), nullable=False)
    title = db.Column(db.String(200), nullable=True)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post',
                            backref='author',
                            lazy=True,
                            cascade='all,delete')
    decisions = db.relationship('Decision',
                                backref='author',
                                lazy=True,
                                cascade='all,delete')
    steps = db.relationship('Step',
                            backref='author',
                            lazy=True,
                            cascade='all,delete')
    feedbacks = db.relationship('Feedback',
                                backref='author',
                                lazy=True,
                                cascade='all,delete')
    comments = db.relationship('Comment',
                               backref='author',
                               lazy=True,
                               cascade='all,delete')
    poll_items = db.relationship('PollItem',
                                 backref='author',
                                 lazy=True,
                                 cascade='all,delete')
    polls = db.relationship('Poll',
                            backref='author',
                            lazy=True,
                            cascade='all,delete')
    company_id = db.Column(db.String(4),
                           db.ForeignKey('company.id'),
                           nullable=False)
    liked = db.relationship('PostLike',
                            foreign_keys='PostLike.user_id',
                            backref='user',
                            lazy='dynamic',
                            cascade='all,delete')
    disliked = db.relationship('PostDisLike',
                               foreign_keys='PostDisLike.user_id',
                               backref='user',
                               lazy='dynamic',
                               cascade='all,delete')
    voted = db.relationship('ItemVote',
                            foreign_keys='ItemVote.user_id',
                            backref='user',
                            lazy='dynamic',
                            cascade='all,delete')

    def like_post(self, post):
        if not self.has_liked_post(post):
            like = PostLike(user_id=self.id, post_id=post.id)
            db.session.add(like)

    def unlike_post(self, post):
        if self.has_liked_post(post):
            PostLike.query.filter_by(user_id=self.id, post_id=post.id).delete()

    def has_liked_post(self, post):
        return PostLike.query.filter(PostLike.user_id == self.id,
                                     PostLike.post_id == post.id).count() > 0

    def dislike_post(self, post):
        if not self.has_disliked_post(post):
            dislike = PostDisLike(user_id=self.id, post_id=post.id)
            db.session.add(dislike)

    def undislike_post(self, post):
        if self.has_disliked_post(post):
            PostDisLike.query.filter_by(user_id=self.id,
                                        post_id=post.id).delete()

    def has_disliked_post(self, post):
        return PostDisLike.query.filter(PostDisLike.user_id == self.id,
                                        PostDisLike.post_id
                                        == post.id).count() > 0

    def vote(self, poll_item):
        if not self.has_voted(poll_item):
            vote = ItemVote(user_id=self.id, poll_item_id=poll_item.id)
            db.session.add(vote)

    def unvote(self, poll_item):
        if self.has_voted(poll_item):
            ItemVote.query.filter_by(user_id=self.id,
                                     poll_item_id=poll_item.id).delete()

    def has_voted(self, poll_item):
        return ItemVote.query.filter(ItemVote.user_id == self.id,
                                     ItemVote.poll_item_id
                                     == poll_item.id).count() > 0
Exemplo n.º 7
0
class Topic(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False)
    company_id = db.Column(db.String(4),
                           db.ForeignKey('company.id'),
                           nullable=False)
Exemplo n.º 8
0
class ItemVote(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    poll_item_id = db.Column(db.Integer, db.ForeignKey('poll_item.id'))
Exemplo n.º 9
0
class PostDisLike(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
Exemplo n.º 10
0
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    company_id = db.Column(db.String(4),
                           db.ForeignKey('company.id'),
                           nullable=False)
    likes = db.relationship('PostLike',
                            backref='post',
                            lazy='dynamic',
                            cascade='all,delete')
    dislikes = db.relationship('PostDisLike',
                               backref='post',
                               lazy='dynamic',
                               cascade='all,delete')
    responses = db.relationship('Post', lazy=True, cascade='all,delete')


Post.original_post_id = db.Column(db.Integer, db.ForeignKey(Post.id))


class Decision(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    department = db.Column(db.String(200), nullable=False)
    topic = db.Column(db.String(200), nullable=False)
    steps = db.relationship('Step',
                            backref='decision',
                            lazy=True,
                            cascade='all,delete')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)