Esempio n. 1
0
def edit_hotel(request, hotelID):
    try:
        hotel = Hotel.objects.get(pk=hotelID)
        init = {'name': hotel.name, 'hotelier': hotel.hotelier, 'star_number': hotel.star_number,
                'credit_number': hotel.credit_number, 'address': hotel.address, 'city' : hotel.city, 'phone_number' : hotel.phone_number,
                'lake': hotel.lake, 'sport': hotel.sport, 'breakfast': hotel.breakfast, 'wife': hotel.wifi, 'parking': hotel.parking, 'pool': hotel.pool, 'cafe':hotel.cafe}
        if request.method == "POST":
            form = HotelForm(request.POST)
            if form.is_valid():
                hotel.name = form.cleaned_data['name']
                hotel.star_number = form.cleaned_data['star_number']
                hotel.credit_number = form.cleaned_data['credit_number']
                hotel.address = form.cleaned_data['address']
                hotel.city = form.cleaned_data['city']
                hotel.phone_number = form.cleaned_data['phone_number']
                hotel.lake = form.cleaned_data['lake']
                hotel.sport = form.cleaned_data['sport']
                hotel.breakfast = form.cleaned_data['breakfast']
                hotel.pool = form.cleaned_data['pool']
                hotel.parking = form.cleaned_data['parking']
                hotel.cafe = form.cleaned_data['cafe']
                hotel.wifi = form.cleaned_data['wifi']
                hotel.save()
                return render(request, 'thanks.html', {'message': "اطلاعات جدید هتل با موفقیت به ثبت رسید", 'redir': '/simorgh/edit/hotel/'+ hotelID})
        else:
            form = HotelForm(initial=init)
            return render(request, 'hotel/edit.html', {'form': form, 'photoForm': HotelPhotoForm(), 'id': hotel.id, 'type': 'hotel', 'images': hotel.hotelphoto_set.all(), 'rooms': hotel.room_set.all()})
    except Hotel.DoesNotExist:
        return render(request, 'thanks.html', {'message': "هتل مورد نظر وجود ندارد.", 'redir' : '/simorgh/profile/'})
Esempio n. 2
0
def add_hotel(request):
    if request.method == "POST":
        form = HotelForm(request.POST)
        if form.is_valid():
            hotel = form.save(commit=False)
            hotel.hotelier_id = request.user.id
            hotel.save()
            return render(request, "thanks.html", {'message': 'هتل شما به ثبت رسید.', 'redir': '/simorgh/profile/hotels_list/'})
    else:
        form = HotelForm()
    return render(request, "hotel/add_hotel.html", {'form': form})