diff --git a/.env.templates b/.env.templates new file mode 100644 index 000000000..e76fd68cd --- /dev/null +++ b/.env.templates @@ -0,0 +1,3 @@ +FLASK_APP=application.py +FLASK_DEBUG=1 +DATABASE_URL= \ No newline at end of file diff --git a/app.py b/app.py deleted file mode 100644 index d82c51f0d..000000000 --- a/app.py +++ /dev/null @@ -1,6 +0,0 @@ -from flask import Flask -app = Flask(__name__) - -@app.route('/') -def hello_world(): - return 'Hello, World!' diff --git a/application.py b/application.py new file mode 100644 index 000000000..6aef17fbd --- /dev/null +++ b/application.py @@ -0,0 +1,36 @@ +import os +from flask import Flask, request, render_template, redirect, url_for +from dotenv import load_dotenv +from models import db, Estudiantes +load_dotenv() + +app = Flask(__name__) +app.config['SECRET_KEY'] = 'mysecretkey' + +if not os.getenv("DATABASE_URL"): + raise RuntimeError("DATABASE_URL is not set") +app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL') +db.init_app(app) + +@app.route('/') +def lista_estudiantes(): + estudiantes = Estudiantes.query.all() + return render_template('estudiantes.html', estudiantes=estudiantes) + + +@app.route('/Crear', methods=['GET', 'POST']) +def nuevo_estudiante(): + if request.method == 'POST': + nombre = request.form.get('Nombre') + apellido = request.form.get('Apellido') + ciclo = request.form.get('Ciclo') + programa = request.form.get('Programa') + + if nombre and apellido and ciclo and programa: + nuevo_estudiante = Estudiantes(nombre=nombre, apellido=apellido, ciclo=ciclo, programa=programa) + db.session.add(nuevo_estudiante) + db.session.commit() + + return redirect(url_for('lista_estudiantes')) + + return render_template('index.html') diff --git a/crear_tablas.py b/crear_tablas.py new file mode 100644 index 000000000..b8c978bc7 --- /dev/null +++ b/crear_tablas.py @@ -0,0 +1,18 @@ +import os +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from models import * +from dotenv import load_dotenv +load_dotenv() + +app = Flask(__name__) +app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("DATABASE_URL") +app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False +db.init_app(app) + +def main(): + db.create_all() + +if __name__ == "__main__": + with app.app_context(): + main() \ No newline at end of file diff --git a/models.py b/models.py new file mode 100644 index 000000000..ae2fddfe9 --- /dev/null +++ b/models.py @@ -0,0 +1,11 @@ +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() + +class Estudiantes(db.Model): + __tablename__ = "Estudiantes" + id = db.Column(db.Integer, primary_key=True) + nombre = db.Column(db.String, nullable=False) + apellido = db.Column(db.String, nullable=False) + ciclo = db.Column(db.String, nullable=False) + programa = db.Column(db.String, nullable=False) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 147ddd086..d0a5ad093 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/templates/estudiantes.html b/templates/estudiantes.html new file mode 100644 index 000000000..6c9e6b39a --- /dev/null +++ b/templates/estudiantes.html @@ -0,0 +1,26 @@ + + + + + + + + Document + + + + + {% for estudiante in estudiantes %} +
+
  • Nombre: {{ estudiante.nombre }} {{ estudiante.apellido }} - Ciclo: {{ estudiante.ciclo }} - Programa: {{ + estudiante.programa }}
  • +
    + {% endfor %} + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 000000000..9224b4a8c --- /dev/null +++ b/templates/index.html @@ -0,0 +1,37 @@ + + + + + + + + Document + + + + +
    +
    + + + + + + + + + + + + + +
    +
    + + + \ No newline at end of file