class User(db.Model, UserMixin): """ Basic user model """ __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(255)) email = db.Column(db.Unicode(255), unique=True) password = db.Column(db.Unicode(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) skills = db.relationship("Skill", secondary=user_skills, backref=db.backref("users", lazy='dynamic')) def __repr__(self): return "{}: {}".format(self.name, self.email) @property def _user_skills_as_set(self): """ returns student skills as set to work with it """ return set([skill.id for skill in self.skills])
class Skill(db.Model): """ Basic skill model """ __tablename__ = "skills" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(50), unique=True) description = db.Column(db.UnicodeText) logo = db.Column(db.Unicode(255)) def __repr__(self): return self.name
class Skill(db.Model): __tablename__ = "skills" #dar nombre a la db id = db.Column(db.Integer, primary_key=True) #crear columna id name = db.Column( db.Unicode(50), unique=True) #Unicode:permite representar todo tipo de data description = db.Column(db.UnicodeText) # agregar un logo para cada item logo = db.Column(db.Unicode(255)) def __repr__(self): return "{}".format(self.name)
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) # User authentication information (required for Flask-User) email = db.Column(db.Unicode(255), nullable=False, server_default=u'', unique=True) username = db.Column(db.String(80), nullable=False, server_default='') # confirmed_at = db.Column(db.DateTime()) password = db.Column(db.String(255), nullable=False, server_default='') active = db.Column(db.Boolean(), nullable=False, server_default='0') # User information active = db.Column('is_active', db.Boolean(), nullable=False, server_default='0') # Relationships roles = db.relationship('Role', secondary='user_roles', backref=db.backref('users', lazy='dynamic')) def __repr__(self): return self.username
class Company(db.Model): __tablename__ = "companies" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(100), unique=True) address = db.Column(db.Unicode(255)) phone = db.Column(db.Unicode(50)) website = db.Column(db.Unicode(255), unique=True) skills = db.relationship("Skill", secondary=company_skills, backref=db.backref("companies", lazy="dynamic")) mapa = db.Column(db.Unicode(255)) def __repr__(self): return u"{} - {}".format(self.name, self.address)
class Role(db.Model, RoleMixin): """ Basic Role model """ __tablename__ = "roles" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.Unicode(80), unique=True) description = db.Column(db.UnicodeText) def __repr__(self): return "{}: {}".format(self.name, self.description)
class NotificationContent(db.Model, Timestamp): __tablename__ = 'notification_content' id = db.Column(db.Integer, primary_key=True) type = db.Column(db.String, nullable=False) target_type = db.Column(db.Unicode(255)) target_id = db.Column(db.Integer) target = generic_relationship(target_type, target_id) # For storing state of the action target_action = db.Column(db.String)
class User(db.Model, TimestampMixin, UserMixin): # primary key id = db.Column(db.Integer, primary_key=True, autoincrement=True) # object properties username = db.Column(db.UnicodeText, nullable=False, unique=True) email = db.Column(EmailType, nullable=False, unique=True) password_hash = db.Column(db.Unicode(255), nullable=False) @property def password(self): raise AttributeError('password not readable') @password.setter def password(self, password): # bcrypt expects bytes as input self.password_hash = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8') def check_password(self, password): # bcrypt expects bytes as input return bcrypt.checkpw(password.encode('utf-8'), self.password_hash.encode('utf-8'))
class Student(db.Model): __tablename__ = "students" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(255)) last_name = db.Column(db.Unicode(255)) age = db.Column(db.Integer) email = db.Column(db.Unicode(50), unique=True) skills = db.relationship("Skill", secondary=student_skills, backref=db.backref("students", lazy="dynamic")) def __repr__(self): return "{}, {}".format(self.name, self.email) @property def _student_skills_as_set(self): """ returns student skills as set to work with it """ return set([skill.id for skill in self.skills]) def matching_companies(self): """ Returns a list of matching companiesordered by relevance """ student_skills = self._student_skills_as_set companies = db.session.query(Company).all() print companies matching_companies = [] for company in companies: company_skills = set([skill.id for skill in company.skills]) match_skills = [skill for skill in student_skills & company_skills] other_skills = [skill for skill in company_skills - student_skills] if len(match_skills) > 0: # Model lists match_skills_obj = [ db.session.query(Skill).get(skill) for skill in match_skills ] other_skills_obj = [ db.session.query(Skill).get(skill) for skill in other_skills ] match = { "model": company, "matches": len(match_skills), "skills": match_skills_obj, "other_skills": other_skills_obj } matching_companies.append(match) # sort the list by matches, most matches first from operator import itemgetter sorted_matching_companies = sorted(matching_companies, key=itemgetter('matches'), reverse=True) return sorted_matching_companies