class StudentWorkshop(db.Model): __tablename__ = 'estudiante_taller' student_id = db.Column('estudiante_id', db.Integer, db.ForeignKey('estudiante.id'), primary_key=True) schoolyear_id = db.Column('ciclo_lectivo_id', db.Integer, db.ForeignKey('ciclo_lectivo.id'), primary_key=True) workshop_id = db.Column('taller_id', db.Integer, db.ForeignKey('taller.id'), primary_key=True) __table_args__ = (db.ForeignKeyConstraint( ['taller_id', 'ciclo_lectivo_id'], [ 'ciclo_lectivo_taller.taller_id', 'ciclo_lectivo_taller.ciclo_lectivo_id' ]), ) def __init__(self, student_id, cicle_id, workshop_id): self.student_id = student_id self.schoolyear_id = cicle_id self.workshop_id = workshop_id @classmethod def create(cls, student_id, cicle_id, workshop_id): cicle_id = cicle_id course = cls(student_id, cicle_id, workshop_id) db.session.add(course) db.session.commit() @classmethod def get_students_doing_workshop(cls, schoolyear_id, workshop_id): students = cls.query.filter(cls.schoolyear_id == schoolyear_id, cls.workshop_id == workshop_id).all() students_ids = [] for student in students: students_ids.append(student.student_id) return students_ids
class Teacher(db.Model): __tablename__ = 'docente' id = db.Column(db.Integer, primary_key=True) last_name = db.Column('apellido', db.String(255), nullable=False) first_name = db.Column('nombre', db.String(255), nullable=False) birth_date = db.Column('fecha_nac', db.DateTime, nullable=False) location_id = db.Column('localidad_id', db.Integer, nullable=False) residency = db.Column('domicilio', db.String(255), nullable=False) latitude = db.Column('latitud', db.String(255), nullable=False) longitude = db.Column('longitud', db.String(255), nullable=False) gender_id = db.Column('genero_id', db.Integer, db.ForeignKey('genero.id'), nullable=False) doc_type_id = db.Column('tipo_doc_id', db.Integer, nullable=False) doc_number = db.Column('numero', db.Integer, nullable=False) telephone = db.Column('tel', db.String(255), nullable=False) is_active = db.Column(db.Boolean, nullable=False, default=True) school_years = db.relationship('SchoolYear', secondary=school_year_workshop_teacher, lazy='subquery', backref=db.backref('teachers', lazy=True)) workshops = db.relationship('Workshop', secondary=school_year_workshop_teacher, lazy='subquery', backref=db.backref('teachers', lazy=True)) def __init__(self, data): self.__init_attributes(data) def __init_attributes(self, data): self.last_name = data['last_name'] self.first_name = data['first_name'] self.birth_date = data['birth_date'] self.location_id = data['location_id'] self.residency = data['residency'] self.gender_id = data['gender_id'] self.doc_type_id = data['doc_type_id'] self.doc_number = data['doc_number'] self.telephone = data['telephone'] self.latitude = data['latitude'] self.longitude = data['longitude'] def activate(self): self.is_active = True db.session.commit() return self def deactivate(self): self.is_active = False db.session.commit() return self @classmethod def create(cls, data): teacher = cls(data) db.session.add(teacher) db.session.commit() def update(self, values): self.__init_attributes(values) db.session.commit() def get_workshops_of_cicle(self, cicle_id): return Workshop.query.join(school_year_workshop_teacher).\ filter_by(docente_id=self.id, ciclo_lectivo_id=cicle_id) def get_workshops(self): return Workshop.query.join(school_year_workshop_teacher).\ filter_by(docente_id=self.id) def assign_to(self, form_workshops, form_cicle): for whp in form_workshops: statement = school_year_workshop_teacher.insert().values( docente_id=self.id, ciclo_lectivo_id=form_cicle, taller_id=whp) db.session.execute(statement) db.session.commit() def get_days_of_cicle_whp_nucleus(self, cicle_id, whp_id, nucleus_id): return Day.query.join(TeacherNucleus).\ filter_by(teacher_id=self.id, schoolyear_id=cicle_id, workshop_id=whp_id, nucleus_id=nucleus_id) # se supone que esto va a asignar los nucleos, algun dia .... def assign_to_nucleus(self, form_cicle, form_whp, form_nucleus, week_day): statement = TeacherNucleus.create(self.id, form_nucleus, form_cicle, form_whp, week_day)
class Instrument(db.Model): __tablename__ = 'instrumento' id = db.Column(db.Integer, primary_key=True) name = db.Column('nombre', db.String(255), nullable=False) category_id = db.Column('categoria_id', db.Integer, db.ForeignKey('tipo_instrumento.id'), nullable=False) inventory_number = db.Column('cod_inventario', db.String(255), unique=True, nullable=False) image = db.Column('imagen', db.LargeBinary(length=(2**32) - 1), nullable=False) is_active = db.Column(db.Boolean, nullable=False, default=True) def __repr__(self): return f"{self.inventory_number} - {self.name}" def __init__(self, data): self.__init_attributes(data) self.__init_image(data) def __init_attributes(self, data): self.name = data['name'] self.category_id = data['category_id'] self.inventory_number = data['inventory_number'] def __init_image(self, data): self.image = data['image'] @classmethod def create(cls, data): instrument = cls(data) db.session.add(instrument) db.session.commit() return instrument @classmethod def any_inventory_number(cls, number): return any(cls.query.filter(cls.inventory_number == number)) def activate(self): self.is_active = True db.session.commit() return self def deactivate(self): self.is_active = False db.session.commit() return self def switch_status(self): self.deactivate() if self.is_active else self.activate() return self.is_active def update(self, values): self.__init_attributes(values) db.session.commit() return self def update_image(self, values): self.__init_image(values) db.session.commit() @classmethod def all_with_representative_entities(cls): return cls.query.with_entities(cls.name, cls.inventory_number, cls.id, cls.is_active)
class AssistanceStudentWorkshop(db.Model): __tablename__ = 'asistencia_estudiante_taller' student_id = db.Column('estudiante_id', db.Integer, db.ForeignKey('estudiante.id'), primary_key=True) schoolyear_id = db.Column('ciclo_lectivo_id', db.Integer, db.ForeignKey('ciclo_lectivo.id'), primary_key=True) workshop_id = db.Column('taller_id', db.Integer, db.ForeignKey('taller.id'), primary_key=True) nucleus_id = db.Column('nucleo_id', db.Integer, db.ForeignKey('nucleo.id'), primary_key=True) date = db.Column('fecha', db.Date, primary_key=True) assisted = db.Column( 'asistio', db.Integer, ) observation = db.Column( 'observacion', db.String(255), nullable=True, ) __table_args__ = (db.ForeignKeyConstraint( ['taller_id', 'ciclo_lectivo_id'], [ 'ciclo_lectivo_taller.taller_id', 'ciclo_lectivo_taller.ciclo_lectivo_id' ]), ) def __init__(self, data): self.__init_attributes(data) def __init_attributes(self, data): self.student_id = data['student_id'] self.schoolyear_id = data['schoolyear_id'] self.workshop_id = data['workshop_id'] self.nucleus_id = data['nucleus_id'] self.date = data['date'] self.assisted = data['assistance'] self.observation = data['observation'] @classmethod def create(cls, data): assistance_student_workshop = cls(data) db.session.add(assistance_student_workshop) db.session.commit() @classmethod def assistance_already_taken(cls, schoolyear_id, workshop_id): return cls.query.filter(cls.schoolyear_id == schoolyear_id, cls.workshop_id == workshop_id, cls.date == datetime.now().date()).count() != 0 @classmethod def student_assistances(cls, student_id): return cls.query.filter(cls.student_id == student_id)
from flaskps.extensions.db import db from flaskps.models.permission import Permission role_permission = db.Table( 'role_permission', db.Column('role_id', db.Integer, db.ForeignKey('role.id'), primary_key=True), db.Column('permission_id', db.Integer, db.ForeignKey('permission.id'), primary_key=True))
class Responsable(db.Model): __tablename__ = 'responsable' id = db.Column( db.Integer, autoincrement=True, primary_key=True ) last_name = db.Column( 'apellido', db.String(30), nullable=False ) first_name = db.Column( 'nombre', db.String(20), nullable=False ) birth_date = db.Column( 'fecha_nac', db.DateTime, nullable=False ) location_id = db.Column( 'localidad_id', db.Integer ) residency = db.Column( 'domicilio', db.String(255), nullable=False ) gender_id = db.Column( 'genero_id', db.Integer, db.ForeignKey('genero.id'), nullable=False ) doc_type_id = db.Column( 'tipo_doc_id', db.Integer, nullable=False ) doc_number = db.Column( 'numero', db.Integer, nullable=False ) telephone = db.Column( 'tel', db.String(255), nullable=False ) is_active = db.Column( 'activo', db.Boolean, nullable=False, default=True ) def __init__(self, data): self.__init_attributes(data) def __init_attributes(self, data): self.last_name = data['last_name'] self.first_name = data['first_name'] self.birth_date = data['birth_date'] self.location_id = data['location_id'] self.residency = data['residency'] self.gender_id = data['gender_id'] self.doc_type_id = data['doc_type_id'] self.doc_number = data['doc_number'] self.telephone = data['telephone'] @classmethod def create(cls, data): responsable = cls(data) db.session.add(responsable) db.session.commit() return responsable def activate(self): self.is_active = True db.session.commit() def deactivate(self): self.is_active = False db.session.commit() def update(self, values): self.__init_attributes(values) db.session.commit() def can_deactivated(self): return all(map( lambda student: student.more_responsables_active_that(self), self.students )) @classmethod def all_except(cls, responsables): return Responsable.query.filter( ~Responsable.id.in_(cls.responsables_id(responsables)) ) @classmethod def responsables_id(cls, responsables): return list(map(lambda responsable: int(responsable.id), responsables)) @property def full_name(self): return f"{self.last_name}, {self.first_name}"
from flaskps.extensions.db import db responsable_student = db.Table( 'responsable_estudiante', db.Column( 'estudiante_id', db.Integer, db.ForeignKey('estudiante.id'), primary_key=True ), db.Column( 'responsable_id', db.Integer, db.ForeignKey('responsable.id'), primary_key=True ) )
class TeacherNucleus(db.Model): __tablename__ = 'docente_nucleo_taller_ciclo' teacher_id = db.Column( 'docente_id', db.Integer, db.ForeignKey('docente.id'), primary_key=True ) nucleus_id = db.Column( 'nucleo_id', db.Integer, db.ForeignKey('nucleo.id'), primary_key=True ) schoolyear_id = db.Column( 'ciclo_lectivo_id', db.Integer, db.ForeignKey('ciclo_lectivo.id'), primary_key=True ) workshop_id = db.Column( 'taller_id', db.Integer, db.ForeignKey('taller.id'), primary_key=True ) day_id = db.Column( 'dia_id', db.Integer, db.ForeignKey('dia.id'), primary_key=True ) __table_args__ = ( db.ForeignKeyConstraint( ['taller_id', 'ciclo_lectivo_id'], ['ciclo_lectivo_taller.taller_id', 'ciclo_lectivo_taller.ciclo_lectivo_id'] ), ) def __init__(self, teacher_id, nucleus_id, schoolyear_id, workshop_id, day_id): self.__init_attributes(teacher_id, nucleus_id, schoolyear_id, workshop_id, day_id) def __init_attributes(self, teacher_id, nucleus_id, schoolyear_id, workshop_id, day_id): self.teacher_id = teacher_id self.nucleus_id = nucleus_id self.schoolyear_id = schoolyear_id self.workshop_id = workshop_id self.day_id = day_id @classmethod def create(cls, teacher_id, nucleus_id, schoolyear_id, workshop_id, day_id): teacherNucleus = cls(teacher_id, nucleus_id, schoolyear_id, workshop_id, day_id) db.session.add(teacherNucleus) db.session.commit() @classmethod def nucleus_of(cls, workshop_id, schoolyear_id): courses = cls.query.filter_by( workshop_id=workshop_id, schoolyear_id=schoolyear_id ) return set(map(lambda course: course.nucleus, courses))
from flaskps.extensions.db import db from .school_year import SchoolYear from .workshop import Workshop school_year_workshop_teacher = db.Table( 'docente_responsable_taller', db.Column('docente_id', db.Integer, db.ForeignKey('docente.id'), primary_key=True), db.Column('ciclo_lectivo_id', db.Integer, db.ForeignKey('ciclo_lectivo.id'), primary_key=True), db.Column('taller_id', db.Integer, db.ForeignKey('taller.id'), primary_key=True))
class Student(db.Model): __tablename__ = 'estudiante' id = db.Column(db.Integer, primary_key=True) last_name = db.Column('apellido', db.String(30), nullable=False) first_name = db.Column('nombre', db.String(20), nullable=False) birth_date = db.Column('fecha_nac', db.DateTime, nullable=False) birth_location = db.Column('lugar_nac', db.String(255), nullable=False) location_id = db.Column('localidad_id', db.Integer, nullable=False) residency = db.Column('domicilio', db.String(255), nullable=False) latitude = db.Column('latitud', db.String(255), nullable=False) longitude = db.Column('longitud', db.String(255), nullable=False) neighborhood_id = db.Column('barrio_id', db.Integer, db.ForeignKey('barrio.id'), nullable=False) gender_id = db.Column('genero_id', db.Integer, db.ForeignKey('genero.id'), nullable=False) doc_type_id = db.Column('tipo_doc_id', db.Integer, nullable=False) doc_number = db.Column('numero', db.Integer, nullable=False) telephone = db.Column('tel', db.String(255), nullable=False) school_id = db.Column('escuela_id', db.Integer, db.ForeignKey('escuela.id'), nullable=False) level_id = db.Column('nivel_id', db.Integer, db.ForeignKey('nivel.id'), nullable=False) is_active = db.Column('activo', db.Boolean, nullable=False, default=True) workshops_school_years = db.relationship('StudentWorkshop', lazy=True, backref=db.backref('students')) responsables = db.relationship('Responsable', secondary=responsable_student, lazy='subquery', backref=db.backref('students', lazy=True)) def __init__(self, data): self.__init_attributes(data) self.__init_relationships(data) def __init_attributes(self, data): self.last_name = data['last_name'] self.first_name = data['first_name'] self.birth_date = data['birth_date'] self.location_id = data['location_id'] self.residency = data['residency'] self.gender_id = data['gender_id'] self.doc_type_id = data['doc_type_id'] self.doc_number = data['doc_number'] self.telephone = data['telephone'] self.gender_id = data['gender_id'] self.school_id = data['school_id'] self.neighborhood_id = data['neighborhood_id'] self.birth_location = data['birth_location'] self.level_id = data['level_id'] self.latitude = data['latitude'] self.longitude = data['longitude'] def __init_relationships(self, data): self.responsables = self.__responsables_by_id(data['responsables_id']) def __responsables_by_id(self, responsables_id): return [Responsable.query.get(r_id) for r_id in responsables_id] def __repr__(self): return f'<Student {self.first_name}, {self.last_name}>' def activate(self): self.is_active = True db.session.commit() def deactivate(self): self.is_active = False db.session.commit() def get_workshops_of_cicle(self, cicle_id): return Workshop.query.join(StudentWorkshop).\ filter_by(student_id=self.id, schoolyear_id=cicle_id) @classmethod def create(cls, data): student = cls(data) db.session.add(student) db.session.commit() def update(self, values): self.__init_attributes(values) db.session.commit() def more_responsables_active_that(self, responsable): return any( map(lambda r: r.is_active, self.other_responsables(responsable))) def other_responsables(self, responsable): return filter(lambda r: r.id != responsable.id, self.responsables) def add_responsable(self, responsable): self.responsables.append(responsable) db.session.commit() def add_course(self, cicle_id, workshops_id): for workshop_id in workshops_id: StudentWorkshop.create(self.id, cicle_id, workshop_id) def has_responsable(self, responsable): return responsable in self.responsables
from flaskps.extensions.db import db from flaskps.models.role import Role user_role = db.Table( 'user_role', db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True), db.Column('role_id', db.Integer, db.ForeignKey('role.id'), primary_key=True))