Fixed some bugs.

This commit is contained in:
Miguel Angel Astor Romero
2017-10-02 16:41:18 -04:00
parent 91107d71bf
commit 18cb664bc3
4 changed files with 47 additions and 22 deletions

0
README.md Executable file → Normal file
View File

53
code.py Executable file → Normal file
View File

@@ -117,13 +117,18 @@ class Subject:
return render.subject(subject_name[0]['name'], schedules, form, None) return render.subject(subject_name[0]['name'], schedules, form, None)
def POST(self): def POST(self):
cookie = web.cookies().get(COOKIE_SUBJECT)
schedules = db.query( schedules = db.query(
"SELECT schedules.sched_id, schedules.description, schedules.capacity, rooms.name " + "SELECT schedules.sched_id, schedules.description, schedules.capacity, rooms.name " +
"FROM schedules " + "FROM schedules " +
"INNER JOIN rooms ON schedules.room_id = rooms.room_id " + "INNER JOIN rooms ON schedules.room_id = rooms.room_id " +
"AND schedules.subject_id = " + str(cookie) + " " +
"ORDER BY schedules.sched_id ASC" "ORDER BY schedules.sched_id ASC"
) )
subject_name = db.query("SELECT name FROM subjects WHERE subject_id = " + str(cookie))
form = self.form() form = self.form()
if not form.validates(): if not form.validates():
@@ -136,18 +141,25 @@ class Subject:
else: else:
student = db.query( student = db.query(
"SELECT schedule_id FROM students WHERE id_CARD = $id AND email = $email", "SELECT schedule_id FROM students WHERE id_CARD = $id AND email = $email AND subject_id = $subject ",
vars = { vars = {
'id':str(form.d.cedula), 'id':str(form.d.cedula),
'email':form.d.email.upper() 'email':form.d.email.upper(),
'subject': int(cookie)
} }
) )
if len(student) == 0: if len(student) == 0:
return render.index(schedules, self.form, "Cedula o email no encontrados.") scheds = _get_schedule_list()
form = self.form()
form.horario.args = scheds
return render.subject(subject_name[0]['name'], schedules, form, "Cedula o email no encontrados para esta asignatura.")
else: else:
if student[0]["schedule_id"] != 8: if student[0]["schedule_id"] != 1:
return render.index(schedules, self.form, "Estudiante con horario ya registrado.") scheds = _get_schedule_list()
form = self.form()
form.horario.args = scheds
return render.subject(subject_name[0]['name'], schedules, form, "Estudiante con horario ya registrado.")
else: else:
sched = db.query( sched = db.query(
@@ -156,7 +168,10 @@ class Subject:
) )
if len(sched) == 0: if len(sched) == 0:
return render.index(schedules, self.form, "ERROR: Horario no encontrado.") scheds = _get_schedule_list()
form = self.form()
form.horario.args = scheds
return render.subject(subject_name[0]['name'], schedules, form, "ERROR: Horario no encontrado.")
else: else:
x = 0 x = 0
for s in sched: for s in sched:
@@ -167,7 +182,10 @@ class Subject:
x += 1 x += 1
if cap <= 0: if cap <= 0:
return render.index(schedules, self.form, "Horario agotado.") scheds = _get_schedule_list()
form = self.form()
form.horario.args = scheds
return render.subject(subject_name[0]['name'], schedules, form, "Horario agotado.")
else: else:
db.query( db.query(
"UPDATE schedules SET capacity = $cap where sched_id = $id", "UPDATE schedules SET capacity = $cap where sched_id = $id",
@@ -196,14 +214,21 @@ class Subject:
"ORDER BY schedules.sched_id ASC" "ORDER BY schedules.sched_id ASC"
) )
web.sendmail( try:
'', web.sendmail(
form.d.email.lower(), '',
'OECI - Laboratorio Registrado', form.d.email.lower(),
'Ha registrado exitosamente el horario de laboratorio: ' + desc 'OECI - Laboratorio Registrado',
) 'Ha registrado exitosamente el horario de laboratorio: ' + desc
)
except Exception:
pass
return render.index(schedules, self.form, "Horario registrado exitosamente.") scheds = _get_schedule_list()
form = self.form()
form.horario.args = scheds
return render.subject(subject_name[0]['name'], schedules, form, "Horario registrado exitosamente.")
if __name__ == "__main__": if __name__ == "__main__":
web.config.smtp_server = '' web.config.smtp_server = ''

View File

@@ -13,7 +13,7 @@ SECCTION_IDS = {"C1": 1,
QUERY = "SELECT students.id_card AS cedula, students.first_name AS nombre, students.last_name AS apellido, students.email AS email, sections.section AS seccion, schedules.description AS horario, rooms.name AS salon FROM students INNER JOIN schedules ON schedules.sched_id = students.schedule_id INNER JOIN rooms ON schedules.room_id = rooms.room_id INNER JOIN sections ON students.class_id = sections.section_id AND students.class_id = $sect AND students.subject_id = $subj;" QUERY = "SELECT students.id_card AS cedula, students.first_name AS nombre, students.last_name AS apellido, students.email AS email, sections.section AS seccion, schedules.description AS horario, rooms.name AS salon FROM students INNER JOIN schedules ON schedules.sched_id = students.schedule_id INNER JOIN rooms ON schedules.room_id = rooms.room_id INNER JOIN sections ON students.class_id = sections.section_id AND students.class_id = $sect AND students.subject_id = $subj;"
def main(): def main():
db = web.database(dbn = 'mysql', user = 'root', pw = 'Familylost9989*', db = 'labs') db = web.database(dbn = 'mysql', user = '', pw = '', db = '')
for s in SUBJECTS: for s in SUBJECTS:
for c in SECCTION_IDS.keys(): for c in SECCTION_IDS.keys():

View File

@@ -4,12 +4,12 @@
import pandas import pandas
import web import web
FILES = [("/home/miky/Documentos/listado_6001_C1.xls", 3), FILES = [("../listado_6001_C1.xls", 3),
("/home/miky/Documentos/listado_6001_C2.xls", 3), ("../listado_6001_C2.xls", 3),
("/home/miky/Documentos/listado_6001_C3.xls", 3), ("../listado_6001_C3.xls", 3),
("/home/miky/Documentos/listado_6001_C4.xls", 3), ("../listado_6001_C4.xls", 3),
("/home/miky/Documentos/listado_6004_C1.xls", 2), ("../listado_6004_C1.xls", 2),
("/home/miky/Documentos/listado_6004_C2.xls", 2)] ("../listado_6004_C2.xls", 2)]
SHEET_NAME = "Sheet1" SHEET_NAME = "Sheet1"
@@ -21,7 +21,7 @@ SECCTION_IDS = {"C1": 1,
QUERY = "INSERT INTO students(id_card, first_name, last_name, email, class_id, schedule_id, subject_id) VALUES($id, $fn, $ln, $ml, $cl, 1, $sj)" QUERY = "INSERT INTO students(id_card, first_name, last_name, email, class_id, schedule_id, subject_id) VALUES($id, $fn, $ln, $ml, $cl, 1, $sj)"
def main(): def main():
db = web.database(dbn = 'mysql', user = 'root', pw = 'Familylost9989*', db = 'labs') db = web.database(dbn = 'mysql', user = '', pw = '', db = '')
for f in FILES: for f in FILES:
xls = pandas.ExcelFile(f[0]) xls = pandas.ExcelFile(f[0])