Exemplo n.º 1
0
def edit_hotel(key_id, uid):
    region = Region.retrieve_by_id(key_id)
    if not region:
        return redirect(url_for('hotel.admin.index'))
    for i, hotel in enumerate(region.hotels):
        if hotel.uid == uid:
            break
    else:
        return redirect(url_for('hotel.admin.reg_edit', key_id=key_id))
    if request.method == 'POST' and 'del_hotel' in request.form:
        del region.hotels[i]
        region.put()
        return redirect(url_for('hotel.admin.reg_edit', key_id=key_id))
    form = HotelForm(obj=hotel)
    if request.method == 'POST' and form.validate_on_submit():
        form.populate_obj(region.hotels[i])
        set_geo(form, region.hotels[i])
        region.put()
        return redirect(url_for('hotel.admin.reg_edit', key_id=key_id))
    get_geo(hotel, form)
    return render_template(
        'hotel/admin/edit_hotel.html',
        hform=form,
        region=region,
        hotel=hotel
    )
Exemplo n.º 2
0
def add_hotel(key_id):
    region = Region.retrieve_by_id(key_id)
    if not region:
        return redirect(url_for('hotel.admin.index'))
    if 'cancel_hotel' in request.form:
        return redirect(url_for('hotel.admin.reg_edit', key_id=key_id))
    form = HotelForm()
    if form.validate_on_submit():
        hotel = Hotel(uid=str(uuid.uuid1()).replace('-',''))
        form.populate_obj(hotel)
        set_geo(form, hotel)
        region.hotels.append(hotel)
        region.put()
        return redirect(url_for('hotel.admin.reg_edit', key_id=key_id))
    return render_template(
        'hotel/admin/add_hotel.html',
        hform=form,
        region=region
    )