commit 1fefaffecd749e70ef8e64cc01e9f8ea8d36d943 Author: Miguel Angel Astor Romero Date: Wed Nov 4 11:00:20 2015 -0430 First commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95401e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +*.pyo +*~ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..df72e22 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100755 index 0000000..c4e9d68 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +OECI - Lab Register +=================== + +A Web.py application that registers students to the UCV 6001 course. + diff --git a/code.py b/code.py new file mode 100755 index 0000000..a356c91 --- /dev/null +++ b/code.py @@ -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íos.
La cédula debe ser un nú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() diff --git a/db_schema.sql b/db_schema.sql new file mode 100644 index 0000000..4c61370 --- /dev/null +++ b/db_schema.sql @@ -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 diff --git a/static/favicon.png b/static/favicon.png new file mode 100644 index 0000000..6144570 Binary files /dev/null and b/static/favicon.png differ diff --git a/static/header-CICORE-new.png b/static/header-CICORE-new.png new file mode 100644 index 0000000..f9b8f24 Binary files /dev/null and b/static/header-CICORE-new.png differ diff --git a/static/styles.css b/static/styles.css new file mode 100644 index 0000000..eee1110 --- /dev/null +++ b/static/styles.css @@ -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;*/ +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..38991a3 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,85 @@ +$def with (schedules, form, error_text) + + + + + + GD-OECI :: Semestre 2-2015 - Inscripción de laboratorios. + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+
+ +
+
+
+
+

+ Datos para la inscripción. +

+
+
+
+

Horarios disponibles

+
+
+ $if error_text is not None: +
+

$:error_text

+
+
+ $:form.render() +
+
+
+
    + $for sched in schedules: + $if sched.sched_id < 8: +
  • + $sched.description +
    + Capacidad: 15 +
    + Disponibles: + $sched.capacity +
    + Sala: + $sched.name +
  • +
+
+
+
+
+

+ Laboratorio ICARO, Escuela de Computación, Facultad de Ciencias, Universidad Central de Venezuela. +

+
+ +