Browse Source

Cambio la forma de reservar.

politica
Celestino Rey 1 year ago
parent
commit
84e54bf4b5
4 changed files with 69 additions and 54 deletions
  1. +23
    -5
      Padel/padel/reservas.py
  2. +4
    -2
      Padel/padel/templates/_navegacion.html
  3. +2
    -2
      Padel/padel/templates/reservas/misreservas.html
  4. +40
    -45
      Padel/padel/templates/reservas/reservar.html

+ 23
- 5
Padel/padel/reservas.py View File

@ -57,10 +57,11 @@ def reservar(diaelegido):
for fila in reservas: for fila in reservas:
print("Fecha ", fila["fecha"] , ". Hora: ", fila["hora"]) print("Fecha ", fila["fecha"] , ". Hora: ", fila["hora"])
return render_template("reservas/reservar.html", diaelegido=diaelegido, name=current_user.name)
return render_template("reservas/reservar.html", diaelegido=diaelegido, name=current_user.name, reservas=reservas)
# Ruta para eliminar una reserva # Ruta para eliminar una reserva
@bp.route('/eliminar_reserva/<int:id>', methods=['POST']) @bp.route('/eliminar_reserva/<int:id>', methods=['POST'])
@login_required
def eliminar_reserva(id): def eliminar_reserva(id):
db = get_db() db = get_db()
@ -71,6 +72,20 @@ def eliminar_reserva(id):
return redirect(url_for('reservas.misreservas')) return redirect(url_for('reservas.misreservas'))
@bp.route('/actualizar_reserva/<int:id>', methods=['POST'])
@login_required
def actualizar_reserva(id):
db = get_db()
db.execute(
"UPDATE reservas SET nombre=? WHERE id=?", (current_user.name, id,)
)
db.commit()
return redirect(url_for('reservas.misreservas'))
@bp.route("/eligedia", methods=['GET', 'POST']) @bp.route("/eligedia", methods=['GET', 'POST'])
@login_required @login_required
def eligedia(): def eligedia():
@ -90,7 +105,7 @@ def eligedia():
db = get_db() db = get_db()
horashoy = db.execute( horashoy = db.execute(
"SELECT * FROM horas WHERE fecha=?", (diaelegido,)
"SELECT * FROM reservas WHERE fecha=?", (diaelegido,)
).fetchall() ).fetchall()
db.commit() db.commit()
@ -99,9 +114,12 @@ def eligedia():
print("No hay horas para hoy") print("No hay horas para hoy")
db = get_db() db = get_db()
db.execute(
"INSERT INTO horas (fecha, hora0900, hora1000, hora1100, hora1200, hora1300, hora1400, hora1500, hora1600, hora1700, hora1800, hora1900, hora2000, hora2100, hora2200) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (diaelegido,"-","-","-","-","-","-","-","-","-","-","-","-","-","-",),
)
for hora in range(8,18):
print("hora: %2d", hora)
db.execute(
"INSERT INTO reservas (nombre, fecha, hora) VALUES (?, ?, ?)", ("-", diaelegido, "%02d:00" % hora,),
)
db.commit() db.commit()
horashoy = db.execute( horashoy = db.execute(


+ 4
- 2
Padel/padel/templates/_navegacion.html View File

@ -4,6 +4,8 @@
<div id="navbarMenuHeroA" class="navbar-menu"> <div id="navbarMenuHeroA" class="navbar-menu">
<div class="navbar-end"> <div class="navbar-end">
<a href="{{ url_for('auth.index') }}" class="navbar-item">Inicio</a>
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<!-- <!--
<a href="{{ url_for('paginas.inicio') }}" class="navbar-item"> <a href="{{ url_for('paginas.inicio') }}" class="navbar-item">
@ -12,16 +14,16 @@
<a href="{{ url_for('paginas.acerca') }}" class="navbar-item"> <a href="{{ url_for('paginas.acerca') }}" class="navbar-item">
Acerca de... Acerca de...
</a> </a>
-->
<a href="{{ url_for('reservas.misreservas') }}" class="navbar-item"> <a href="{{ url_for('reservas.misreservas') }}" class="navbar-item">
Mis reservas Mis reservas
</a> </a>
-->
<a href="{{ url_for('reservas.eligedia') }}" class="navbar-item"> <a href="{{ url_for('reservas.eligedia') }}" class="navbar-item">
Reservar Reservar
</a> </a>
<a href="{{ url_for('auth.logout') }}" class="navbar-item">Salir</a> <a href="{{ url_for('auth.logout') }}" class="navbar-item">Salir</a>
{% else %} {% else %}
<a href="{{ url_for('auth.index') }}" class="navbar-item">Inicio</a>
<a href="{{ url_for('auth.login') }}" class="navbar-item">Entrar</a> <a href="{{ url_for('auth.login') }}" class="navbar-item">Entrar</a>
<a href="{{ url_for('auth.signup') }}" class="navbar-item">Registrarse</a> <a href="{{ url_for('auth.signup') }}" class="navbar-item">Registrarse</a>
{% endif %} {% endif %}


+ 2
- 2
Padel/padel/templates/reservas/misreservas.html View File

@ -23,7 +23,7 @@
{% for reserva in reservas %} {% for reserva in reservas %}
<tr> <tr>
<td>{{reserva.id}}</td>
<td>{{ reserva.id }}</td>
<td>{{ reserva.nombre }}</td> <td>{{ reserva.nombre }}</td>
<td>{{ reserva.fecha }}</td> <td>{{ reserva.fecha }}</td>
<td>{{ reserva.hora }}</td> <td>{{ reserva.hora }}</td>
@ -34,5 +34,5 @@
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</ul>
</table>
{% endblock content %} {% endblock content %}

+ 40
- 45
Padel/padel/templates/reservas/reservar.html View File

@ -1,56 +1,51 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block header %} {% block header %}
<h2>{% block title %}Hacer una nueva reserva{% endblock title %}</h2>
<h2 class="subtitle is-1 has-text-centered">
{% block title %}Hacer una nueva reserva{% endblock title %}
</h2>
{% endblock header %} {% endblock header %}
{% block content %} {% block content %}
<form action="/inserta/{{ diaelegido }}" method="post">
<!--
<div class="field">
<label for="nombre">Nombre:</label>
<input type="text" id="nombre" name="nombre" required class="form-control"><br>
</div>
-->
<div class="field">
<!-- <label for="fecha">Fecha:</label>
<input type="date" id="fecha" name="fecha" required class="form-control" min="{{ diaelegido }}", max="{{ diaelegido }}", value={{ diaelegido }}""><br> -->
<textarea class="textarea" rows="1">Fecha de la reserva: {{ diaelegido }} </textarea>
</div>
<section class="hero is-primary has-text-centered">
<h1 class="subtitle is-1 has-text-centered">
Estas son las horas disponibles y las ocupadas
</h1>
</section>
<table class="table" id="tablareservas" border = 1>
<thead>
<th id="columnid">ID</th>
<th id="columnnombre">Nombre</th>
<th>Fecha</th>
<th>Hora</th>
<th></th>
</thead>
<div class="field">
<label for="hora">Hora:</label>
<input class="input" type="time" id="hora" name="hora" required class="form-control" list="horas-permitidas"><br>
</div>
<datalist id="horas-permitidas">
<option value="08:00"></option>
<option value="09:00"></option>
<option value="10:00"></option>
<option value="11:00"></option>
<option value="12:00"></option>
<option value="13:00"></option>
<option value="14:00"></option>
<option value="15:00"></option>
<option value="16:00"></option>
<option value="17:00"></option>
</datalist>
<div class="form-group">
<button type="submit" class="button is-medium">Reservar</button>
</div>
</form>
{% for reserva in reservas %}
<tr>
<td>{{ reserva.id }}</td>
<td>{{ reserva.nombre }}</td>
<td>{{ reserva.fecha }}</td>
<td>{{ reserva.hora }}</td>
<td>
<script>
document.getElementById('hora').addEventListener('input', function() {
var val = this.value;
var options = document.getElementById('horas-permitidas').querySelectorAll('option');
var match = Array.from(options).find(function(option) {
return option.value === val;
});
if (!match) {
this.value = '';
}
});
</script>
{% if name == reserva.nombre %}
<form class="form-eliminar" action="{{ url_for('reservas.eliminar_reserva', id=reserva.id) }}" method="post" style="display: inline;">
<button type="submit" class="button is-danger is-small">Eliminar</button>
</form>
{% else %}
{% if reserva.nombre == "-" %}
<form class="form-eliminar" action="{{ url_for('reservas.actualizar_reserva', id=reserva.id) }}" method="post" style="display: inline;">
<button type="submit" class="button is-primary is-small">Reservar</button>
</form>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% endblock content %} {% endblock content %}

Loading…
Cancel
Save