Beispiel #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)