def report_perf(request, performance): this_perf = models.get_performance(performance) seats_list = models.get_seats(this_perf) paginator = Paginator(seats_list, 100) page = request.GET.get('page') try: seats = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. seats = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. seats = paginator.page(paginator.num_pages) html = render(request, 'report_perf.html', {'performance': this_perf, 'seats': seats}) return StreamingHttpResponse(html)
def buy_perf(request, performance): this_perf = models.get_performance(performance) error = None if request.method == 'POST': data = request.POST available_prices = models.get_prices(this_perf) # make a new transaction transaction = models.create_transaction(request.user) redirect_to_cart = False # go through the available prices and see what the user has requested for price in available_prices: buyer = str(price.buyer_type) if buyer in data: # for each of these buyer_types lock a seat and add it to the cart if int(data[buyer]) < 10: for i in range(int(data[buyer])): seat = this_perf.lock_seat(transaction, price.buyer_type, price.price) if seat: cart = Cart(request) cart.add(seat, price.price, 1) redirect_to_cart = True else: error = "Invalid number of seats selected" # only redirect to the cart if we have added some seats if redirect_to_cart: return redirect('cart') html = render(request, 'buy_perf.html', {'performance': this_perf, 'seat_count': models.get_seat_count(performance), 'prices': models.get_prices(this_perf), 'error': error}) return StreamingHttpResponse(html)