def editar_quarto(quarto_id, user_id):
    form_reserva = VerificarDisponibilidade()
    form = AdicionarQuarto()
    user = User.query.filter_by(id=user_id).first()
    user_id_room = Rooms.query.filter_by(id=quarto_id).join(Hotels, (Rooms.hotel_id == Hotels.id)).add_columns(Hotels.user_id).add_columns(Hotels.id)
    if (([i.user_id for i in user_id_room][0] != user_id) and (user.hotel_id != [i for i in user_id_room][0][2])):
        return '<h1>Erro! Você não pode acessar este conteúdo!</h1>'
    if (user.hotel_id is None):
        hoteis = Hotels.query.order_by(Hotels.created_at)
        form.hotel_id.choices = [(hotel.id, hotel.name) for hotel in hoteis if (hotel.user_id == user_id)]
    else:
        hoteis = Hotels.query.filter_by(id=user.hotel_id).order_by(Hotels.created_at)
        form.hotel_id.choices = [(hotel.id, hotel.name) for hotel in hoteis]
    if form.validate_on_submit():
        if (request.method == 'POST'):
            to_update = Rooms.query.get_or_404(quarto_id)
            to_update.hotel_id = request.form['hotel_id']
            to_update.number = request.form['number']
            to_update.name = request.form['name']
            to_update.short_description = request.form['short_description']
            to_update.kind = request.form['kind']
            to_update.phone_extension = request.form['phone_extension']
            to_update.price = float(request.form['price'].replace('.', '').replace(',', '.'))
            to_update.guest_limit = request.form['guest_limit']
            db.session.commit()
            flash('Quarto editado com sucesso!', 'success')
        return redirect(url_for('ocupacao_quartos_endpoint', id=request.form['hotel_id']))
    room = Rooms.query.filter_by(id=quarto_id).first()
    form.hotel_id.default = room.hotel_id
    form.process()
    form.number.data = room.number
    form.name.data = room.name
    form.short_description.data = room.short_description
    form.kind.data = room.kind
    form.phone_extension.data = room.phone_extension
    form.price.data = str(room.price).replace('.', ',')
    form.guest_limit.data = room.guest_limit
    return render_template('adicionar_quartos.html', form=form, user=user, quarto=room, titulo='Editar quarto', form_reserva=form_reserva)
def editar_quarto(quarto_id, user_id):
    form_reserva = VerificarDisponibilidade()
    form = AdicionarQuarto()
    user = User.query.filter_by(id=user_id).first()
    user_id_room = Rooms.query.filter_by(id=quarto_id).join(Hotels, (Rooms.hotel_id == Hotels.id)).add_columns(Hotels.user_id).add_columns(Hotels.id)
    if (([i.user_id for i in user_id_room][0] != user_id) and (user.hotel_id != [i for i in user_id_room][0][2])):
        return '<h1>Erro! Você não pode acessar este conteúdo!</h1>'
    if (user.hotel_id is None):
        hoteis = Hotels.query.order_by(Hotels.created_at)
        form.hotel_id.choices = [(hotel.id, hotel.name) for hotel in hoteis if (hotel.user_id == user_id)]
    else:
        hoteis = Hotels.query.filter_by(id=user.hotel_id).order_by(Hotels.created_at)
        form.hotel_id.choices = [(hotel.id, hotel.name) for hotel in hoteis]
    if form.validate_on_submit():
        if (request.method == 'POST'):
            to_update = Rooms.query.get_or_404(quarto_id)
            to_update.hotel_id = request.form['hotel_id']
            to_update.number = request.form['number']
            to_update.name = request.form['name']
            to_update.short_description = request.form['short_description']
            to_update.kind = request.form['kind']
            to_update.phone_extension = request.form['phone_extension']
            to_update.price = float(request.form['price'].replace('.', ).replace(',', '.'))
            to_update.guest_limit = request.form['guest_limit']
            db.session.commit()
            flash('Quarto editado com sucesso!', 'success')
        return redirect(url_for('ocupacao_quartos_endpoint', id=request.form['hotel_id']))
    room = Rooms.query.filter_by(id=quarto_id).first()
    form.hotel_id.default = room.hotel_id
    form.process()
    form.number.data = room.number
    form.name.data = room.name
    form.short_description.data = room.short_description
    form.kind.data = room.kind
    form.phone_extension.data = room.phone_extension
    form.price.data = str(room.price).replace('.', ',')
    form.guest_limit.data = room.guest_limit
    return render_template('adicionar_quartos.html', form=form, user=user, quarto=room, titulo='Editar quarto', form_reserva=form_reserva)