Ejemplo n.º 1
0
class ManageEvaluations(db.Model):
    """
        Modelo de la tabla Gestor de Evaluaciones
    """

    # Nombre de la tabla
    __tablename__ = 'manage_evaluations'

    # Columnas
    id_manage_evaluation = db.Column(
                UUID(as_uuid = True),
                primary_key = True,
                default = uuid.uuid4(),
                unique = True,
                nullable = True
            )

    quantity = db.Column(
                db.Integer,
                default = 0,
                nullable = True
            )

    date_last_evaluation = db.Column(
                db.DateTime,
                default = datetime.now(),
                nullable = True
            )
 
    def __init__(self):
        self.id_manage_evaluation = uuid.uuid4()
        self.quantity = 0
        self.date_last_evaluation = datetime.now()
        self.id_manage_evaluation = uuid.uuid4()

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

    def save(self):
        db.session.add(self)
        db.session.commit()

    def update(self):
        self.quantity += 1
        self.date_last_evaluation = datetime.now()
        db.session.commit()

    @staticmethod
    def delete(id: uuid.UUID):
        return ManageEvaluations.query.filter_by(id_manage_evaluation = id).delete()

    @staticmethod
    def by_id(id: uuid.UUID):
        return ManageEvaluations.query.filter_by(id_manage_evaluation = id).first()

    @staticmethod
    def by_all():
        return ManageEvaluations.query.all()
Ejemplo n.º 2
0
class User(db.Model):

    # Declarar el nombre de la tabla
    __tablename__ = 'users'

    # Declarar los parametros
    id = db.Column(db.Integer, nullable=True, unique=True, primary_key=True)
    username = db.Column(db.String(15), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=True)
    password = db.Column(db.String(150), nullable=False)
    is_admin = db.Column(db.Boolean, default=False)
    # Foreign Key
    surverys = db.relationship('Surverys')

    def __init__(self, username: str, email: str):
        self.username = username
        self.email = email

    def __repr__(self):
        return f'<User {self.username}>'

    def encrypt_password(self, password: str):
        self.password = bcrypt.generate_password_hash(password).decode('utf-8')

    def check_password(self, password: str):
        return bcrypt.check_password_hash(self.password, password)

    def save(self):
        if not self.id:
            db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    # Metodos para obtener un User
    @staticmethod
    def get_by_id(id: int):
        return User.query.filter_by(id=id).first()

    @staticmethod
    def get_by_email(email: str):
        return User.query.filter_by(email=email).first()

    def get_all_survery_by_id(id: int):
        return Surverys.query.join(User).filter(Surverys.user_id == id).all()

    @staticmethod
    def get_all():
        return User.query.all()
Ejemplo n.º 3
0
class Tasks(db.Model):
    """
        Modelo de la tabla Tareas
    """

    # Nombre de la tabla
    __tablename__ = 'tasks'

    # Columnas
    id_task = db.Column(UUID(as_uuid=True),
                        primary_key=True,
                        default=uuid.uuid4(),
                        unique=True,
                        nullable=True)

    managers = db.Column(db.Integer, nullable=True)

    date_task = db.Column(db.DateTime, default=datetime.now(), nullable=True)

    id_team_leader = db.Column(UUID(as_uuid=True), )

    def __init__(self, managers: list, date_task: datetime,
                 id_team_leader: uuid.UUID):
        self.id_task = uuid.uuid4()
        self.managers = managers
        self.date_task = date_task
        self.id_team_leader = id_team_leader

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

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    @staticmethod
    def by_id(id: uuid.UUID):
        return Tasks.query.filter_by(id_task=id).first()

    @staticmethod
    def by_team_leader(id_team_leader: uuid.UUID):
        return Tasks.query.filter_by(id_team_leader=id_team_leader).all()

    @staticmethod
    def by_all():
        return Tasks.query.all()
Ejemplo n.º 4
0
class Employees(db.Model):
    """
        Modelo de la tabla empleados
    """

    # Nombre de la tabla
    __tablename__ = 'employees'

    # Columnas
    id_employees = db.Column(
                UUID(as_uuid = True),
                primary_key = True,
                default = uuid.uuid4(),
                unique = True,
                nullable = True
            )

    name = db.Column(
                db.String(15),
                nullable = True
            )

    last_name = db.Column(
                db.String(15),
                nullable = True
            )
 
    def __init__(self, name: str, last_name: str):
        self.id_employees = uuid.uuid4()
        self.name = name
        self.last_name = last_name

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

    def save(self):
        db.session.add(self)
        db.session.commit()

    @staticmethod
    def delete(id: uuid.UUID):
        return Employees.query.filter_by(id_employees = id).delete()

    @staticmethod
    def by_id(id: uuid.UUID):
        return Employees.query.filter_by(id_employees = id).first()

    @staticmethod
    def by_all():
        return Employees.query.all()
Ejemplo n.º 5
0
class Answers(db.Model):
    __tablename__ = 'answers'

    id = db.Column(db.Integer, nullable=True, unique=True, primary_key=True)
    user = db.Column(db.String, nullable=True)
    answer = db.Column(db.Integer, nullable=True)
    answer_date = db.Column(db.DateTime,
                            nullable=True,
                            default=datetime.datetime.now)
    # Foreign Key
    survery_id = db.Column(db.Integer, db.ForeignKey('surverys.id'))

    def __init__(self, user: str, answer_date: datetime, answer: int,
                 survery_id: int):
        self.user = user
        self.survery_id = survery_id
        self.answer_date = answer_date
        self.answer = answer

    def save(self) -> dict:
        # Obtener Encuesta
        survery = Surverys.get_survery_by_id(self.survery_id)

        # Obtener fechas limites y fecha actual
        deadline = survery.deadline
        date_now = datetime.datetime.combine(datetime.date.today(),
                                             datetime.time(0, 0))

        # Comprobar si la fecha caduco
        if deadline >= date_now:
            if not self.id:
                db.session.add(self)
            db.session.commit()

            response = {'error': False, 'msg': 'Respuestas Guardadas!'}
            return response
        else:
            response = {'error': True, 'msg': 'La encueta ya caduco!'}
            return response

    @staticmethod
    def get_answers_of_survery(survery_id: int):
        return Answers.query.join(Surverys).filter(
            Surverys.id == survery_id).all()
Ejemplo n.º 6
0
class Category(db.Model):
    """
        Modelo de la tabla Categoria
    """

    # Nombre de la tabla
    __tablename__ = 'category'

    # Columnas
    id_category = db.Column(UUID(as_uuid=True),
                            primary_key=True,
                            default=uuid.uuid4(),
                            unique=True,
                            nullable=True)

    category = db.Column(db.String(20), nullable=True)

    def __init__(self, category: str):
        self.id_category = uuid.uuid4()
        self.category = category

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

    def save(self):
        db.session.add(self)
        db.session.commit()

    @staticmethod
    def by_id(id: uuid.UUID):
        return Category.query.filter_by(id_category=id).first()

    @staticmethod
    def by_category(category: str):
        return Category.query.filter_by(category=category).first()

    @staticmethod
    def by_all():
        return Category.query.all()
Ejemplo n.º 7
0
class Evaluations(db.Model):
    """
        Modelo para la tabla Evaluaciones
    """

    # Nombre de la tabla
    __tablaname__ = "evaluations"

    # Columnas
    id_evaluations = db.Column(UUID(as_uuid=True),
                               primary_key=True,
                               default=uuid.uuid4(),
                               unique=True,
                               nullable=True)

    observations = db.Column(db.Text, nullable=True)

    corrections = db.Column(db.ARRAY(String), nullable=True)

    # Foreign Key
    id_data_evaluation = db.Column(UUID(as_uuid=True))

    id_results_evaluation = db.Column(UUID(as_uuid=True), )

    id_users = db.Column(UUID(as_uuid=True), )

    def __init__(self, observations: str, corrections: list,
                 id_data_evaluation: uuid.UUID,
                 id_results_evaluation: uuid.UUID, id_user: uuid.UUID):
        self.observations = observations
        self.corrections = corrections
        self.id_data_evaluation = id_data_evaluation
        self.id_results_evaluation = id_results_evaluation
        self.id_users = id_user
        self.id_evaluations = uuid.uuid4()

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

    def save(self):
        db.session.add(self)
        db.session.commit()

    @staticmethod
    def by_id_user(id_user: uuid.UUID):
        return Evaluations.query.filter_by(id_users=id_user).all()

    @staticmethod
    def by_id(id: uuid.UUID):
        return Evaluations.query.filter_by(id_evaluations=id).first()

    @staticmethod
    def by_all():
        return Evaluations.query.all()
Ejemplo n.º 8
0
class Surverys(db.Model):

    __tablename__ = 'surverys'

    id = db.Column(db.Integer, nullable=True, unique=True, primary_key=True)
    name_survery = db.Column(db.String(30), nullable=True)
    questions = db.Column(db.ARRAY(String), nullable=True)
    answers_correct = db.Column(db.ARRAY(Integer), nullable=True)
    deadline = db.Column(db.DateTime, nullable=True)
    created_date = db.Column(db.DateTime,
                             nullable=True,
                             default=datetime.datetime.now)
    labels = db.Column(db.ARRAY(String), nullable=True)
    # Foreign Key
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    answers = db.relationship('Answers')

    def __init__(self, name_survery: str, questions: list,
                 answers_correct: list, deadline: datetime, labels: list,
                 user_id: int):
        self.name_survery = name_survery
        self.questions = questions
        self.answers_correct = answers_correct
        self.deadline = deadline
        self.labels = labels
        self.user_id = user_id

    def save(self) -> str:
        if not self.id:
            db.session.add(self)
        db.session.commit()
        return 'Se guardo la encuesta correctamente!'

    @staticmethod
    def get_survery_by_id(id: int):
        return Surverys.query.filter_by(id=id).first()

    @staticmethod
    def get_survery_all():
        return Surverys.query.all()
Ejemplo n.º 9
0
class Users(db.Model):
    """
        Modelo de la tabla Usuarios
    """

    # Nombre de la tabla
    __tablename__ = 'users'

    # Columnas
    id_users = db.Column(UUID(as_uuid=True),
                         primary_key=True,
                         default=uuid.uuid4(),
                         unique=True,
                         nullable=True)

    internal_user = db.Column(db.Integer, nullable=True)

    username = db.Column(db.Integer, nullable=True)

    password = db.Column(db.String(150), nullable=True)

    created_user = db.Column(db.DateTime,
                             default=datetime.now(),
                             nullable=True)

    # Foreign Key
    id_employees = db.Column(UUID(as_uuid=True))

    id_category = db.Column(UUID(as_uuid=True))

    id_manage_evaluation = db.Column(UUID(as_uuid=True))

    def __init__(self, internal_user: int, username: int,
                 id_employees: uuid.UUID, id_category: uuid.UUID,
                 id_manage_evaluation: uuid.UUID):
        self.id_users = uuid.uuid4()
        self.internal_user = internal_user
        self.username = username
        self.created_user = datetime.now()
        self.id_employees = id_employees
        self.id_category = id_category
        self.id_manage_evaluation = id_manage_evaluation

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

    def encrypt_password(self, password: str):
        self.password = bcrypt.generate_password_hash(password).decode('utf-8')

    def validate_password(self, password: str):
        return bcrypt.check_password_hash(self.password, password)

    def save(self):
        db.session.add(self)
        db.session.commit()

    @staticmethod
    async def delete(id: uuid.UUID):
        await Employees.delete(Users.id_employees)
        await ManageEvaluations.delete(Users.id_manage_evaluation)
        return Users.query.filter_by(id_users=id).delete()

    @staticmethod
    def by_id(id: uuid.UUID):
        return Users.query.filter_by(id_users=id).first()

    @staticmethod
    def by_username(username: int):
        return Users.query.filter_by(username=username).first()

    @staticmethod
    def by_all():
        return Users.query.all()
Ejemplo n.º 10
0
class ResultsEvaluation(db.Model):
    """
        Modelo de la tabla Resultados de Evaluacion
    """

    # Nombre de la tabla
    __tablename__ = 'results_evaluation'

    # Columnas
    id_results_evaluation = db.Column(UUID(as_uuid=True),
                                      primary_key=True,
                                      default=uuid.uuid4(),
                                      unique=True,
                                      nullable=True)

    salute = db.Column(db.Numeric(precision=8,
                                  asdecimal=False,
                                  decimal_return_scale=None),
                       nullable=True)

    attitude = db.Column(db.Numeric(precision=8,
                                    asdecimal=False,
                                    decimal_return_scale=None),
                         nullable=True)

    negotiation_one = db.Column(db.Numeric(precision=8,
                                           asdecimal=False,
                                           decimal_return_scale=None),
                                nullable=True)

    negotiation_two = db.Column(db.Numeric(precision=8,
                                           asdecimal=False,
                                           decimal_return_scale=None),
                                nullable=True)

    registration_one = db.Column(db.Numeric(precision=8,
                                            asdecimal=False,
                                            decimal_return_scale=None),
                                 nullable=True)

    registration_two = db.Column(db.Numeric(precision=8,
                                            asdecimal=False,
                                            decimal_return_scale=None),
                                 nullable=True)

    message = db.Column(db.Numeric(precision=8,
                                   asdecimal=False,
                                   decimal_return_scale=None),
                        default=None,
                        nullable=True)

    closing = db.Column(db.Numeric(precision=8,
                                   asdecimal=False,
                                   decimal_return_scale=None),
                        default=None,
                        nullable=True)

    result = db.Column(db.Numeric(precision=8,
                                  asdecimal=False,
                                  decimal_return_scale=None),
                       nullable=True)

    def __init__(self, salute: float, attitude: float, negotiation_one: float,
                 negotiation_two: float, registration_one: float,
                 registration_two: float, result: float):
        self.salute = salute
        self.attitude = attitude
        self.negotiation_one = negotiation_one
        self.negotiation_two = negotiation_two
        self.registration_one = registration_one
        self.registration_two = registration_two
        self.result = result
        self.id_results_evaluation = uuid.uuid4()

    def save(self, message: float = None, closing: float = None):
        if message == None:
            self.closing = closing
            self.message = message
            db.session.add(self)
            db.session.commit()
        elif message != None:
            self.message = message
            self.closing = closing
            db.session.add(self)
            db.session.commit()

    @staticmethod
    def by_id(id: uuid.UUID):
        return ResultsEvaluation.query.filter_by(
            id_results_evaluation=id).first()

    @staticmethod
    def by_all():
        return ResultsEvaluation.query.all()
Ejemplo n.º 11
0
class DataEvaluations(db.Model):
    """
        Modelo de la tabla Datos de la Evaluacion
    """

    # Nombre de la tabla
    __tablename__ = 'data_evaluations'

    # Columnas
    id_data_evaluation = db.Column(
                UUID(as_uuid = True),
                primary_key = True,
                default = uuid.uuid4(),
                unique = True,
                nullable = True
            )

    number_internal = db.Column(
                db.Integer,
                nullable = True
            )

    phone = db.Column(
                db.String(15),
                nullable = True
            )

    default = db.Column(
                db.String(20),
                nullable = True
            )

    contact = db.Column(
                db.String(20),
                nullable = True
            )

    date_evaluation = db.Column(
                db.DateTime,
                default = datetime.now(),
                nullable = True
            )

    date_audio = db.Column(
                db.DateTime,
                default = datetime.now(),
                nullable = True
            )

    name_audio = db.Column(
                db.String(100),
                nullable = True
            )
 
    def __init__(self,
                    number_internal: int,
                    phone: str,
                    contact: str,
                    date_evaluation: datetime,
                    date_audio: datetime,
                    name_audio: str,
                    default: str = None
                ):
        self.number_internal = number_internal
        self.phone = phone
        self.default = default
        self.contact = contact
        self.date_evaluation = date_evaluation
        self.date_audio = date_audio
        self.name_audio = name_audio
        self.id_data_evaluation = uuid.uuid4()

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

    def save(self):
        db.session.add(self)
        db.session.commit()

    @staticmethod
    def by_id(id: uuid.UUID):
        return DataEvaluations.query.filter_by(id_data_evaluation = id).first()

    @staticmethod
    def by_all():
        return DataEvaluations.query.all()