Example #1
0
def admin_hoteles():
    if not current_user.is_admin():
        return redirect(url_for('index'))
    form = CreateHotelForm(request.form)
    hoteles_p = []
    for hotel in Hotel.select():
        nombre = hotel.nombre
        region = hotel.region
        ciudad = hotel.ciudad
        direccion = hotel.direccion
        formd = DeleteHotelForm(request.form)
        hoteles_p.insert(len(hoteles_p),{'nombre':nombre,
        'region':region,'ciudad':ciudad,'direccion':direccion,'form':formd })
    if form.validate_on_submit():
        try:
            hotel = Hotel.get(Hotel.nombre == form.nombre.data)
            if hotel:
                return render_template('admin_hoteles.html',hoteles=hoteles_p, form=form, error=u'nombre de hotel ya existente en sistema')
        except:
            Hotel.create(
                nombre=form.nombre.data,
                region=form.region.data,
                ciudad=form.ciudad.data,
                direccion=form.direccion.data,
                numeroAtencion=form.numeroAtencion.data,
                emailContacto=form.emailContacto.data
            )
        return redirect(url_for('admin_hoteles'))

    return render_template('admin_hoteles.html',hoteles=hoteles_p,form=form)
Example #2
0
def admin_habitaciones():
    if not current_user.is_admin():
        return redirect(url_for('index'))
    form = CreateHabitacionForm(request.form)
    tipos_habitacion_choices = []
    for tipo_habitacion in TipoHabitacion.select():
        valor = u'Tipo: {},Numero Personas: {},Precio: {}'.format(tipo_habitacion.nombre,tipo_habitacion.numeroPersonas,tipo_habitacion.precio)
        tipos_habitacion_choices.insert(len(tipos_habitacion_choices),(tipo_habitacion.id,valor))
    form.tipoHabitacion.choices = tipos_habitacion_choices
    hoteles_choices = []
    for hotel in Hotel.select():
        valor = u'Hotel: {}'.format(hotel.nombre)
        hoteles_choices.insert(len(hoteles_choices),(hotel.id,valor))
    form.hotel.choices = hoteles_choices
    habitaciones_p = []
    for habitacion in Habitacion.select():
        numeroHabitacion = habitacion.numeroHabitacion
        piso = habitacion.piso
        tipoHabitacion = habitacion.tipoHabitacion.nombre
        hotel = habitacion.hotel.nombre
        formd = DeleteHabitacionForm(request.form)
        habitaciones_p.insert(len(habitaciones_p),{'numeroHabitacion':numeroHabitacion,
        'piso':piso,'tipoHabitacion':tipoHabitacion,'hotel':hotel,'form':formd })
    if form.validate_on_submit():
        try:
            tipoHabitacion = TipoHabitacion.get(TipoHabitacion.numeroHabitacion == form.numeroHabitacion.data)
            if tipoHabitacion:
                return render_template('admin_habitaciones.html',habitaciones=habitaciones_p, form=form, error=u'habitacion ya existente en sistema')
        except:
            Habitacion.create(
                numeroHabitacion=form.numeroHabitacion.data,
                piso=form.piso.data,
                tipoHabitacion=form.tipoHabitacion.data,
                hotel=form.hotel.data
            )
        return redirect(url_for('admin_habitaciones'))

    return render_template('admin_habitaciones.html',habitaciones=habitaciones_p,form=form)