Exemplo n.º 1
0
def create_book(request):
    book = Book()
    checkout_form = CheckoutForm(request.POST , instance = book )
    book = checkout_form.save(commit = False)
    book.user = None
    if request.user.is_authenticated():
        book.user = request.user
    book.status = Book.SUBMITTED
    book.save()

    # if the book save succeeded
    if book.pk:
        book_dests = b.get_book_dests(request)
        for bd in book_dests:
            # create book destination for each booking items
            oi = BookDest()
            oi.book = book
            oi.price = bd.price()
            oi.nopeople = bd.nopeople
            oi.destination = bd.destination
            oi.save()
        # all set , empty booking
        b.empty_book(request)
        # save profile info for future bookings
        if request.user.is_authenticated():
            from savannahtrekkers.accounts import profile
            profile.set(request)
    # return the new booking object
    return book
Exemplo n.º 2
0
def show_checkout(request, template_name ='checkout/checkout.html'):
    if book.is_empty(request):
        book_url = urlresolvers.reverse('show_booking')
        return HttpResponseRedirect(book_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            book_number = response.get('book_number',0)
            error_message = response.get('message','')
            if book_number:
                request.session['book_number'] = book_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()


    page_title = 'Checkout'
    return render_to_response(template_name , locals(),context_instance = RequestContext(request))