Added rudimentary support for differente subjects and helper scripts.
This commit is contained in:
74
code.py
74
code.py
@@ -4,15 +4,24 @@
|
||||
import web
|
||||
|
||||
urls = (
|
||||
'/', 'Index'
|
||||
'/', 'Index',
|
||||
'/[0-9]+', 'Subject'
|
||||
)
|
||||
|
||||
render = web.template.render('templates/')
|
||||
|
||||
db = web.database(dbn = 'mysql', user = '', pw = '', db = '')
|
||||
|
||||
COOKIE_SUBJECT = "weblabs_cookie_subject"
|
||||
|
||||
def _get_schedule_list():
|
||||
schedules = db.query("SELECT sched_id, description FROM schedules WHERE sched_id < 8 ORDER BY sched_id ASC")
|
||||
cookie = web.cookies().get(COOKIE_SUBJECT)
|
||||
|
||||
if cookie is None or int(cookie) <= 1:
|
||||
return []
|
||||
|
||||
schedules = db.query("SELECT sched_id, description FROM schedules WHERE sched_id > 1 AND subject_id = " + str(cookie) + " " +
|
||||
"ORDER BY sched_id ASC")
|
||||
|
||||
lst = []
|
||||
for s in schedules:
|
||||
@@ -20,7 +29,36 @@ def _get_schedule_list():
|
||||
|
||||
return lst
|
||||
|
||||
def _get_subject_list():
|
||||
subjects = db.query("SELECT subject_id, name FROM subjects WHERE subject_id > 1 ORDER BY subject_id ASC")
|
||||
|
||||
lst = []
|
||||
for s in subjects:
|
||||
lst.append((s['subject_id'], s['name']))
|
||||
|
||||
return lst
|
||||
|
||||
class Index:
|
||||
form = web.form.Form(
|
||||
web.form.Dropdown(
|
||||
'asignatura',
|
||||
_get_subject_list(),
|
||||
description = "Asignatura inscrita"
|
||||
),
|
||||
web.form.Button('Seleccionar')
|
||||
)
|
||||
|
||||
def GET(self):
|
||||
return render.index(self.form())
|
||||
|
||||
def POST(self):
|
||||
form = self.form()
|
||||
form.validates()
|
||||
subject_id = form.d.asignatura
|
||||
web.setcookie(COOKIE_SUBJECT, subject_id)
|
||||
raise web.seeother('/' + str(subject_id))
|
||||
|
||||
class Subject:
|
||||
|
||||
form = web.form.Form(
|
||||
web.form.Textbox(
|
||||
@@ -38,21 +76,45 @@ class Index:
|
||||
),
|
||||
web.form.Dropdown(
|
||||
'horario',
|
||||
_get_schedule_list(),
|
||||
[],
|
||||
description = "Horario a inscribir:"
|
||||
),
|
||||
web.form.Button('Registrar horario')
|
||||
)
|
||||
|
||||
def GET(self):
|
||||
cookie = web.cookies().get(COOKIE_SUBJECT)
|
||||
|
||||
def validate_cookie(cookie):
|
||||
found = False
|
||||
|
||||
subjects = db.query("SELECT subject_id FROM subjects WHERE subject_id > 1 ORDER BY subject_id ASC")
|
||||
for s in subjects:
|
||||
if int(cookie) == int(s['subject_id']):
|
||||
found = True
|
||||
break
|
||||
|
||||
return found
|
||||
|
||||
if cookie is None or not validate_cookie(cookie):
|
||||
raise web.seeother('/')
|
||||
|
||||
|
||||
schedules = _get_schedule_list()
|
||||
form = self.form()
|
||||
form.horario.args = schedules
|
||||
|
||||
schedules = db.query(
|
||||
"SELECT schedules.sched_id, schedules.description, schedules.capacity, rooms.name " +
|
||||
"FROM schedules " +
|
||||
"INNER JOIN rooms ON schedules.room_id = rooms.room_id " +
|
||||
"ORDER BY schedules.sched_id ASC"
|
||||
"AND schedules.subject_id = " + str(cookie) + " " +
|
||||
"ORDER BY schedules.sched_id ASC "
|
||||
)
|
||||
|
||||
return render.index(schedules, self.form(), None)
|
||||
subject_name = db.query("SELECT name FROM subjects WHERE subject_id = " + str(cookie))
|
||||
|
||||
return render.subject(subject_name[0]['name'], schedules, form, None)
|
||||
|
||||
def POST(self):
|
||||
schedules = db.query(
|
||||
@@ -67,7 +129,7 @@ class Index:
|
||||
if not form.validates():
|
||||
return render.index(
|
||||
schedules,
|
||||
self.form,
|
||||
self.form(),
|
||||
"No deje los campos vacíos.<br/>La cédula debe ser un número."
|
||||
)
|
||||
|
||||
|
@@ -15,6 +15,21 @@
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `subjects`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `subjects`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `subjects` (
|
||||
`subject_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100),
|
||||
PRIMARY KEY (`subject_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
--
|
||||
-- Table structure for table `rooms`
|
||||
--
|
||||
@@ -26,7 +41,7 @@ CREATE TABLE `rooms` (
|
||||
`room_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(5) DEFAULT NULL,
|
||||
PRIMARY KEY (`room_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -41,10 +56,12 @@ CREATE TABLE `schedules` (
|
||||
`description` varchar(30) DEFAULT NULL,
|
||||
`capacity` int(11) NOT NULL,
|
||||
`room_id` int(10) unsigned NOT NULL,
|
||||
`subject_id` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`sched_id`),
|
||||
KEY `fk_room` (`room_id`),
|
||||
CONSTRAINT `schedules_ibfk_1` FOREIGN KEY (`room_id`) REFERENCES `rooms` (`room_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
|
||||
CONSTRAINT `schedules_ibfk_1` FOREIGN KEY (`room_id`) REFERENCES `rooms` (`room_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `schedules_ibfk_2` FOREIGN KEY (`subject_id`) REFERENCES `subjects` (`subject_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -58,7 +75,7 @@ CREATE TABLE `sections` (
|
||||
`section_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`section` varchar(2) DEFAULT NULL,
|
||||
PRIMARY KEY (`section_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -76,12 +93,15 @@ CREATE TABLE `students` (
|
||||
`email` varchar(100) NOT NULL,
|
||||
`class_id` int(10) unsigned NOT NULL,
|
||||
`schedule_id` int(10) unsigned NOT NULL,
|
||||
`subject_id` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`student_id`),
|
||||
KEY `fk_class` (`class_id`),
|
||||
KEY `fk_sched` (`schedule_id`),
|
||||
KEY `fk_subject` (`subject_id`),
|
||||
CONSTRAINT `students_ibfk_1` FOREIGN KEY (`class_id`) REFERENCES `sections` (`section_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `students_ibfk_2` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`sched_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=103 DEFAULT CHARSET=latin1;
|
||||
CONSTRAINT `students_ibfk_2` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`sched_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `students_ibfk_3` FOREIGN KEY (`subject_id`) REFERENCES `subjects` (`subject_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
|
40
generate_report.py
Normal file
40
generate_report.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#! /usr/bin/env python
|
||||
# _*_ coding: UTF-8 _*_
|
||||
|
||||
import web
|
||||
|
||||
SUBJECTS = [("6001", 3), ("6004", 2)]
|
||||
|
||||
SECCTION_IDS = {"C1": 1,
|
||||
"C2": 2,
|
||||
"C3": 3,
|
||||
"C4": 4}
|
||||
|
||||
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():
|
||||
db = web.database(dbn = 'mysql', user = 'root', pw = 'Familylost9989*', db = 'labs')
|
||||
|
||||
for s in SUBJECTS:
|
||||
for c in SECCTION_IDS.keys():
|
||||
with open(s[0] + "_" + c + ".csv", "w") as f:
|
||||
values = {"sect": SECCTION_IDS[c],
|
||||
"subj": s[1]}
|
||||
students = db.query(QUERY, values)
|
||||
|
||||
f.write("Cedula, Nombres, Apellidos, E-mail, Seccion, Horario, Salon,\n")
|
||||
|
||||
for student in students:
|
||||
out_str = ""
|
||||
out_str += unicode(student['cedula']) + ", "
|
||||
out_str += unicode(student['nombre']) + ", "
|
||||
out_str += unicode(student['apellido']) + ", "
|
||||
out_str += unicode(student['email']) + ", "
|
||||
out_str += unicode(student['seccion']) + ", "
|
||||
out_str += unicode(student['horario']) + ", "
|
||||
out_str += unicode(student['salon']) + ", "
|
||||
|
||||
f.write(out_str.encode('utf8') + "\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
50
insert_students.py
Normal file
50
insert_students.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#! /usr/bin/env python
|
||||
# _*_ coding: UTF-8 _*_
|
||||
|
||||
import pandas
|
||||
import web
|
||||
|
||||
FILES = [("/home/miky/Documentos/listado_6001_C1.xls", 3),
|
||||
("/home/miky/Documentos/listado_6001_C2.xls", 3),
|
||||
("/home/miky/Documentos/listado_6001_C3.xls", 3),
|
||||
("/home/miky/Documentos/listado_6001_C4.xls", 3),
|
||||
("/home/miky/Documentos/listado_6004_C1.xls", 2),
|
||||
("/home/miky/Documentos/listado_6004_C2.xls", 2)]
|
||||
|
||||
SHEET_NAME = "Sheet1"
|
||||
|
||||
SECCTION_IDS = {"C1": 1,
|
||||
"C2": 2,
|
||||
"C3": 3,
|
||||
"C4": 4}
|
||||
|
||||
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():
|
||||
db = web.database(dbn = 'mysql', user = 'root', pw = 'Familylost9989*', db = 'labs')
|
||||
|
||||
for f in FILES:
|
||||
xls = pandas.ExcelFile(f[0])
|
||||
df = xls.parse(SHEET_NAME)
|
||||
|
||||
subject_id = f[1]
|
||||
section_id = SECCTION_IDS[df.iloc[7, 1]]
|
||||
|
||||
row = 10
|
||||
while True:
|
||||
try:
|
||||
values = {"id": int(df.iloc[row, 2]),
|
||||
"fn": unicode(df.iloc[row, 3]),
|
||||
"ln": unicode(df.iloc[row, 4]),
|
||||
"ml": unicode(df.iloc[row, 5]),
|
||||
"cl": section_id,
|
||||
"sj": subject_id}
|
||||
|
||||
db.query(QUERY, vars = values)
|
||||
|
||||
row += 1
|
||||
except IndexError:
|
||||
break
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,10 +1,10 @@
|
||||
$def with (schedules, form, error_text)
|
||||
$def with (form)
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8 />
|
||||
<title>
|
||||
GD-OECI :: Semestre 2-2015 - Inscripción de laboratorios.
|
||||
ICARO :: Semestre 1-2017 - Inscripción de laboratorios.
|
||||
</title>
|
||||
<link rel=stylesheet type=text/css href=static/styles.css>
|
||||
<link href=img/favicon.ico rel=icon type=image/x-icon />
|
||||
@@ -18,8 +18,7 @@ $def with (schedules, form, error_text)
|
||||
<td colspan=2>
|
||||
<br>
|
||||
<div class=text_style id=banner>
|
||||
<h1> Organización y Estructura del Computador 1 </h1>
|
||||
<h2> Inscripción de laboratorios :: Semestre 2-2015 </h2>
|
||||
<h2> Inscripción de laboratorios :: Semestre 1-2017 </h2>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -28,49 +27,12 @@ $def with (schedules, form, error_text)
|
||||
<hr />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class=text_style>
|
||||
<h3>
|
||||
Datos para la inscripción.
|
||||
</h3>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class=text_style>
|
||||
<h3>Horarios disponibles</h3>
|
||||
<div class=text_style>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style=vertical-align:top>
|
||||
$if error_text is not None:
|
||||
<div class=text_style>
|
||||
<p class=warning> $:error_text </p>
|
||||
</div>
|
||||
<form action="" method=post>
|
||||
$:form.render()
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<div style=font-variant:small-caps>
|
||||
<ul>
|
||||
$for sched in schedules:
|
||||
$if sched.sched_id < 8:
|
||||
<li>
|
||||
<b>$sched.description</b>
|
||||
<br/>
|
||||
Capacidad: <i>15</i>
|
||||
<br/>
|
||||
Disponibles:
|
||||
<i>$sched.capacity</i>
|
||||
<br/>
|
||||
Sala:
|
||||
$sched.name
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
85
templates/subject.html
Normal file
85
templates/subject.html
Normal file
@@ -0,0 +1,85 @@
|
||||
$def with (name, schedules, form, error_text)
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8 />
|
||||
<title>
|
||||
ICARO :: Semestre 1-2017 - Inscripción de laboratorios.
|
||||
</title>
|
||||
<link rel=stylesheet type=text/css href=static/styles.css>
|
||||
<link href=img/favicon.ico rel=icon type=image/x-icon />
|
||||
</head>
|
||||
<body>
|
||||
<table id=main_table>
|
||||
<tr>
|
||||
<td id=main_cell>
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan=2>
|
||||
<br>
|
||||
<div class=text_style id=banner>
|
||||
<h1> $:name </h1>
|
||||
<h2> Inscripción de laboratorios :: Semestre 1-2017 </h2>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=2>
|
||||
<hr />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class=text_style>
|
||||
<h3>
|
||||
Datos para la inscripción.
|
||||
</h3>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class=text_style>
|
||||
<h3>Horarios disponibles</h3>
|
||||
<div class=text_style>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style=vertical-align:top>
|
||||
$if error_text is not None:
|
||||
<div class=text_style>
|
||||
<p class=warning> $:error_text </p>
|
||||
</div>
|
||||
<form action="" method=post>
|
||||
$:form.render()
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<div style=font-variant:small-caps>
|
||||
<ul>
|
||||
$for sched in schedules:
|
||||
$if sched.sched_id > 1:
|
||||
<li>
|
||||
<b>$sched.description</b>
|
||||
<br/>
|
||||
Capacidad: <i>15</i>
|
||||
<br/>
|
||||
Disponibles:
|
||||
<i>$sched.capacity</i>
|
||||
<br/>
|
||||
Sala:
|
||||
$sched.name
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class=text_style>
|
||||
<p style=text-align:center;>
|
||||
Laboratorio ICARO, Escuela de Computación, Facultad de Ciencias, Universidad Central de Venezuela.
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user