def adminGetCourseAssignmentTable() -> dict: if "account_type" not in session: return make_response("", 401) elif session["account_type"] == "Administrador": db_connection = db.get_connection() db_cursor = db_connection.cursor() query: str = ( "select d.DocenteDNI, d.Nombre, d.Apellido," "a.CursoNombre, s.Pabellon,s.Numero, a.HoraInicio, a.HoraFin,a.Dia " "from AsignacionCurso a " "inner join Salon s using(SalonID) " "inner join Docente d using(DocenteDNI)" ) db_cursor.execute(query) course_assignment_table = scad_utils.rowToDict( ( "DocenteDNI", "Nombre", "Apellido", "CursoNombre", "Pabellon", "Numero", "HoraInicio", "HoraFin", "Dia", ), db_cursor.fetchall(), ) db_cursor.close() db_connection.close() return make_response(jsonify(course_assignment_table), 200) elif session["account_type"] == "Docente": return make_response("", 401)
def adminGetClassroomTable() -> dict: if "account_type" not in session: return make_response("", 401) elif session["account_type"] == "Administrador": db_connection = db.get_connection() db_cursor = db_connection.cursor() query: str = ("select Pabellon,Numero from Salon") db_cursor.execute(query) classroom_table = scad_utils.rowToDict( ("Pabellon", "Numero"), db_cursor.fetchall(), ) db_cursor.close() db_connection.close() return make_response(jsonify(classroom_table), 200) elif session["account_type"] == "Docente": return make_response("", 401)
def adminGetTeacherTable() -> dict: if "account_type" not in session: return make_response("", 401) elif session["account_type"] == "Administrador": db_connection = db.get_connection() db_cursor = db_connection.cursor() query: str = ("select * from Docente") db_cursor.execute(query) teacher_table = scad_utils.rowToDict( ("DocenteDNI", "Nombre", "Apellido", "Usuario", "Contrasena"), db_cursor.fetchall(), ) db_cursor.close() db_connection.close() return make_response(jsonify(teacher_table), 200) elif session["account_type"] == "Docente": return make_response("", 401)
def adminGetCourseTable() -> dict: if "account_type" not in session: return make_response("", 401) elif session["account_type"] == "Administrador": db_connection = db.get_connection() db_cursor = db_connection.cursor() query: str = ("select * from Curso") db_cursor.execute(query) course_table = scad_utils.rowToDict( ("CursoNombre", "FechaInicio", "FechaFin"), db_cursor.fetchall(), ) for course in course_table: course["FechaInicio"] = course["FechaInicio"].isoformat() course["FechaFin"] = course["FechaFin"].isoformat() db_cursor.close() db_connection.close() return make_response(jsonify(course_table), 200) elif session["account_type"] == "Docente": return make_response("", 401)
def adminGetReport() -> list: if "account_type" not in session: # no inicio sesion return make_response("nope", 401) elif session["account_type"] == "Administrador": time_range = request.get_json()["time_range"] if testing: current_datetime = fake_datetime else: current_datetime = datetime.datetime.now() db_connection = db.get_connection() db_cursor = db_connection.cursor(named_tuple=True) db_cursor.execute("SET lc_time_names = 'es_PE'") report: list if time_range == "today": query: str = ( "select a.AsignacionCursoID,d.DocenteDNI,d.Nombre,d.Apellido, " "a.CursoNombre, a.HoraInicio, a.HoraFin, s.Pabellon, s.Numero " "from AsignacionCurso a " "inner join Salon s using(SalonID) " "inner join Docente d using(DocenteDNI) " "where Dia=dayname(?) and a.HoraInicio<? " ) db_cursor.execute( query, ( current_datetime.strftime("%Y-%m-%d"), current_datetime.strftime("%H:%M:%S"), ), ) report = db_cursor.fetchall() # se formatea la lista de cursos report = scad_utils.rowToDict( ( "AsignacionCursoID", "DocenteDNI", "Nombre", "Apellido", "CursoNombre", "HoraInicio", "HoraFin", "Pabellon", "Numero", ), report, ) if len(report) > 0: existence_check_query: str = ( "select * from Marcacion " "where Fecha=? and AsignacionCursoID=?" ) for assignment in report: db_cursor.execute( existence_check_query, ( current_datetime.strftime("%Y-%m-%d"), assignment["AsignacionCursoID"], ), ) if len(db_cursor.fetchall()) > 0: assignment["state"] = "marked" else: assignment["state"] = "not_marked" db_cursor.close() db_connection.close() return make_response(jsonify(report), 200) elif time_range == "yesterday": query: str = ( "select a.AsignacionCursoID,d.DocenteDNI,d.Nombre,d.Apellido, " "a.CursoNombre, a.HoraInicio, a.HoraFin, s.Pabellon, s.Numero " "from AsignacionCurso a " "inner join Salon s using(SalonID) " "inner join Docente d using(DocenteDNI) " "where Dia=dayname(?)" ) current_datetime -= datetime.timedelta(days=1) db_cursor.execute( query, (current_datetime.strftime("%Y-%m-%d"),), ) report = db_cursor.fetchall() # se formatea la lista de cursos report = scad_utils.rowToDict( ( "AsignacionCursoID", "DocenteDNI", "Nombre", "Apellido", "CursoNombre", "HoraInicio", "HoraFin", "Pabellon", "Numero", ), report, ) if len(report) > 0: existence_check_query: str = ( "select * from Marcacion " "where Fecha=? and AsignacionCursoID=?" ) for assignment in report: db_cursor.execute( existence_check_query, ( current_datetime.strftime("%Y-%m-%d"), assignment["AsignacionCursoID"], ), ) if len(db_cursor.fetchall()) > 0: assignment["state"] = "marked" else: assignment["state"] = "not_marked" db_cursor.close() db_connection.close() return make_response(jsonify(report), 200) elif time_range == "this_week": pass elif time_range == "this_month": pass elif time_range == "all": pass else: return make_response("peticion invalida", 406) elif session["account_type"] == "Docente": # el administrador no deberia usar este servicio return make_response("ya nos jakiaron", 400)
def teacherCourseList() -> list: # verificar la sesion if "account_type" not in session: # no inicio sesion return make_response("nope", 401) elif session["account_type"] == "Docente": # consultar la lista de cursos y si se han marcado o no # un curso marcado se diferencia porque el valor de Hora de la tabla Marcacion # es diferente de NULL if testing: current_datetime = fake_datetime else: current_datetime = datetime.datetime.now() db_connection = db.get_connection() db_cursor = db_connection.cursor() db_cursor.execute("SET lc_time_names = 'es_PE'") query: str = ( "select AsignacionCursoID, a.CursoNombre, a.HoraInicio, a.HoraFin, s.Pabellon, s.Numero " "from AsignacionCurso a " "inner join Salon s using(SalonID) " "where Dia=dayname(?) and DocenteDNI=? " ) db_cursor.execute( query, (current_datetime.strftime("%Y/%m/%d"), session["DocenteDNI"]) ) today_assigned_courses: list = db_cursor.fetchall() # se formatea la lista de cursos today_assigned_courses = scad_utils.rowToDict( ( "AsignacionCursoID", "CursoNombre", "HoraInicio", "HoraFin", "Pabellon", "Numero", ), today_assigned_courses, ) if len(today_assigned_courses) > 0: existence_check_query: str = ( "select * from Marcacion " "where Fecha=? and AsignacionCursoID=?" ) for course in today_assigned_courses: db_cursor.execute( existence_check_query, ( current_datetime.strftime("%Y/%m/%d"), course["AsignacionCursoID"], ), ) if len(db_cursor.fetchall()) > 0: course["state"] = "marked" else: if current_datetime >= scad_utils.timeToDatetime( course["HoraInicio"], current_datetime ): if ( current_datetime - scad_utils.timeToDatetime( course["HoraInicio"], current_datetime ) <= teacher_time_tolerance ): course["state"] = "mark_now" else: course["state"] = "not_marked" else: course["state"] = "waiting" db_cursor.close() db_connection.close() return jsonify(today_assigned_courses) elif session["account_type"] == "Administrador": # el administrador no deberia usar este servicio return make_response("ya nos jakiaron", 400)