Skip to content

Commit

Permalink
fix: modificacion y eliminacion de paquetes turisticos #99
Browse files Browse the repository at this point in the history
  • Loading branch information
juancruz1990 committed Aug 12, 2023
1 parent 40613fa commit 439781e
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 47 deletions.
3 changes: 2 additions & 1 deletion hotel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, *args, **kwargs):
class PaqueteTuristicoForm(forms.ModelForm):
habitaciones = forms.MultipleChoiceField(
choices=[],
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
widget=forms.SelectMultiple(attrs={'class': 'form-control'}),
)

class Meta:
Expand All @@ -67,6 +67,7 @@ def __init__(self, *args, **kwargs):
self.fields['inicio'].widget.attrs.update({'class': 'form-control'})
self.fields['fin'].widget.attrs.update({'class': 'form-control'})
self.fields['habitaciones'].widget.attrs.update({'class': 'form-control'})



class AgregarTipoAHotelForm(ModelForm):
Expand Down
7 changes: 5 additions & 2 deletions hotel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ def dar_baja(self):

def dar_alta(self):
self.baja=False




# Temporada Alta
class TemporadaAlta(models.Model):
Expand Down Expand Up @@ -277,5 +276,9 @@ def get_pasajeros(self):

def get_habitaciones(self):
return self.habitaciones.all()

def set_habitaciones(self , habitaciones):
self.habitaciones = habitaciones
self.save()


176 changes: 156 additions & 20 deletions hotel/templates/hotel/modals/modal_paqueteTuristicoHotel_modificar.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,164 @@
<div class="modal-xl modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title " id="exampleModalLabel">
MODIFICAR PAQUETE TURISTICO: {{paquete.nombre.upper}}

</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>



{% load static %}

<html>

<head>
<link rel="icon" type="image/png" href="/static/icons/hotelIco.png">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--SWEET ALERT CSS-->
<link rel="stylesheet" href="{% static '/css/sweetalert2.css' %}">
<!--BOOTSTRAP CSS-->
<link rel="stylesheet" href="{% static '/css/bootstrap.min.css' %}">

<!-- Bootstrap CSS para datatable-->
<link rel="stylesheet" href="{% static '/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static '/css/dataTables.bootstrap4.min.css' %}">
<!-- Bootstrap CSS para datatable-->

<!-- FONTAWESOME -->
<script src="{% static '/js/d91d4c71ff.js' %}"></script>

<!--CUSTOM CSS-->
<link rel="stylesheet" href="{% static '/css/styleBase.css' %}">
<link rel="stylesheet" href="{% static '/css/modal.css' %}">
<link rel="stylesheet" href="{% static '/css/botones.css' %}">


{% block extra_css %}

{% endblock extra_css %}
</head>

<body class="bodyComplete">


<!-- HEADER -->
<div class="container-fluid mainHeader p-3 fixed-top">
<div class="row">
<div class="col-2">
{% block header %}

{% endblock header %}

</div>
<div class="col-8">
{% block headerContenido %}
{% endblock headerContenido %}

{% block carrito %}
{% endblock carrito %}
</div>
<div class="col-2">

<button onclick="location.href='/core/logout'" style="text-decoration:none; align-items:right;"
class="rounded-1 btn btn-lg btn-outline-secondary text-white float-center mt-1 "> Cerrar Sesion
</button>

</div>
</div>
<form action="{% url 'hotel:modalModificarPaqueteTuristicoHotel' hotel.pk paquete.pk %}" method="POST">
<div class="modal-body">
</div>

<!-- opciones + contenido -->
<div class="container-fluid " >
<!-- CONTENIDO -->
<div class="col-12 " style="top: 100px;" id="main">
<div class="modal-xl modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title " id="exampleModalLabel">
MODIFICAR PAQUETE TURISTICO: {{paquete.nombre.upper}}

</h5>
<a type="button" class="close" data-dismiss="modal" aria-label="Close" href="{% url 'hotel:vistaHotel' hotel.pk %}">
<span aria-hidden="true">&times;</span>
</a>
</div>
<form action="{% url 'hotel:modalModificarPaqueteTuristicoHotel' hotel.pk paquete.pk %}" method="POST">
<div class="modal-body" >

{% csrf_token %}

{{formulario.as_p}}

</div>
<div class="modal-footer">
<a href="{% url 'hotel:vistaHotel' hotel.pk %}">Cerrar</a>
<button type="submit" name="accion" class="Guardar" value="categoria">Guardar</button>

</div>
</form>
</div>
</div>

{% csrf_token %}

{{formulario.as_p}}

</div>
<div class="modal-footer">
<button type="dismiss" class="Cerrar" data-dismiss="modal">Cerrar</button>
<button type="submit" name="accion" class="Guardar" value="categoria">Guardar</button>
</div>

<!-- Footer -->
<div class="footer text-center mb-0 fixed-bottom">
<div class="container">
{% block footer %}

{% endblock footer %}
<p class="m-0 mbt1 text-white">&copy; UNPSJB - GRUPO 1 - DESARROLLO DE SOFTWARE</p>
</div>
</form>
</div>
</div>


<!--sweet alert2-->

<script src="{% static '/js/[email protected]' %}"></script>

<!-- Bootstrap 4.5-->
<script src="{% static '/js/jquery-3.5.1.js' %}"></script>
<script src="{% static '/js/bootstrap.bundle.js' %}"></script>

<script src="{% static '/js/bootstrap-datetimepicker.min.js' %}"></script>

<!--dataTable jquery + bootstrap + popper include-->
<script src="{% static 'js/jquery.dataTables.min.js'%}"></script>
<script src="{% static '/js/dataTables.bootstrap4.min.js'%}"></script>

<!--scripts personalizados-->
<script src="{% static '/js/main.js' %}"></script>

<!--sweet alert2-->
<script src="{% static '/js/[email protected]' %}"></script>



<!--dataTable jquery + bootstrap + popper include-->
<script src="{% static '/js/jquery.dataTables.min.js'%}"></script>
<script src="{% static '/js/dataTables.bootstrap4.min.js'%}"></script>


<!--scripts personalizados-->

<script src="{% static '/js/main.js' %}"></script>

<!--CUSTOM CSS-->
<link rel="stylesheet" href="{% static '/css/styleBase.css' %}">
<link rel="stylesheet" href="{% static '/css/modal.css' %}">
<link rel="stylesheet" href="{% static '/css/botones.css' %}">

{% block extrajs %}

<script type="text/javascript">
$(document).ready(function () {
$('.datepicker').datetimepicker();
$(".datepicker").datetimepicker({ sideBySide: true, format: 'DD/MM/YYYY' })
});
</script>
{% endblock %}

</body>


</html>



30 changes: 18 additions & 12 deletions hotel/templates/hotel/vistaHotelAdmin.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,25 @@ <h3 class="mb-5">PAQUETES</h3>
<td>
<center>
{% if paquete.estoy_vigente %}
<button type="button" class="btn btn-warning" data-toggle="modal"
data-target="#modificarPaqueteTuristicoHotel"
onclick="abrir_modal('{% url 'hotel:modalModificarPaqueteTuristicoHotel' hotel.pk paquete.pk%}', '#modificarPaqueteTuristicoHotel');"
title="Editar">
<i class="fas fa-edit"></i>
</button>
<button type="button" class="btn btn-warning" data-toggle="modal"
data-target="#modificarPaqueteTuristicoHotel"
onclick="abrir_modal('{% url 'hotel:modalModificarPaqueteTuristicoHotel' hotel.pk paquete.pk%}', '#modificarPaqueteTuristicoHotel');"
title="Editar">
<i class="fas fa-edit"></i>
</button>
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#eliminarPaqueteTuristicoHotel"
onclick="abrir_modal('{% url 'hotel:modalEliminarPaqueteTuristicoHotel' hotel.pk paquete.pk%}', '#eliminarPaqueteTuristicoHotel');"
title="Eliminar">
<i class="fas fa-trash"></i>
</button>
{% elif paquete.estoy_vencido %}
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#eliminarPaqueteTuristicoHotel"
onclick="abrir_modal('{% url 'hotel:modalEliminarPaqueteTuristicoHotel' hotel.pk paquete.pk%}', '#eliminarPaqueteTuristicoHotel');"
title="Eliminar">
<i class="fas fa-trash"></i>
</button>
<button type="button" class="btn btn-danger" data-toggle="modal"
data-target="#eliminarPaqueteTuristicoHotel"
onclick="abrir_modal('{% url 'hotel:modalEliminarPaqueteTuristicoHotel' hotel.pk paquete.pk%}', '#eliminarPaqueteTuristicoHotel');"
title="Eliminar">
<i class="fas fa-trash"></i>
</button>
{% elif paquete.estoy_vendido %}

{% endif %}
Expand Down
47 changes: 35 additions & 12 deletions hotel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,29 +309,52 @@ def paqueteTuristicoHotelCrear(request, hotel):


def paqueteTuristicoHotelModificar(request,hotel,paquete):
hotelInstancia=get_object_or_404(Hotel, pk=hotel)
id_hotel = hotel
hotelInstancia=get_object_or_404(Hotel, pk=id_hotel)
paqueteInstancia=get_object_or_404(PaqueteTuristico, pk=paquete)
form = PaqueteTuristicoForm(request.POST or None,instance=paqueteInstancia)
if request.method == "POST":
fecha_inicio = request.POST['inicio']
fecha_fin = request.POST['fin']
lista_habitaciones_seleccion = request.POST.getlist('habitaciones')
lista_filtrada_habitaciones=[]
for elemento in lista_habitaciones_seleccion:
habitacion = Habitacion.objects.get(id = elemento)
lista_filtrada_habitaciones.append(habitacion)
paquetes = list(habitacion.paqueteturistico.all())
for x in paquetes:
if(x.id == paquete):
paquetes.remove(x)
for paq in paquetes:
if (hay_fechas_superpuestas(fecha_inicio ,fecha_fin , str(paq.inicio), str(paq.fin))):
form.add_error('habitaciones', 'alguna de las habitaciones seleccionadas ya tienen un paquete para ese periodo de fechas')
form.fields['habitaciones'].choices=[(c.pk,c.numero) for c in Habitacion.objects.filter(hotel=hotelInstancia)]
return render(request, "hotel/modals/modal_paqueteTuristicoHotel_modificar.html",{'formulario':form,'hotel':hotelInstancia,'paquete':paqueteInstancia})

form.fields['habitaciones'].choices=[(c.pk,c.numero) for c in Habitacion.objects.filter(hotel=hotelInstancia)]

if form.is_valid():
paquete=form.save(commit=False)
paquete.save()
print(paqueteInstancia)
paqueteInstancia.nombre = request.POST["nombre"]
paqueteInstancia.coeficiente = request.POST["coeficiente"]
paqueteInstancia.inicio = request.POST["inicio"]
paqueteInstancia.fin = request.POST["fin"]
paqueteInstancia.habitaciones.set(lista_habitaciones_seleccion)
paqueteInstancia.save()
return redirect('hotel:paqueteTuristicoHotel', hotel)
else:
form.fields['habitaciones'].choices=[(c.pk,c.numero) for c in Habitacion.objects.filter(hotel=hotelInstancia)]
arregloHabitacionesSeleccionadas = paqueteInstancia.habitaciones.all()
preseleccion=[]
for habitacion in arregloHabitacionesSeleccionadas:
preseleccion.append(habitacion.pk)
form.initial['habitaciones'] = preseleccion
form.initial['inicio']=str(paqueteInstancia.inicio)
form.initial['fin']=str(paqueteInstancia.fin)
dicc={'nombre','habitaciones','inicio','fin'}
for campo in dicc:
form.fields[campo].widget.attrs['style'] = 'display:none;'
form.fields[campo].widget.attrs['style'] = ''
form.fields[campo].label = ''
form.fields['coeficiente'].label='coeficiente de descuento'
return render(request, "hotel/modals/modal_paqueteTuristicoHotel_modificar.html",{'formulario':form,'hotel':hotelInstancia,'paquete':paqueteInstancia})
form.fields['nombre'].label='nombre'
form.fields['inicio'].label='inicio'
form.fields['fin'].label='fin'
form.fields['habitaciones'].label='Habitaciones'
form.fields['habitaciones'].choices=[(c.pk,c.numero) for c in Habitacion.objects.filter(hotel=hotelInstancia)]
return render(request, "hotel/modals/modal_paqueteTuristicoHotel_modificar.html",{'formulario':form,'hotel':hotelInstancia,'paquete':paqueteInstancia})

def paqueteTuristicoHotelEliminar(request,hotel,paquete):
hotelInstancia=get_object_or_404(Hotel, pk=hotel)
Expand Down

0 comments on commit 439781e

Please sign in to comment.