Esempio n. 1
0
def abort_booking_view(request, *args, **kwargs):
    try:
        change = bool(request.GET.get('change', False))
        change_ratis = request.GET.get('change_ratis', None)
        change_id = request.GET.get('change_id', None)
        change_to = None
        booking = utils.get_session_booking(request.session)
        if change_ratis:
            try:
                c_id = Campground.objects.get(ratis_id=change_ratis).id
            except:
                c_id = booking.campground.id
        elif change_id:
            try:
                c_id = Campground.objects.get(id=change_id).id
            except:
                c_id = booking.campground.id
        else:
            c_id = booking.campground.id
        # only ever delete a booking object if it's marked as temporary
        if booking.booking_type == 3:
            booking.delete()
        utils.delete_session_booking(request.session)
        if change:
            # Redirect to the availability screen
            return redirect(
                reverse('campsite_availaiblity_selector') +
                '?site_id={}'.format(c_id))
        else:
            # Redirect to explore parks
            return redirect(settings.EXPLORE_PARKS_URL + '/park-stay')
    except Exception as e:
        pass
    return redirect('public_make_booking')
Esempio n. 2
0
def abort_booking_view(request, *args, **kwargs):
    try:
        change = bool(request.GET.get('change',False))
        change_ratis = request.GET.get('change_ratis',None)
        change_id = request.GET.get('change_id',None)
        change_to = None
        booking = utils.get_session_booking(request.session)
        if change_ratis:
            try:
                c_id = Campground.objects.get(ratis_id=change_ratis).id
            except:
                c_id = booking.campground.id
        elif change_id:
            try:
                c_id = Campground.objects.get(id=change_id).id
            except:
                c_id = booking.campground.id
        else:
            c_id = booking.campground.id
        # only ever delete a booking object if it's marked as temporary
        if booking.booking_type == 3:
            booking.delete()
        utils.delete_session_booking(request.session)
        if change:
            # Redirect to the availability screen
            return redirect(reverse('campsite_availaiblity_selector') + '?site_id={}'.format(c_id)) 
        else:
            # Redirect to explore parks
            return redirect(settings.EXPLORE_PARKS_URL+'/park-stay')
    except Exception as e:
        pass
    return redirect('public_make_booking')
Esempio n. 3
0
    def get(self, request, *args, **kwargs):
        try:
            print("BookingSuccessView - get 1.0.1",
                  datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
            basket = None

            booking = utils.get_session_booking(request.session)
            if self.request.user.is_authenticated():
                basket = Basket.objects.filter(
                    status='Submitted', owner=request.user).order_by('-id')[:1]
            else:
                basket = Basket.objects.filter(
                    status='Submitted',
                    owner=booking.customer).order_by('-id')[:1]

            #booking = utils.get_session_booking(request.session)
            #invoice_ref = request.GET.get('invoice')
            try:
                print("BookingSuccessView - get 3.0.1",
                      datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
                utils.bind_booking(booking, basket)
                print("BookingSuccessView - get 4.0.1",
                      datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
                utils.delete_session_booking(request.session)
                print("BookingSuccessView - get 5.0.1",
                      datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
                request.session['ps_last_booking'] = booking.id

            except BindBookingException:
                return redirect('public_make_booking')

        except Exception as e:
            if ('ps_last_booking'
                    in request.session) and Booking.objects.filter(
                        id=request.session['ps_last_booking']).exists():
                booking = Booking.objects.get(
                    id=request.session['ps_last_booking'])
            else:
                return redirect('home')

        context = {'booking': booking}
        print("BookingSuccessView - get 6.0.1",
              datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
        response = render(request, self.template_name, context)
        response.delete_cookie(settings.OSCAR_BASKET_COOKIE_OPEN)
        return response
Esempio n. 4
0
    def get(self, request, *args, **kwargs):
        try:
            booking = utils.get_session_booking(request.session)
            invoice_ref = request.GET.get('invoice')

            if booking.booking_type == 3:
                try:
                    inv = Invoice.objects.get(reference=invoice_ref)
                except Invoice.DoesNotExist:
                    logger.error(
                        '{} tried making a booking with an incorrect invoice'.
                        format('User {} with id {}'.format(
                            booking.customer.get_full_name(), booking.customer.
                            id) if booking.customer else 'An anonymous user'))
                    return redirect('public_make_booking')

                if inv.system not in ['0019']:
                    logger.error(
                        '{} tried making a booking with an invoice from another system with reference number {}'
                        .format(
                            'User {} with id {}'.format(
                                booking.customer.get_full_name(),
                                booking.customer.id) if booking.customer else
                            'An anonymous user', inv.reference))
                    return redirect('public_make_booking')

                try:
                    b = BookingInvoice.objects.get(
                        invoice_reference=invoice_ref)
                    logger.error(
                        '{} tried making a booking with an already used invoice with reference number {}'
                        .format(
                            'User {} with id {}'.format(
                                booking.customer.get_full_name(),
                                booking.customer.id) if booking.customer else
                            'An anonymous user', inv.reference))
                    return redirect('public_make_booking')
                except BookingInvoice.DoesNotExist:
                    logger.info(
                        '{} finished temporary booking {}, creating new BookingInvoice with reference {}'
                        .format(
                            'User {} with id {}'.format(
                                booking.customer.get_full_name(),
                                booking.customer.id) if booking.customer else
                            'An anonymous user', booking.id, invoice_ref))
                    # FIXME: replace with server side notify_url callback
                    book_inv, created = BookingInvoice.objects.get_or_create(
                        booking=booking, invoice_reference=invoice_ref)

                    # set booking to be permanent fixture
                    booking.booking_type = 1  # internet booking
                    booking.expiry_time = None
                    booking.save()

                    utils.delete_session_booking(request.session)
                    request.session['ps_last_booking'] = booking.id

                    # send out the invoice before the confirmation is sent
                    emails.send_booking_invoice(booking)
                    # for fully paid bookings, fire off confirmation email
                    if booking.paid:
                        emails.send_booking_confirmation(booking, request)

        except Exception as e:
            if 'ps_booking_internal' in request.COOKIES:
                return redirect('home')
            elif ('ps_last_booking'
                  in request.session) and Booking.objects.filter(
                      id=request.session['ps_last_booking']).exists():
                booking = Booking.objects.get(
                    id=request.session['ps_last_booking'])
            else:
                return redirect('home')

        context = {'booking': booking}
        return render(request, self.template_name, context)