예제 #1
0
def reservation_create(request):
    if request.method == 'POST':
        form = ReservationForm(request.POST)
    else:
        form = ReservationForm()
    return save_reservation_form(
        request, form, 'reservation/includes/partial_reservation_create.html')
예제 #2
0
def reservation_update(request, pk):
    reservation = get_object_or_404(Reservation, pk=pk)
    if request.method == 'POST':
        form = ReservationForm(request.POST, instance=reservation)
    else:
        form = ReservationForm(instance=reservation)
    return save_reservation_form(
        request, form, 'reservation/includes/partial_reservation_update.html')
예제 #3
0
def get_menu(request):
    categories = Category.objects.all()
    dishes = Dish.objects.all()
    form = ReservationForm()

    if request.method == 'POST':
        form = ReservationForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            phone = form.cleaned_data['phone']
            email = form.cleaned_data['email']
            date = form.cleaned_data['date']
            time = form.cleaned_data['time']
            persons = form.cleaned_data['persons']
            try:
                Reservation.objects.create(name=name, phone=phone, email=email, date=date, time=time, persons=persons)
            except ValueError as e:
                return HttpResponse(e)
            # return redirect('contact:send_success')
    else:
        form = ReservationForm()

    template = 'menu/menu.html'
    context = {
        'categories': categories,
        'dishes': dishes,
        'form': form
    }
    return render(request, template, context)
예제 #4
0
def reserve(request):
    form = ReservationForm()
    if request.method == "POST":
        form = ReservationForm(request.POST)
        if form.is_valid():
            form.save()
    return render(request, 'reservation/reservation.html', {'form': form})
예제 #5
0
def create_reservation(request):
    reservation = Reservation()
    if request.method == "POST":
        reservation_form = ReservationForm(request.POST)
        contact_form = ContactForm(request.POST)
        pickup_address_form = AddressForm(request.POST, prefix="pickup")
        dropoff_address_form = AddressForm(request.POST, prefix="dropoff")
        
        if reservation_form.is_valid() and contact_form.is_valid() and pickup_address_form.is_valid() and dropoff_address_form.is_valid():
            contact = contact_form.save()
            pickup_address = pickup_address_form.save()
            dropoff_address = dropoff_address_form.save()
            reservation = reservation_form.save(commit=False)
            reservation.customer = contact
            reservation.pickup_address = pickup_address
            reservation.dropoff_address = dropoff_address
            reservation.company = request.user.profile.client
            reservation.save()
            reservation_form.save_m2m()
            return HttpResponseRedirect('/reservation/')
    else:
        reservation_form = ReservationForm(instance=Reservation())
        contact_form = ContactForm(instance=Contact())
        pickup_address_form = AddressForm(instance=Address(), prefix="pickup")
        dropoff_address_form = AddressForm(instance=Address(), prefix="dropoff")
    return render_to_response('reservation/update.html', 
        {
            'reservation_form' : reservation_form, 
            'reservation':reservation, 
            'contact_form':contact_form,
            'pickup_address_form':pickup_address_form,
            'dropoff_address_form':dropoff_address_form
        },
        context_instance=RequestContext(request))
예제 #6
0
def home(request):
    about_item = AboutItem.objects.last()
    categories = Category.objects.all()
    dishes = Dish.objects.all()
    speciality_dishes = Dish.objects.filter(speciality=True)[:4]
    testimonials = Testimonial.objects.all()[:6]
    articles = Article.objects.all()

    if request.method == 'POST':
        form = ReservationForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            phone = form.cleaned_data['phone']
            email = form.cleaned_data['email']
            date = form.cleaned_data['date']
            time = form.cleaned_data['time']
            persons = form.cleaned_data['persons']
            try:
                Reservation.objects.create(name=name, phone=phone, email=email, date=date, time=time, persons=persons)
            except ValueError as e:
                return HttpResponse(e)
            # return redirect('contact:send_success')
    else:
        form = ReservationForm()

    template = 'home/index.html'
    context = {
        'about_item': about_item,
        'categories': categories,
        'dishes': dishes,
        'speciality_dishes': speciality_dishes,
        'testimonials': testimonials,
        'articles': articles,
        'form': form

    }
    return render(request, template, context)
예제 #7
0
def add_reservation_view(request, vehicle_id):
    if request.user.is_authenticated:
        admin = User.objects.get(username='******')
        vehicle = Vehicle.objects.get(id=vehicle_id)
        chat = Messages.objects.filter(vehicle=vehicle,
                                       sender__in=[request.user, admin],
                                       receiver__in=[request.user, admin])
        context = {
            'html_title': f'RESERVE {vehicle.brand.name.upper()}',
            'vehicle': vehicle,
            'chat': chat,
            'message_form': MessagesForm(),
            'section': 'account',
            'sub_section': 'reserve',
        }
        if request.method == 'POST':
            reservation_form = ReservationForm(request.POST)
            if reservation_form.is_valid():
                new_reservation = reservation_form.save(commit=False)
                new_reservation.user = request.user
                new_reservation.vehicle = vehicle
                vehicle.quantity -= 1
                if vehicle.quantity == 0:
                    vehicle.availability = False
                vehicle.save()
                new_reservation.save()
                context['is_reserved'] = True
                context['reservation'] = new_reservation
            else:
                messages.error(request, 'Error! Invaild input.')
            return render(request, 'account/account_base.html', context)
        else:
            context['reservation_form'] = ReservationForm()
            return render(request, 'account/account_base.html', context)
    else:
        messages.error(request, 'Please login')
        return redirect('index')
예제 #8
0
def edit_reservation(request, reservation_id):
    reservation = get_object_or_404(Reservation, pk=reservation_id)
    if request.method == "POST":
        reservation_form = ReservationForm(request.POST, instance=reservation)
        contact_form = ContactForm(request.POST, instance=reservation.customer)
        pickup_address_form = AddressForm(request.POST, instance=reservation.pickup_address, prefix="pickup")
        dropoff_address_form = AddressForm(request.POST, instance=reservation.dropoff_address, prefix="dropoff")
        
        if reservation_form.is_valid() and contact_form.is_valid() and pickup_address_form.is_valid() and dropoff_address_form.is_valid():
            # Figure out what this does, if anything!
            if request.is_ajax():
                retValue = serialize('json', [reservation])
                return HttpResponse(simplejson.dumps({'test':retValue}), mimetype='application/javascript')
            else:
                contact = contact_form.save()
                pickup_address = pickup_address_form.save()
                dropoff_address = dropoff_address_form.save()
                reservation = reservation_form.save(commit=False)
                reservation.customer = contact
                reservation.pickup_address = pickup_address
                reservation.dropoff_address = dropoff_address
                reservation.company = Client.objects.get(pk=1)
                reservation.save()
                reservation_form.save_m2m()
                return HttpResponseRedirect('/reservation/')
    else:
        reservation_form = ReservationForm(instance=reservation)
        contact_form = ContactForm(instance=reservation.customer)
        pickup_address_form = AddressForm(instance=reservation.pickup_address, prefix="pickup")
        dropoff_address_form = AddressForm(instance=reservation.dropoff_address, prefix="dropoff")
    return render_to_response('reservation/update.html', 
        {
            'reservation_form' : reservation_form, 
            'reservation':reservation, 
            'contact_form':contact_form,
            'pickup_address_form':pickup_address_form,
            'dropoff_address_form':dropoff_address_form
        },
        context_instance=RequestContext(request))
예제 #9
0
def continue_reservation(request, reservation_seat_ids, session_id):
    session = Session.objects.get(pk=session_id)
    seat_ids = reservation_seat_ids.split(',')
    seats = []
    price = 0
    for id in seat_ids:

        seat = get_object_or_None(Seat, pk=id)
        r = get_object_or_None(ReservationSeat, session=session, seat=seat)
        if not r:
            seats.append(seat)
            price += SessionSeatTypePrice.objects.get(seat_type=seat.type,
                                                      session=session).price

    if seats:
        film_name = session.film_cinema.film.name
        date_time_start = session.datetime_start
        date_time_end = session.datetime_end
    else:
        return redirect(request.META['HTTP_REFERER'])
    if request.method == 'POST':
        form = ReservationForm(request.POST)

        if form.is_valid():
            tickets = []
            name = form.cleaned_data['name']
            surname = form.cleaned_data['surname']
            email = form.cleaned_data['email']
            for seat in seats:
                r = ReservationSeat(session=session, seat=seat)
                r.save()
                t = Ticket.objects.create(reservation_seat=r)
                t.save()
                tickets.append(t)
            reservation = Reservation(name=name, surname=surname, email=email)
            reservation.save()
            for ticket in tickets:
                reservation.tickets.add(ticket)
            reservation.save()
            send_mail(
                "Регестрация билета",
                f'Здравствуйте {name} {surname}.'
                f'Вы заказали билеты в количестве {len(tickets)}. Номер заказа - {reservation.id}'
                f' на фильм {film_name} который пройдет'
                f' {datetime.datetime.strftime(date_time_start,"%m.%d %a %H:%M")} - {datetime.datetime.strftime(date_time_end,"%H:%M")}.'
                f'Вы можете оплатить билеты на кассе. '
                f'Помните, пока вы только забронировали билеты, их нужно выкупить',
                'СinemaHouse+',
                [email],
            )
            return redirect(reverse('main'))
    form = ReservationForm()
    return render(
        request, 'reservation/reservation.html', {
            'seats': seats,
            'name': film_name,
            'datetime': date_time_start,
            'price': price,
            'form': form,
            'hall': session.hall.name,
            'seat_ids': reservation_seat_ids,
            'session_id': session_id
        })
def home(request):
    listado = list(Cita.objects.all())
    citas = listado

    listado = list(Sugerencia.objects.all())
    sugerencias = []
    for elem in listado:
        if elem.activo:
            sugerencias.append(elem)

    listado = list(Categoria.objects.all())

    categorias_menu = []
    for elem in listado:
        if elem.activo:
            categorias_menu.append(elem)

    categorias_cuatro = []
    shuffle(listado)
    for elem in listado:
        if (elem.activo or elem.tituloES == 'Del Mar'
                or elem.tituloES == 'Pollo' or elem.tituloES
                == 'Carnes') and elem.tituloES != 'Platos Principales':
            categorias_cuatro.append(elem)
            if len(categorias_cuatro) == 4:
                break

    listado = list(Plato.objects.all())
    platos = []
    for categoria in categorias_menu:
        cont = 0
        for elem in listado:
            if elem.categoria.tituloES == categoria.tituloES:
                platos.append(elem)
                cont += 1
                if cont >= 3:
                    break

    eventos = Evento.objects.all()

    form = ReservationForm()

    if request.method == 'POST':
        form = ReservationForm(data=request.POST)
        if form.is_valid():
            datos = form.cleaned_data
            nombre = datos.get('nombre')
            email = datos.get('email')
            fecha_y_hora = datos.get('fecha_y_hora')
            mensaje = datos.get('mensaje')
            try:
                send_mail(
                    "Reservación para las {}".format(fecha_y_hora),
                    "De {} <{}>\n\nEscribió:\n\n{}".format(
                        nombre, email, mensaje),
                    settings.EMAIL_HOST_USER,
                    ['*****@*****.**'],
                    fail_silently=False,
                )
                return redirect(reverse('home') + '?ok')
            except:
                return redirect(reverse('home') + '?fail')

    return render(
        request, "core/index.html", {
            'citas': citas,
            'sugerencias': sugerencias,
            'categorias': categorias_menu,
            'categorias_cuatro': categorias_cuatro,
            'platos': platos,
            'eventos': eventos,
            'form': form,
            'language': 'ES'
        })