Ejemplo n.º 1
0
class Projects_Juniors_Relation(db.Model):
    __tablename__ = 'Projects_Juniors_Relation'

    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer,
                           db.ForeignKey('Projects.id'),
                           nullable=False)
    junior_id = db.Column(db.Integer,
                          db.ForeignKey('Juniors.id'),
                          nullable=False)

    def __init__(self, project_id, junior_id):
        self.project_id = project_id
        self.junior_id = junior_id

    def __repr__(self):
        return f"<id {self.id}>"

    def add_new_relation(new_project_junior_relation):
        db.session.add(new_project_junior_relation)
        db.session.commit()

    def get_junior_portfolio(email):
        return db.session.query(Projects_Juniors_Relation, Junior, Project, Company)\
            .join(Junior, Projects_Juniors_Relation.junior_id == Junior.id)\
            .join(Project, Projects_Juniors_Relation.project_id == Project.id)\
            .join(Company, Project.company_id == Company.id)\
            .filter(email==email).all()

    def dump(self):
        return {'project_id': self.project_id, 'junior_id': self.junior_id}
Ejemplo n.º 2
0
class Project(db.Model):
    __tablename__ = 'Projects'

    id = db.Column(db.Integer, primary_key=True)
    company_id = db.Column(db.Integer,
                           db.ForeignKey('Companies.id'),
                           nullable=False)
    description = db.Column(db.Text)
    field = db.Column(db.ARRAY(db.String(50)))
    status = db.Column(db.String(120))

    def __init__(self, company_id, description, field, status):
        self.company_id = company_id
        self.description = description
        self.field = field
        self.status = status

    def __repr__(self):
        return f"<id {self.id}>"

    def get_projects(lim=None):
        return Project.query.limit(lim).all()

    def add_new_project(new_project):
        db.session.add(new_project)
        db.session.commit()

    def change_project_status(project_id, status):
        project = Project.query.filter_by(id=project_id).first()
        print("!!!!!!!!!")
        print(project.description)
        project.status = status
        db.session.commit()

    def dump(self,
             company_name,
             company_email,
             company_description,
             company_profile_picture=None,
             company_url=None,
             facebook_url=None,
             instagram_url=None):
        return {
            'id': self.id,
            'company_name': company_name,
            'company_email': company_email,
            'company_description': company_description,
            'company_profile_picture': company_profile_picture,
            'description': self.description,
            'field': self.field,
            'status': self.status,
            'company_url': company_url,
            'facebook_url': facebook_url,
            'instagram_url': instagram_url
        }
Ejemplo n.º 3
0
class PostUpvoteUser(db.Model):
    __tablename__ = 'post_upvote_user'

    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id'),
                        primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id'),
                        primary_key=True)

    post = db.relationship('Post', cascade="save-update, merge, delete")
    user = db.relationship('User', cascade="save-update, merge, delete")
Ejemplo n.º 4
0
class PostTag(db.Model):
    # http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html#association-object
    __tablename__ = 'post_tag'

    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id'),
                        primary_key=True)
    tag_id = db.Column(db.Integer, db.ForeignKey('tags.id'), primary_key=True)
    is_explicit = db.Column(db.Boolean, nullable=False, default=True)

    post = db.relationship('Post', cascade="save-update, merge, delete")
    tag = db.relationship('Tag', cascade="save-update, merge, delete")
Ejemplo n.º 5
0
class Team(db.Model):
    __tablename__ = 'teams'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    team_name = db.Column(db.String(30),
                          primary_key=False,
                          unique=True,
                          nullable=False)
    created_date = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.datetime.now())

    # posts = db.relationship('Post')
    users = db.relationship('User', secondary='user_team')
Ejemplo n.º 6
0
class UserTeam(db.Model):
    __tablename__ = 'user_team'

    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id'),
                        primary_key=True)

    team_id = db.Column(db.Integer,
                        db.ForeignKey('teams.id'),
                        primary_key=True)

    user = db.relationship('User', cascade="save-update, merge, delete")

    team = db.relationship('Team', cascade="save-update, merge, delete")
Ejemplo n.º 7
0
class Post(db.Model):
    __tablename__ = 'posts'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    created_date = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.datetime.now())
    modified_date = db.Column(db.DateTime,
                              nullable=False,
                              default=datetime.datetime.now())
    title = db.Column(db.String(130), nullable=False)
    # body = db.Column(db.Text(4294967295), nullable=False)
    body = db.Column(db.LargeBinary(length=(2**32) - 1), nullable=False)

    post_tags = db.relationship('PostTag')
    collaborators = db.relationship('User', secondary='post_user')
    upvotes = db.relationship('User', secondary='post_upvote_user')
Ejemplo n.º 8
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(30),
                         primary_key=False,
                         unique=True,
                         nullable=False)
    display_name = db.Column(db.String(30),
                             primary_key=False,
                             unique=False,
                             nullable=False)
    hashed_password = db.Column(db.Binary(64), nullable=False)
    # is_verified = db.Column(db.Boolean, nullable=False, default=False)
    last_login_date = db.Column(db.DateTime, nullable=True)
    minimum_iat = db.Column(db.Integer,
                            nullable=False,
                            default=int(time.time()))
    picture = db.Column(db.String(100), unique=False, nullable=True)

    # posts = db.relationship('Post')
    teams = db.relationship('Team', secondary='user_team')

    def set_password(self, password):
        '''hash via bcrypt and persist to user'''

        self.hashed_password = bcrypt.hashpw(password=password.encode('utf-8'),
                                             salt=bcrypt.gensalt())

    def check_password(self, password):
        '''check password against hashed user pwd using bcrypt'''

        return bcrypt.checkpw(password=password.encode('utf-8'),
                              hashed_password=self.hashed_password)
Ejemplo n.º 9
0
class Junior(UserMixin, db.Model):
    __tablename__ = 'Juniors'

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password_hash = db.Column(db.String(120), nullable=False)
    full_name = db.Column(db.String(120), nullable=False)
    phone_number = db.Column(db.Text)
    field = db.Column(db.ARRAY(db.String(50)))
    profile_picture = db.Column(db.String())
    personal_url = db.Column(db.String())
    facebook_url = db.Column(db.String())
    instagram_url = db.Column(db.String())
    linkedIn_url = db.Column(db.String())
    gitHub_url = db.Column(db.String())
    about_me = db.Column(db.Text)

    def __init__(self, email, full_name, phone_number, field, profile_picture,
                 personal_url, facebook_url, instagram_url, linkedIn_url,
                 gitHub_url, about_me):
        self.email = email
        self.full_name = full_name
        self.phone_number = phone_number
        self.field = field
        self.profile_picture = profile_picture
        self.personal_url = personal_url
        self.facebook_url = facebook_url
        self.instagram_url = instagram_url
        self.linkedIn_url = linkedIn_url
        self.gitHub_url = gitHub_url
        self.about_me = about_me

    def __repr__(self):
        return f"<User {self.email}>"

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def get_juniors(lim=None):
        return Junior.query.limit(lim).all()

    def add_new_junior(new_junior):
        db.session.add(new_junior)
        db.session.commit()

    def delete_junior(junior_email):
        d = Junior.delete().where(Junior.email == junior_email)
        d.execute()

    def dump(self):
        return {
            'id': self.id,
            'email': self.email,
            'full_name': self.full_name,
            'phone_number': self.phone_number,
            'field': self.field,
            'profile_picture': self.profile_picture,
            'personal_url': self.personal_url,
            'facebook_url': self.facebook_url,
            'instagram_url': self.instagram_url,
            'linkedIn_url': self.linkedIn_url,
            'gitHub_url': self.gitHub_url,
            'about_me': self.about_me
        }

    def is_authenticated(self):
        return True
Ejemplo n.º 10
0
class Company(UserMixin, db.Model):
    __tablename__ = 'Companies'

    id = db.Column(db.Integer, primary_key=True)
    company_name = db.Column(db.String(120), nullable=False)
    email = db.Column(db.String(120), nullable=False, unique=True)
    phone_number = db.Column(db.Text)
    password_hash = db.Column(db.String(120), nullable=False)
    location = db.Column(db.String(120)) 
    profile_picture = db.Column(db.String())
    company_url = db.Column(db.String())
    facebook_url = db.Column(db.String())
    instagram_url = db.Column(db.String())
    about_me = db.Column(db.Text)

    def __init__(self,company_name, email, phone_number, location, profile_picture, company_url, facebook_url, instagram_url, about_me):
        self.company_name = company_name
        self.email = email
        self.phone_number = phone_number
        self.location = location
        self.profile_picture = profile_picture
        self.company_url = company_url
        self.facebook_url = facebook_url
        self.instagram_url = instagram_url
        self.about_me = about_me

    def __repr__(self):
        return f"<Company Name {self.company_name}>"

    def add_new_company(new_company):
        db.session.add(new_company)
        db.session.commit()

    def delete_company(company_email):
        d = Company.delete().where(Company.email == company_email)
        d.execute()

    def get_company_name_by_id(id):
        result = db.session.query(Company.company_name).filter(Company.id==id).first()
        return result[0]
    
    def get_company_email_by_id(id):
        result = db.session.query(Company.email).filter(Company.id==id).first()
        return result[0]

    def get_company_description_by_id(id):
        result = db.session.query(Company.about_me).filter(Company.id==id).first()
        return result[0]

    def get_company_url_by_id(id):
        result = db.session.query(Company.company_url).filter(Company.id==id).first()
        return result[0]

    def get_facebook_url_by_id(id):
        result = db.session.query(Company.facebook_url).filter(Company.id==id).first()
        return result[0]

    def get_instagram_url_by_id(id):
        result = db.session.query(Company.instagram_url).filter(Company.id==id).first()
        return result[0]
    
    def get_profile_picture_by_id(id):
        result = db.session.query(Company.profile_picture).filter(Company.id==id).first()
        return result[0]

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
        
    def is_authenticated(self):
        return True
Ejemplo n.º 11
0
class Tag(db.Model):
    __tablename__ = 'tags'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    tag = db.Column(db.String(30), primary_key=False, unique=True, nullable=False)
    created_date = db.Column(db.DateTime, nullable=False, default=datetime.datetime.now())
    has_explicit = db.Column(db.Boolean, nullable=False, default=True) # has an explicit use, not just implicit tags