Exemplo n.º 1
0
class Opportunity(db.Model, UserMixin):
    """table Search"""

    # positional cols
    id = db.Column(db.Integer, primary_key=True)
    company = db.Column(db.String(100), unique=False, nullable=False)
    job = db.Column(db.String(100), unique=False, nullable=False)
    plateform = db.Column(db.String(20), unique=False, nullable=False)
    url = db.Column(db.Text(1000), unique=False, nullable=False)
    loc = db.Column(
        db.String(20),
        unique=False,
        nullable=False,
    )
    applied = db.Column(db.Boolean(),
                        unique=False,
                        nullable=False,
                        default=False)  # IT IS THE ORDER
    send = db.Column(db.Boolean(), unique=False, nullable=False,
                     default=False)  # IF REALLY SENT
    text = db.Column(db.Text(1000), unique=False, nullable=False, default=".")
    created = db.Column(db.String(20),
                        unique=False,
                        nullable=False,
                        default=datetime.utcnow)

    # optionals cols
    rem = db.Column(db.String(40), unique=False, nullable=True)
    status = db.Column(db.String(20), unique=False, nullable=True)
    contract = db.Column(db.String(20), unique=False, nullable=True)

    # score
    score = db.Column(db.String(2), unique=False, nullable=True)

    # relationship
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        unique=False,
                        nullable=False)
    search_id = db.Column(db.Integer,
                          db.ForeignKey('search.id'),
                          unique=False,
                          nullable=False)

    def columns_list(self=None):
        if self:
            return [column.key for column in self.__table__.columns]
        else:
            return [column.key for column in Opportunity.__table__.columns]

    def __repr__(self):
        keys = [
            'id', 'company', 'job', 'plateform', "applied", "loc", "user_id",
            "search_id"
        ]
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt
Exemplo n.º 2
0
class Departement(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    departement = db.Column(db.String(50), unique=True, nullable=False)

    def __repr__(self):
        return self.departement

    @staticmethod
    def list_all():
        return [i.departement for i in Departement.query.all()]
Exemplo n.º 3
0
class Region(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    region = db.Column(db.String(50), unique=True, nullable=False)

    def __repr__(self):
        return self.region

    @staticmethod
    def list_all():
        return [i.region for i in Region.query.all()]
Exemplo n.º 4
0
class Job(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    job = db.Column(db.String(50), unique=True, nullable=False)

    def __repr__(self):
        return self.job

    @staticmethod
    def list_all():
        return [i.job for i in Job.query.all()]
Exemplo n.º 5
0
class Company(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    company = db.Column(db.String(50), unique=True, nullable=False)

    def __repr__(self):
        return self.company

    @staticmethod
    def list_all():
        return [i.company for i in Company.query.all()]
Exemplo n.º 6
0
class School(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    school = db.Column(db.String(50), unique=True, nullable=False)

    def __repr__(self):
        return self.school

    @staticmethod
    def list_all():
        return [i.school for i in School.query.all()]
Exemplo n.º 7
0
class Contact(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), unique=False, nullable=True)
    # topic = None
    text = db.Column(db.Text(1000), unique=False, nullable=True)
    name = db.Column(db.String(50), unique=False, nullable=True)
    email = db.Column(db.String(50), unique=False, nullable=True)
    phone = db.Column(db.String(20), unique=False, nullable=True)
    # user = db.Column(db.String(50), unique=False, nullable=True)
    created = db.Column(db.String(20),
                        unique=False,
                        nullable=False,
                        default=datetime.utcnow)

    def __repr__(self):
        keys = ['title', 'text', 'name', 'email', 'phone']
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt + "\n"
Exemplo n.º 8
0
class Features(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(10), unique=True, nullable=False)
    searchs_max = db.Column(db.String(10), unique=False, nullable=False)
    candidatures_max = db.Column(db.String(10), unique=False, nullable=False)
    plateforms_max = db.Column(db.String(10), unique=False, nullable=False)
    candidature_auto = db.Column(db.Boolean(), unique=False, nullable=False)
    opportunity_score = db.Column(db.Boolean(), unique=False, nullable=False)
    decideur_identification = db.Column(db.Boolean(),
                                        unique=False,
                                        nullable=False)
    edhunt_email = db.Column(db.Boolean(), unique=False, nullable=False)
    create_plateform_account = db.Column(db.Boolean(),
                                         unique=False,
                                         nullable=False)
    handle_external_app = db.Column(db.Boolean(), unique=False, nullable=False)
    decideur_contact = db.Column(db.Boolean(), unique=False, nullable=False)
    decideur_contact_auto = db.Column(db.Boolean(),
                                      unique=False,
                                      nullable=False)
    coach = db.Column(db.Boolean(), unique=False, nullable=False)

    # user_id = db.Column(db.Integer, db.ForeignKey('user.id'), unique=True,
    #                     nullable=False)

    def __repr__(self):
        keys = [
            'name', 'searchs_max', 'candidatures_max', "candidature_auto",
            "opportunity_score", "opportunity_score",
            "decideur_identification", "edhunt_email",
            "create_plateform_account", "handle_external_app",
            "decideur_contact", "decideur_contact_auto", "coach"
        ]
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt + "\n"
Exemplo n.º 9
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), unique=False, nullable=True)
    tags = db.Column(db.String(50), unique=False, nullable=True)
    author = db.Column(db.String(50), unique=False, nullable=True)
    text = db.Column(db.Text(1000), unique=False, nullable=True)
    created = db.Column(db.String(18),
                        unique=False,
                        nullable=True,
                        default=str(datetime.utcnow())[:16])
    source = db.Column(db.String(50), unique=False, nullable=True)
    link = db.Column(db.String(50), unique=False, nullable=True)

    @property
    def header(self):
        return str(self.text)[:140]

    def __repr__(self):
        keys = ['title', 'author', 'text', 'source', 'created']
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt + "\n"
Exemplo n.º 10
0
class Questionnaire(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    token = db.Column(db.String(34), unique=True, nullable=False)

    # FORM_1
    search = db.Column(db.Enum(*UsersEnums.search),
                       unique=False,
                       nullable=True)
    employed = db.Column(db.Enum(*UsersEnums.trooleen),
                         unique=False,
                         nullable=True)

    offer_timing = db.Column(db.Enum(*QuestionnaireEnums.timing),
                             unique=False,
                             nullable=True)
    candidature_timing = db.Column(db.Enum(*QuestionnaireEnums.timing),
                                   unique=False,
                                   nullable=True)
    call_timing = db.Column(db.Enum(*QuestionnaireEnums.timing),
                            unique=False,
                            nullable=True)
    interview_timing = db.Column(db.Enum(*QuestionnaireEnums.timing),
                                 unique=False,
                                 nullable=True)

    # FORM_2
    feat_1 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_2 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_3 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_4 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_5 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_6 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_7 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_8 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_9 = db.Column(db.Enum(*UsersEnums.trooleen),
                       unique=False,
                       nullable=True)
    feat_10 = db.Column(db.Enum(*UsersEnums.trooleen),
                        unique=False,
                        nullable=True)
    feat_11 = db.Column(db.Enum(*UsersEnums.trooleen),
                        unique=False,
                        nullable=True)
    feat_12 = db.Column(db.Enum(*UsersEnums.trooleen),
                        unique=False,
                        nullable=True)
    feat_13 = db.Column(db.Enum(*UsersEnums.trooleen),
                        unique=False,
                        nullable=True)
    feat_14 = db.Column(db.Enum(*UsersEnums.trooleen),
                        unique=False,
                        nullable=True)

    # FORM_3
    contract = db.Column(db.Enum(*UsersEnums.contract),
                         unique=False,
                         nullable=True)
    status = db.Column(db.Enum(*UsersEnums.status),
                       unique=False,
                       nullable=True)
    sector = db.Column(db.Enum(*UsersEnums.sector),
                       unique=False,
                       nullable=True)
    function = db.Column(db.Enum(*UsersEnums.function),
                         unique=False,
                         nullable=True)
    # position = db.Column(db.Enum(*UsersEnums.position), unique=False, nullable=True)
    # management = db.Column(db.Enum(*UsersEnums.management), unique=False,
    #                        nullable=True)
    rem = db.Column(db.Enum(*UsersEnums.small_rem),
                    unique=False,
                    nullable=True)
    # xp_at_work = db.Column(db.String(2), unique=False, nullable=True)
    diploma_level = db.Column(db.Enum(*UsersEnums.diploma_level),
                              unique=False,
                              nullable=True)
    # diploma_type = db.Column(db.Enum(*UsersEnums.diploma_type), unique=False,
    #                          nullable=True)
    diploma_year = db.Column(db.String(4), unique=False, nullable=True)
    zip_code = db.Column(db.String(5), unique=False, nullable=True)

    # FORM_4
    fond_already = db.Column(db.String(4), unique=False, nullable=True)
    fond_concurency = db.Column(db.String(300), unique=False, nullable=True)
    # forme_choc_level = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
    #                              unique=False, nullable=True)
    # forme_cool_level = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
    #                              unique=False, nullable=True)
    fond_compr_level = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
                                 unique=False,
                                 nullable=True)
    fond_painful_level = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
                                   unique=False,
                                   nullable=True)
    fond_interest_level = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
                                    unique=False,
                                    nullable=True)
    device_type = db.Column(db.String(50), unique=False, nullable=True)
    # device_name = db.Column(db.String(50), unique=False, nullable=True)
    remarque = db.Column(db.Text(1000), unique=False, nullable=True)

    # CONNECTION
    email = db.Column(db.String(40), unique=False, nullable=True)
    phone = db.Column(db.String(40), unique=False, nullable=True)
    hour = db.Column(db.String(40), unique=False, nullable=True)

    created = db.Column(db.String(20),
                        unique=False,
                        nullable=False,
                        default=datetime.utcnow)

    # DEPRECIATED
    # forme_generic = db.Column(db.Text(1000), unique=False, nullable=True)
    # forme_good = db.Column(db.Text(1000), unique=False, nullable=True)
    # forme_bad = db.Column(db.Text(1000), unique=False, nullable=True)
    # fond_generic = db.Column(db.Text(1000), unique=False, nullable=True)
    # fond_questions = db.Column(db.Text(1000), unique=False, nullable=True)
    # user = db.Column(db.String(50), unique=False, nullable=True)
    # device = db.Column(db.String(50), unique=False, nullable=True)
    # # offers_week = db.Column(db.String(50), unique=False, nullable=True)
    # offers_month = db.Column(db.String(50), unique=False, nullable=True)
    # offers_semester = db.Column(db.String(50), unique=False, nullable=True)
    # call_week = db.Column(db.String(50), unique=False, nullable=True)
    # call_month = db.Column(db.String(50), unique=False, nullable=True)
    # call_semester = db.Column(db.String(50), unique=False, nullable=True)
    # interview_week = db.Column(db.String(50), unique=False, nullable=True)
    # interview_month = db.Column(db.String(50), unique=False, nullable=True)
    # interview_semester = db.Column(db.String(50), unique=False, nullable=True)
    # candidaté derniereme
    # xp_at_job = db.Column(db.String(2), unique=False, nullable=True)
    # xp_at_company = db.Column(db.String(2), unique=False, nullable=True)
    # linkedin
    # dummy
    # earth = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
    #                   unique=False, nullable=True)
    # moon = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
    #                  unique=False, nullable=True)
    # marre = db.Column(db.Enum(*QuestionnaireEnums.satisfaction),
    #                   unique=False, nullable=True)

    def __repr__(self):
        keys = [
            'forme_generic', 'forme_good', 'forme_bad', 'fond_generic',
            "fond_questions", "fond_already", "forme_choc_level",
            "forme_cool_level", "fond_compr_level", "fond_interest_level",
            "user", "device"
        ]
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt + "\n"
Exemplo n.º 11
0
class Result(db.Model, UserMixin):
    """table Search"""

    # positional cols
    id = db.Column(db.Integer, primary_key=True)
    created = db.Column(db.String(20),
                        unique=False,
                        nullable=False,
                        default=datetime.utcnow)
    # name = db.Column(db.String(50), unique=False, nullable=False)
    # mob = db.Column(db.Enum(*SearchEnums.mob), unique=False, nullable=False)
    # country = db.Column(db.String(200), unique=False, nullable=True)
    # region = db.Column(db.String(200), unique=False, nullable=True)
    # departement = db.Column(db.String(200), unique=False, nullable=True)
    # town = db.Column(db.String(200), unique=False, nullable=True)
    # key_words = db.Column(db.Text(300), unique=False, nullable=False,
    #                       default=".")

    # # work status
    # contract = db.Column(db.String(200), unique=False, nullable=True)
    # employer = db.Column(db.String(200), unique=False, nullable=True)
    # status = db.Column(db.String(200), unique=False, nullable=True)
    # rem = db.Column(db.String(200), unique=False, nullable=True)
    # currency = db.Column(db.Enum(*SearchEnums.currency), unique=False,
    #                      nullable=True)
    # management = db.Column(db.Enum(*SearchEnums.booleen), unique=False,
    #                        nullable=True)

    # # Job
    company = db.Column(db.String(200), unique=False, nullable=True)
    job = db.Column(db.String(200), unique=False, nullable=True)
    # not_company = db.Column(db.String(200), unique=False, nullable=True)
    # company_size = db.Column(db.String(200), unique=False, nullable=True)
    # sector = db.Column(db.String(200), unique=False, nullable=True)
    # function = db.Column(db.Enum(*SearchEnums.function), unique=False,
    #                      nullable=True)
    # position = db.Column(db.String(200), unique=False, nullable=True)
    # not_key_words = db.Column(db.Text(300), unique=False, nullable=True)

    # # optional cols : language
    # english_mandatory = db.Column(db.String(200),
    #                               unique=False, nullable=True)
    # other_languages = db.Column(db.String(200), unique=False, nullable=True)

    # relationship
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        unique=False,
                        nullable=False)

    def columns_list(self=None):
        if self:
            return [column.key for column in self.__table__.columns]
        else:
            return [column.key for column in Search.__table__.columns]

    def __repr__(self):
        keys = ['id', 'name', 'town', 'country', "key_words", "user_id"]
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt
Exemplo n.º 12
0
class Search(db.Model, UserMixin):
    """table Search"""

    # positional cols
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=False, nullable=False)
    mob = db.Column(db.Enum(*SearchsEnums.mob), unique=False, nullable=False)
    country = db.Column(db.String(200), unique=False, nullable=True)
    region = db.Column(db.String(200), unique=False, nullable=True)
    departement = db.Column(db.String(200), unique=False, nullable=True)
    town = db.Column(db.String(200), unique=False, nullable=True)
    key_words = db.Column(db.Text(300),
                          unique=False,
                          nullable=False,
                          default=".")
    created = db.Column(db.String(20),
                        unique=False,
                        nullable=False,
                        default=datetime.utcnow)
    last_update = db.Column(db.String(20), unique=False, nullable=True)

    # work status
    contract = db.Column(db.String(200), unique=False, nullable=True)
    employer = db.Column(db.String(200), unique=False, nullable=True)
    status = db.Column(db.String(200), unique=False, nullable=True)
    rem = db.Column(db.String(200), unique=False, nullable=True)
    currency = db.Column(db.Enum(*SearchsEnums.currency),
                         unique=False,
                         nullable=True)
    management = db.Column(db.Enum(*SearchsEnums.booleen),
                           unique=False,
                           nullable=True)

    # Job
    company = db.Column(db.String(200), unique=False, nullable=True)
    not_company = db.Column(db.String(200), unique=False, nullable=True)
    company_size = db.Column(db.String(200), unique=False, nullable=True)
    job = db.Column(db.String(200), unique=False, nullable=True)
    sector = db.Column(db.String(200), unique=False, nullable=True)
    function = db.Column(db.Enum(*SearchsEnums.function),
                         unique=False,
                         nullable=True)
    position = db.Column(db.String(200), unique=False, nullable=True)
    not_key_words = db.Column(db.Text(300), unique=False, nullable=True)

    # optional cols : language
    english_mandatory = db.Column(db.String(200), unique=False, nullable=True)
    other_languages = db.Column(db.String(200), unique=False, nullable=True)

    # relationship
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        unique=False,
                        nullable=False)
    opportunities = db.relationship('Opportunity', backref='search', lazy=True)

    def columns_list(self=None):
        if self:
            return [column.key for column in self.__table__.columns]
        else:
            return [column.key for column in Search.__table__.columns]

    def __repr__(self):
        keys = ['id', 'name', 'town', 'country', "key_words", "user_id"]
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt

    @property
    def search_fields(self):
        keys = [
            "contract", "employer", "status", "rem", "management", "company",
            "not_company", "company_size", "job", "sector", "function",
            "position", "not_key_words", "english_mandatory", "other_languages"
        ]
        vals = [getattr(self, k) for k in keys]
        labels = [
            "Contrat", "Employeur", "Status", "Rémuneration", "Mangement",
            "Entr. souhaitée(s)", "Entr. évitée(s)", "Taille", "Poste",
            "Secteur", "Fonction", "Position hiéarchique", "Mots clés évités",
            "Anglais souhaité", "Autres Langue"
        ]
        return zip(labels, vals)

    @property
    def search_fields2(self):
        keys = [
            'name', "key_words", "contract", "employer", "status", "rem",
            "management", "company", "not_company", "company_size", "job",
            "sector", "function", "position", "not_key_words",
            "english_mandatory", "other_languages"
        ]
        vals = [getattr(self, k) for k in keys]
        labels = [
            'Nom', "Mots Clés", "Contrat", "Employeur", "Status",
            "Rémuneration", "Mangement", "Entr. souhaitée(s)",
            "Entr. évitée(s)", "Taille", "Poste", "Secteur", "Fonction",
            "Position hiéarchique", "Mots clés évités", "Anglais souhaité",
            "Autres Langue"
        ]

        l1 = [(k, (v if v else "-")) for k, v in zip(labels, vals)]
        l2 = list()
        for i, data in enumerate(l1):
            if not i % 2:
                try:
                    l2.append((l1[i][0], l1[i][1], l1[i + 1][0], l1[i + 1][1]))
                except Exception as e:
                    l2.append((l1[i][0], l1[i][1], "", ""))
        return l2

    @property
    def search_fields_text(self):
        txt = ""
        for k, v in self.search_fields:
            txt += f"{k} : {v if v else '-'};  "
        return txt

    @property
    def opportunities_count(self):
        opps = Opportunity.query.filter_by(search_id=self.id).all()
        return len(opps)

    @property
    def candidatures_count(self):
        opps = Opportunity.query.filter_by(search_id=self.id).all()
        opps = [i for i in opps if i.send]
        return len(opps)

    @property
    def global_score(self):
        vals = [
            getattr(self, k) for k in self.columns_list() if getattr(self, k)
        ]
        n = round(len(vals) * 100 / len(self.columns_list()))
        return n

    @property
    def essentiel_keys(self):
        keys = ["name", "key_words", 'mob', 'created', 'last_update']
        return keys

    @property
    def essentiel_score(self):
        vals = [
            getattr(self, k) for k in self.essentiel_keys if getattr(self, k)
        ]
        n = round(len(vals) * 100 / len(self.essentiel_keys))
        return n

    @property
    def essentiel_fields(self):
        vals = [getattr(self, k) for k in self.essentiel_keys]
        vals = [(i if i else '-') for i in vals]
        labels = ['Nom', 'Mots Clés', 'Mobilité', 'Créée', 'Dernière MAJ']
        return zip(labels, vals)

    @property
    def job_keys(self):
        keys = [
            "company", "not_company", 'company_size', 'job', 'sector',
            'function', 'position', 'not_key_words'
        ]
        return keys

    @property
    def job_score(self):
        vals = [getattr(self, k) for k in self.job_keys if getattr(self, k)]
        n = round(len(vals) * 100 / len(self.job_keys))
        return n

    @property
    def job_fields(self):
        vals = [getattr(self, k) for k in self.job_keys]
        vals = [(i if i else '-') for i in vals]
        labels = [
            'Entreprise(s) souhaitée(s)', 'Entreprise(s) évitée(s)', 'Taille',
            'Poste', 'Secteur', "Fonction", 'Position', 'Mots clés évités'
        ]
        return zip(labels, vals)

    @property
    def status_keys(self):
        keys = [
            "contract", "employer", 'status', 'rem', 'currency', 'management'
        ]
        return keys

    @property
    def status_score(self):
        vals = [getattr(self, k) for k in self.status_keys if getattr(self, k)]
        n = round(len(vals) * 100 / len(self.status_keys))
        return n

    @property
    def status_fields(self):
        vals = [getattr(self, k) for k in self.status_keys]
        vals = [(i if i else '-') for i in vals]
        labels = [
            'Contrat(s)', "Type d'employeur(s)", 'Status', 'Rémuneration',
            'Monnaie', "Management"
        ]
        return zip(labels, vals)

    @property
    def language_keys(self):
        keys = ["english_mandatory", 'other_languages']
        return keys

    @property
    def language_score(self):
        vals = [
            getattr(self, k) for k in self.language_keys if getattr(self, k)
        ]
        n = round(len(vals) * 100 / len(self.language_keys))
        return n

    @property
    def language_fields(self):
        vals = [getattr(self, k) for k in self.language_keys]
        vals = [(i if i else '-') for i in vals]
        labels = ["Niveau d'Anglais", "Autres langues"]
        return zip(labels, vals)
Exemplo n.º 13
0
def col_password():
    return db.Column(db.String(40), unique=False, nullable=True)
Exemplo n.º 14
0
def col_email():
    return db.Column(db.String(40), unique=True, nullable=True)
Exemplo n.º 15
0
class User(db.Model, UserMixin):
    # account
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(40), unique=True, nullable=False)
    email = db.Column(db.String(40), unique=False, nullable=False)
    password = db.Column(db.String(40), unique=False, nullable=False)
    created = db.Column(db.String(40),
                        unique=False,
                        nullable=False,
                        default=datetime.utcnow)

    # expectations
    employed = db.Column(db.Enum(*UsersEnums.trooleen),
                         unique=False,
                         nullable=True)
    sub_employed = db.Column(db.Enum(*UsersEnums.sub_employed),
                             unique=False,
                             nullable=True)
    search = db.Column(db.Enum(*UsersEnums.search),
                       unique=False,
                       nullable=True)
    order = db.Column(db.Enum(*UsersEnums.order), unique=False, nullable=True)
    automation = db.Column(db.Enum(*UsersEnums.automation),
                           unique=False,
                           nullable=True)

    # resumes
    resume1_doc = db.Column(db.String(40), nullable=True, unique=True)
    resume1_name = db.Column(db.String(40),
                             nullable=False,
                             unique=False,
                             default="no resume")
    resume2_doc = db.Column(db.String(40), nullable=True, unique=True)
    resume2_name = db.Column(db.String(40),
                             nullable=False,
                             unique=False,
                             default="no resume")
    resume3_doc = db.Column(db.String(40), nullable=True, unique=True)
    resume3_name = db.Column(db.String(40),
                             nullable=False,
                             unique=False,
                             default="no resume")

    # identity
    firstname = db.Column(db.String(40), unique=False, nullable=True)
    lastname = db.Column(db.String(40), unique=False, nullable=True)
    sex = db.Column(db.Enum(*UsersEnums.sex), unique=False, nullable=True)
    birthdate = db.Column(db.String(12), unique=False, nullable=True)
    nationality = db.Column(db.String(50), unique=False, nullable=True)
    birth_country = db.Column(db.String(50), unique=False, nullable=True)
    birth_zip_code = db.Column(db.String(5), unique=False, nullable=True)
    birth_town = db.Column(db.String(50), unique=False, nullable=True)

    # localisation
    town = db.Column(db.String(50), unique=False, nullable=True)
    zip_code = db.Column(db.String(5), unique=False, nullable=True)
    country = db.Column(db.String(50), unique=False, nullable=True)
    driver_licence = db.Column(db.Enum(*UsersEnums.trooleen),
                               unique=False,
                               nullable=True)
    vehicule = db.Column(db.Enum(*UsersEnums.trooleen),
                         unique=False,
                         nullable=True)

    # diploma
    diploma_name = db.Column(db.String(50), unique=False, nullable=True)
    diploma_school = db.Column(db.String(50), unique=False, nullable=True)
    diploma_town = db.Column(db.String(50), unique=False, nullable=True)
    diploma_level = db.Column(db.Enum(*UsersEnums.diploma_level),
                              unique=False,
                              nullable=True)
    diploma_type = db.Column(db.Enum(*UsersEnums.diploma_type),
                             unique=False,
                             nullable=True)
    diploma_year = db.Column(db.String(4), unique=False, nullable=True)

    # work experience
    company = db.Column(db.String(50), unique=False, nullable=True)
    xp_at_company = db.Column(db.String(2), unique=False, nullable=True)
    company_size = db.Column(db.Enum(*UsersEnums.company_size),
                             unique=False,
                             nullable=True)
    job = db.Column(db.String(50), unique=False, nullable=True)
    xp_at_job = db.Column(db.String(2), unique=False, nullable=True)
    sector = db.Column(db.Enum(*UsersEnums.sector),
                       unique=False,
                       nullable=True)
    function = db.Column(db.Enum(*UsersEnums.function),
                         unique=False,
                         nullable=True)
    position = db.Column(db.Enum(*UsersEnums.position),
                         unique=False,
                         nullable=True)
    mob = db.Column(db.Enum(*UsersEnums.mob), unique=False, nullable=True)
    key_words = db.Column(db.Text(300), unique=False, nullable=True)

    # work status
    contract = db.Column(db.Enum(*UsersEnums.contract),
                         unique=False,
                         nullable=True)
    employer = db.Column(db.Enum(*UsersEnums.employer),
                         unique=False,
                         nullable=True)
    status = db.Column(db.Enum(*UsersEnums.status),
                       unique=False,
                       nullable=True)
    rem = db.Column(db.Enum(*UsersEnums.small_rem),
                    unique=False,
                    nullable=True)
    currency = db.Column(db.Enum(*UsersEnums.currency),
                         unique=False,
                         nullable=True)
    management = db.Column(db.Enum(*UsersEnums.management),
                           unique=False,
                           nullable=True)
    xp_at_work = db.Column(db.String(2), unique=False, nullable=True)

    # languages
    english = db.Column(db.Enum(*UsersEnums.english),
                        unique=False,
                        nullable=True)
    others = db.Column(db.String(100), unique=False, nullable=True)

    # admin
    last_connexion = db.Column(db.String(20), unique=False, nullable=True)
    connexions_all = db.Column(db.SmallInteger(),
                               unique=False,
                               nullable=True,
                               default=0)
    connexions_this_week = db.Column(db.SmallInteger(),
                                     unique=False,
                                     nullable=True,
                                     default=0)
    connexions_this_month = db.Column(db.SmallInteger(),
                                      unique=False,
                                      nullable=True,
                                      default=0)
    features = db.Column(db.String(10), unique=False, nullable=True)
    features_stop_day = db.Column(db.String(10), unique=False, nullable=True)
    auto_test_plateforms = db.Column(db.Boolean(), unique=False, nullable=True)
    auto_update_searchs = db.Column(db.Boolean(), unique=False, nullable=True)

    # plateforms
    # apec = Joboard.status()
    # apec_email = Joboard.email()
    # apec_password = Joboard.password()
    # apec_autorisation = Joboard.autorisation()
    # apec_good_user = Joboard.good_user()
    # apec_edhunt_integrity = Joboard.edhunt_integrity()

    # cadremploi = Joboard.status()
    # cadremploi_email = Joboard.email()
    # cadremploi_password = Joboard.password()
    # cadremploi_autorisation = Joboard.autorisation()
    # cadremploi_good_user = Joboard.good_user()
    # cadremploi_edhunt_integrity = Joboard.edhunt_integrity()

    # indeed = Joboard.status()
    # indeed_email = Joboard.email()
    # indeed_password = Joboard.password()
    # indeed_autorisation = Joboard.autorisation()
    # indeed_good_user = Joboard.good_user()
    # indeed_edhunt_integrity = Joboard.edhunt_integrity()

    # jobintree = Joboard.status()
    # jobintree_email = Joboard.email()
    # jobintree_password = Joboard.password()
    # jobintree_autorisation = Joboard.autorisation()
    # jobintree_good_user = Joboard.good_user()
    # jobintree_edhunt_integrity = Joboard.edhunt_integrity()

    # keljob = Joboard.status()
    # keljob_email = Joboard.email()
    # keljob_password = Joboard.password()
    # keljob_autorisation = Joboard.autorisation()
    # keljob_good_user = Joboard.good_user()
    # keljob_edhunt_integrity = Joboard.edhunt_integrity()

    # leboncoin = Joboard.status()
    # leboncoin_email = Joboard.email()
    # leboncoin_password = Joboard.password()
    # leboncoin_autorisation = Joboard.autorisation()
    # leboncoin_good_user = Joboard.good_user()
    # leboncoin_edhunt_integrity = Joboard.edhunt_integrity()

    # lesjeudis = Joboard.status()
    # lesjeudis_email = Joboard.email()
    # lesjeudis_password = Joboard.password()
    # lesjeudis_autorisation = Joboard.autorisation()
    # lesjeudis_good_user = Joboard.good_user()
    # lesjeudis_edhunt_integrity = Joboard.edhunt_integrity()

    # linkedin = Joboard.status()
    # linkedin_email = Joboard.email()
    # linkedin_password = Joboard.password()
    # linkedin_autorisation = Joboard.autorisation()
    # linkedin_good_user = Joboard.good_user()
    # linkedin_edhunt_integrity = Joboard.edhunt_integrity()

    # meteojob = Joboard.status()
    # meteojob_email = Joboard.email()
    # meteojob_password = Joboard.password()
    # meteojob_autorisation = Joboard.autorisation()
    # meteojob_good_user = Joboard.good_user()
    # meteojob_edhunt_integrity = Joboard.edhunt_integrity()

    # monster = Joboard.status()
    # monster_email = Joboard.email()
    # monster_password = Joboard.password()
    # monster_autorisation = Joboard.autorisation()
    # monster_good_user = Joboard.good_user()
    # monster_edhunt_integrity = Joboard.edhunt_integrity()

    # polemploi = Joboard.status()
    # polemploi_email = Joboard.email()
    # polemploi_password = Joboard.password()
    # polemploi_autorisation = Joboard.autorisation()
    # polemploi_good_user = Joboard.good_user()
    # polemploi_edhunt_integrity = Joboard.edhunt_integrity()

    # regionjob = Joboard.status()
    # regionjob_email = Joboard.email()
    # regionjob_password = Joboard.password()
    # regionjob_autorisation = Joboard.autorisation()
    # regionjob_good_user = Joboard.good_user()
    # regionjob_edhunt_integrity = Joboard.edhunt_integrity()

    # relationship
    searchs = db.relationship('Search', backref='user', lazy=True)
    opportunities = db.relationship('Opportunity', backref='user', lazy=True)

    # features = db.relationship('Features', backref='user')
    apec = db.relationship('Apec', backref='user')
    cadremploi = db.relationship('Cadremploi', backref='user')
    indeed = db.relationship('Indeed', backref='user')
    jobintree = db.relationship('Jobintree', backref='user')
    keljob = db.relationship('Keljob', backref='user')
    # leboncoin = db.relationship('Leboncoin', backref='user')
    lesjeudis = db.relationship('Lesjeudis', backref='user')
    meteojob = db.relationship('Meteojob', backref='user')
    monster = db.relationship('Monster', backref='user')
    regionjob = db.relationship('Regionjob', backref='user')

    def __repr__(self):
        keys = ['id', 'username', 'email', 'password']
        txt = "\n".join([
            str(key.ljust(20, " ") + ": " + str(self.__dict__[key]))
            for key in keys
        ])
        return "\n" + txt

    def columns_list(self=None):
        """return all field of User Table"""

        if self:
            return [column.key for column in self.__table__.columns]
        else:
            return [column.key for column in User.__table__.columns]

    def _compute_score(self, keys):
        filed = [getattr(self, k) for k in keys]
        filed = [k for k in filed if (k and (k != '-'))]
        l_filed, l_keys = len(filed), len(keys)
        return f"{l_filed * 100 / l_keys:.0f}"

    def _give_vals(self, keys):
        return [getattr(self, k) for k in keys]

    @property
    def profile_score(self):
        """return a % of field info for a User"""

        keys = [
            'username', 'email', 'password', 'created', 'employed',
            'sub_employed', 'search', 'order', 'automation', 'resume1_doc',
            'resume2_doc', 'resume3_doc', 'firstname', 'lastname', 'sex',
            'birthdate', 'nationality', 'birth_country', 'birth_zip_code',
            'birth_town', 'town', 'zip_code', 'country', 'driver_licence',
            'vehicule', 'diploma_name', 'diploma_school', 'diploma_town',
            'diploma_level', 'diploma_type', 'diploma_year', 'company',
            'xp_at_company', 'company_size', 'job', 'xp_at_job', 'sector',
            'function', 'position', 'mob', 'key_words', 'contract', 'employer',
            'status', 'rem', 'currency', 'management', 'xp_at_work', 'english',
            'others'
        ]

        return self._compute_score(keys)

    # def plateform_list(self):
    #     return ["apec", "cadremploi", 'indeed', 'jobintree', 'keljob',
    #             'leboncoin', 'lesjeudis', 'meteojob', 'monster',
    #             'polemploi', 'regionjob']

    # def joboard_score(self):
    #     #     """return a % of field info for a joboards"""

    #     #     keys = ["apec", "cadremploi", 'indeed', 'jobintree', 'keljob',
    #     #             'leboncoin', 'lesjeudis', 'meteojob', 'monster',
    #     #             'polemploi', 'regionjob']
    #     #     filed = [self.__dict__[i] for i in keys if self.__dict__[i] == "On"]
    #     #     l_filed, l_keys = len(filed), len(keys)
    #     #     return f"{l_filed}/{l_keys}"

    #     return "122"

    # Resume
    @property
    def resume_keys(self):
        return ['resume1_name', 'resume2_name', 'resume3_name']

    @property
    def resume_fields(self):
        labels = ["CV n°1", "CV n°2", "CV n°3"]
        return zip(labels, self._give_vals(self.resume_keys))

    @property
    def resume_score(self):
        keys = [
            'resume1_doc',
            'resume2_doc',
            'resume3_doc',
        ]
        return self._compute_score(keys)

    # expectation
    @property
    def expectation_keys(self):
        return ['employed', 'sub_employed', 'search', 'order', 'automation']

    @property
    def expectation_fields(self):
        labels = [
            'En poste', 'Disponible', 'Situation', 'Attentes', 'Candidatures'
        ]
        return zip(labels, self._give_vals(self.expectation_keys))

    @property
    def expectation_score(self):
        return self._compute_score(self.expectation_keys)

    # identification
    @property
    def identification_keys(self):
        return [
            'firstname', 'lastname', 'sex', 'birthdate', 'nationality',
            'birth_country', 'birth_zip_code', 'birth_town'
        ]

    @property
    def identification_fields(self):
        labels = [
            'Prénom', 'Nom', 'Sexe', 'Date de naissance', 'Nationalité',
            "Pays de naissance", 'Code Postal', "Ville de naissance"
        ]
        return zip(labels, self._give_vals(self.identification_keys))

    @property
    def identification_score(self):
        return self._compute_score(self.identification_keys)

    # localisation
    @property
    def localisation_keys(self):
        return ['town', 'zip_code', 'country', 'driver_licence', 'vehicule']

    @property
    def localisation_fields(self):
        labels = [
            'Ville',
            'Code postal',
            'Pays',
            'Permis',
            'Véhicule',
        ]
        return zip(labels, self._give_vals(self.localisation_keys))

    @property
    def localisation_score(self):
        return self._compute_score(self.localisation_keys)

    # diploma
    @property
    def diploma_keys(self):
        return [
            'diploma_name', 'diploma_school', 'diploma_town', 'diploma_level',
            'diploma_type', 'diploma_year'
        ]

    @property
    def diploma_fields(self):
        labels = ['Nom', 'Ecole', 'Ville', 'Niveau', 'Type', 'Année']
        return zip(labels, self._give_vals(self.diploma_keys))

    @property
    def diploma_score(self):
        return self._compute_score(self.diploma_keys)

    # work_experience
    @property
    def work_experience_keys(self):
        return [
            'company', 'xp_at_company', 'company_size', 'job', 'xp_at_job',
            'sector', 'function', 'position', 'mob', 'key_words'
        ]

    @property
    def work_experience_fields(self):
        labels = [
            "Entreprise", 'Experience en entr.', "Taille d'entr.", "Poste",
            "Experience à ce poste", 'Secteur', 'Fonction',
            'Position hiérarchique', 'Mobilité', 'Mots clés'
        ]
        return zip(labels, self._give_vals(self.work_experience_keys))

    @property
    def work_experience_score(self):
        return self._compute_score(self.work_experience_keys)

    # work_status
    @property
    def work_status_keys(self):
        return [
            'contract', 'employer', 'status', 'rem', 'currency', 'management',
            'xp_at_work'
        ]

    @property
    def work_status_fields(self):
        labels = [
            "Contrat", "Type d'entr.", "Statut", "Salaire", "Monnaie",
            'Management', 'Experience prof.'
        ]
        return zip(labels, self._give_vals(self.work_experience_keys))

    @property
    def work_status_score(self):
        return self._compute_score(self.work_status_keys)

    # language
    @property
    def language_keys(self):
        return ['english', 'others']

    @property
    def language_fields(self):
        labels = ["Anglais", "Autres"]
        return zip(labels, self._give_vals(self.language_keys))

    @property
    def language_score(self):
        return self._compute_score(self.language_keys)

    @property
    def plateform_score(self):
        plateforms = [
            getattr(Plateforms.tables,
                    p).query.filter_by(user_id=self.id).first()
            for p in Plateforms.list_all
        ]
        plateforms = [i for i in plateforms if i]
        connexions = [i for i in plateforms if i.connexion == "On"]
        score = round(100 * len(connexions) / len(Plateforms.list_all))
        return score

    def avialable_plateforms(self):
        plateforms = [
            getattr(Plateforms.tables,
                    p).query.filter_by(user_id=self.id).first()
            for p in Plateforms.list_all
        ]
        plateforms = [i for i in plateforms if i]
        connexions = [i for i in plateforms if i.connexion == "On"]

        return [i.__name__ for i in connexions]

    @property
    def opportunities_count(self):
        li = Opportunity.query.filter_by(user_id=self.id).all()
        return len(li)

    @property
    def candidatures_count(self):
        li = Opportunity.query.filter_by(user_id=self.id).all()
        li = [i for i in li if i.send]
        return len(li)

    @property
    def opportunities_max(self):
        return 100

    @property
    def candidatures_max(self):
        return 100

    @property
    def pistes_max(self):
        return 100

    @property
    def searchs_max(self):
        return 3