Example #1
0
def reservar():
    form = ReserveForm(request.form)
    choices = []
    for habitacion in Habitacion.select():
        valor = u'Habitacion: {}, Hotel: {}, Precioxdia: {}'.format(habitacion.numeroHabitacion,habitacion.hotel.nombre,habitacion.tipoHabitacion.precio)
        choices.insert(len(choices),(habitacion.id,valor))
    form.habitacion.choices = choices
    if form.validate_on_submit():
        try:
            reserva = Reserva.get(Reserva.fechaPedido == form.fechaPedido.data,Reserva.habitacion == form.habitacion.data)
            if reserva:
                return render_template('reserva.html', form=form, error=u'reserva ya existente en sistema')
        except:
            fechaTermino = form.fechaPedido.data + timedelta(days=int(form.numeroDias.data))
            Reserva.create(
                fechaPedido=form.fechaPedido.data,
                fechaTermino=fechaTermino,
                cliente=current_user.id,
                habitacion=form.habitacion.data
            )
            return redirect(url_for('index'))
        try:
            return redirect(url_for('index'))
        except:
            return render_template('reserva.html', form=form, error=u'Error')

    return render_template('reserva.html', form=form)
Example #2
0
def reserva_delete():
    form = DeleteReserveForm(request.form)
    if form.validate_on_submit():
        try:
            reserva = Reserva.get(Reserva.id == form.reserva_id.data,Reserva.cliente == current_user.id,Reserva.cancelado == False)
            reserva.delete_instance()
        except:
            None
    return redirect(url_for('ver_reservas'))
Example #3
0
def admin_reservas_delete():
    if not current_user.is_admin():
        return redirect(url_for('index'))
    form = DeleteReserveForm(request.form)
    if form.validate_on_submit():
        try:
            reserva = Reserva.get(Reserva.id == form.reserva_id.data)
            reserva.delete_instance()
        except:
            None
    return redirect(url_for('admin_reservas'))
Example #4
0
def admin_reservas_accept():
    if not current_user.is_admin():
        return redirect(url_for('index'))
    form = AcceptReserveForm(request.form)
    if form.validate_on_submit():
        try:
            print vars(form.reserva_id)
            reserva = Reserva.get(Reserva.id == form.reserva_id.data)
            reserva.cancelado = True
            reserva.save()
        except:
            None
    return redirect(url_for('admin_reservas'))
Example #5
0
def admin_reservas():
    if not current_user.is_admin():
        return redirect(url_for('index'))
    reserva_p = []
    for reserva in Reserva.select().where(Reserva.cancelado == False):
        fechaPedido = reserva.fechaPedido
        delta = reserva.fechaTermino - reserva.fechaPedido
        numeroDias = delta.days
        nombreCliente = reserva.cliente.nombre
        nombreHotel = reserva.habitacion.hotel.nombre
        numeroHabitacion = reserva.habitacion.numeroHabitacion
        forma = AcceptReserveForm(request.form,reserva_id=str(reserva.id))
        formd = DeleteReserveForm(request.form,reserva_id=str(reserva.id))
        reserva_p.insert(len(reserva_p),{'id':reserva.id,'fechaPedido':fechaPedido,
        'numeroDias':numeroDias,'nombreCliente':nombreCliente,'nombreHotel':nombreHotel,'numeroHabitacion':numeroHabitacion,
        'forma':forma,'formd':formd })

    return render_template('admin_reservas.html',reservas=reserva_p)