First commit.

This commit is contained in:
2015-11-04 11:00:20 -04:30
commit 1fefaffecd
9 changed files with 404 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.pyc
*.pyo
*~

22
LICENSE Normal file
View File

@@ -0,0 +1,22 @@
Copyright (c) 2015, Miguel Angel Astor Romero
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

5
README.md Executable file
View File

@@ -0,0 +1,5 @@
OECI - Lab Register
===================
A Web.py application that registers students to the UCV 6001 course.

154
code.py Executable file
View File

@@ -0,0 +1,154 @@
#! /usr/bin/env python
# _*_ coding: UTF-8 _*_
import web
urls = (
'/', 'Index'
)
render = web.template.render('templates/')
db = web.database(dbn = 'mysql', user = '', pw = '', db = '')
def _get_schedule_list():
schedules = db.query("SELECT sched_id, description FROM schedules WHERE sched_id < 8 ORDER BY sched_id ASC")
lst = []
for s in schedules:
lst.append((s['sched_id'], s['description']))
return lst
class Index:
form = web.form.Form(
web.form.Textbox(
'cedula',
web.form.notnull,
web.form.regexp('\d+', 'Debe ser un numero'),
size = 30,
description = "Cedula de identidad:"
),
web.form.Textbox(
'email',
web.form.notnull,
size = 30,
description = "Correo electronico:"
),
web.form.Dropdown(
'horario',
_get_schedule_list(),
description = "Horario a inscribir:"
),
web.form.Button('Registrar horario')
)
def GET(self):
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"
)
return render.index(schedules, self.form(), None)
def POST(self):
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"
)
form = self.form()
if not form.validates():
return render.index(
schedules,
self.form,
"No deje los campos vac&iacute;os.<br/>La c&eacute;dula debe ser un n&uacute;mero."
)
else:
student = db.query(
"SELECT schedule_id FROM students WHERE id_CARD = $id AND email = $email",
vars = {
'id':str(form.d.cedula),
'email':form.d.email.upper()
}
)
if len(student) == 0:
return render.index(schedules, self.form, "Cedula o email no encontrados.")
else:
if student[0]["schedule_id"] != 8:
return render.index(schedules, self.form, "Estudiante con horario ya registrado.")
else:
sched = db.query(
"SELECT description, capacity FROM schedules WHERE sched_id = $id",
vars = {'id':form.d.horario}
)
if len(sched) == 0:
return render.index(schedules, self.form, "ERROR: Horario no encontrado.")
else:
x = 0
for s in sched:
if x > 0:
raise Exception("POOTIS")
desc = s['description']
cap = int(s['capacity'])
x += 1
if cap <= 0:
return render.index(schedules, self.form, "Horario agotado.")
else:
db.query(
"UPDATE schedules SET capacity = $cap where sched_id = $id",
vars = {
'id':form.d.horario,
'cap':str((cap - 1))
}
)
db.query(
"UPDATE students " +
"SET schedule_id = $sched " +
"WHERE id_CARD = $id AND email = $email",
vars = {
'id':str(form.d.cedula),
'email':form.d.email.upper(),
'sched':form.d.horario
}
)
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"
)
web.sendmail(
'',
form.d.email.lower(),
'OECI - Laboratorio Registrado',
'Ha registrado exitosamente el horario de laboratorio: ' + desc
)
return render.index(schedules, self.form, "Horario registrado exitosamente.")
if __name__ == "__main__":
web.config.smtp_server = ''
web.config.smtp_port = -1
web.config.smtp_username = ''
web.config.smtp_password = ''
web.config.smtp_starttls = True
app = web.application(urls, globals())
app.run()

96
db_schema.sql Normal file
View File

@@ -0,0 +1,96 @@
-- MySQL dump 10.13 Distrib 5.5.46, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: db_name
-- ------------------------------------------------------
-- Server version 5.5.46-0+deb7u1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!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 `rooms`
--
DROP TABLE IF EXISTS `rooms`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
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;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `schedules`
--
DROP TABLE IF EXISTS `schedules`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `schedules` (
`sched_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`description` varchar(30) DEFAULT NULL,
`capacity` int(11) NOT NULL,
`room_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;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `sections`
--
DROP TABLE IF EXISTS `sections`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
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;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `students`
--
DROP TABLE IF EXISTS `students`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `students` (
`student_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_card` int(10) unsigned NOT NULL,
`first_name` varchar(60) NOT NULL,
`last_name` varchar(60) NOT NULL,
`email` varchar(100) NOT NULL,
`class_id` int(10) unsigned NOT NULL,
`schedule_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`student_id`),
KEY `fk_class` (`class_id`),
KEY `fk_sched` (`schedule_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;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2015-11-04 16:12:11

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

39
static/styles.css Normal file
View File

@@ -0,0 +1,39 @@
body{ background:#66ADED; }
h1{ color:#fff; }
h2{ color:#fff; }
h3{ color:#13238f; }
div.text_style{ text-align:center; }
p.warning{ color:#FF0000; }
#banner{
background-image:url(header-CICORE-new.png);
background-size:100%;
height:125px;
border:5px solid black;
font-variant:small-caps;
vertical-align:middle
/* -webkit-border-radius:15px 15px 15px 15px;
-moz-border-radius:15px 15px 15px 15px;
border-radius:15px 15px 15px 15px;*/
}
#main_table{
padding:4px;
border-width:4px;
border-spacing:10px;
margin-top:0;
margin-right:auto;
margin-bottom:0;
margin-left:auto;
}
#main_cell{
border-color:#000;
border-width:1px;
border-style:solid;
background-color:#fff;
padding:10px;
-webkit-border-radius:12px 12px 12px 12px;
-moz-border-radius:12px 12px 12px 12px;
border-radius:12px 12px 12px 12px;
/* -webkit-box-shadow:0 0 10px #676767;
-moz-box-shadow:0 0 10px #676767;
box-shadow:0 0 10px #676767;*/
}

85
templates/index.html Normal file
View File

@@ -0,0 +1,85 @@
$def with (schedules, form, error_text)
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>
GD-OECI :: Semestre 2-2015 - Inscripci&oacute;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> Organizaci&oacute;n y Estructura del Computador 1 </h1>
<h2> Inscripci&oacute;n de laboratorios :: Semestre 2-2015 </h2>
</div>
</td>
</tr>
<tr>
<td colspan=2>
<hr />
</td>
</tr>
<tr>
<td>
<div class=text_style>
<h3>
Datos para la inscripci&oacute;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>
</tr>
</table>
<div class=text_style>
<p style=text-align:center;>
Laboratorio ICARO, Escuela de Computaci&oacute;n, Facultad de Ciencias, Universidad Central de Venezuela.
</p>
</div>
</body>
</html>