def payment_success(request): try: if request.user.is_superuser: raise Customer.DoesNotExist() customer = request.user.userinfo.customer orders = Order.objects.filter(customer=customer).all() order = orders[len(orders) - 1] random = 132*1000 return_code = random + order.id return render(request, 'successful_payment.html', {'order': order, 'return_code': return_code}) except Customer.DoesNotExist: return_url = reverse('users:home') return render(request, 'info_template.html', {'message':"متاسفانه خظایی در سامانه رخ داده است.", 'return_url': return_url})
def print_ticket(request, **kwargs): order_id = int(kwargs.pop('return_code')) % 1000 try: if request.user.is_superuser: raise Customer.DoesNotExist() customer = request.user.userinfo.customer try: order = Order.objects.filter(customer=customer).get(id=order_id) tickets = Ticket.objects.filter(order=order).all() return render(request, 'printable_ticket.html', {'tickets': tickets}) except Exception: return_url = reverse('users:home') return render(request, 'info_template.html', {'message':"شمارهی پیگیری را اشتباه وارد کردهاید.", 'return_url': return_url}) except Customer.DoesNotExist: return_url = reverse('users:home') return render(request, 'info_template.html', {'message':"متاسفانه خظایی در سامانه رخ داده است.", 'return_url': return_url})
def cancel_payment(request): try: if request.user.is_superuser: raise Customer.DoesNotExist() customer = request.user.userinfo.customer orders = Order.objects.filter(customer=customer).all() order = orders[len(orders) - 1] event = order.event tickets = Ticket.objects.filter(order=order).all() for ticket in tickets: ticket.type.cancel() ticket.delete() order.delete() return redirect(reverse('users:home')) except Customer.DoesNotExist: return_url = reverse('users:home') return render(request, 'info_template.html', {'message':"متاسفانه خظایی در سامانه رخ داده است.", 'return_url': return_url})
def payment(request): try: if request.user.is_superuser: raise Customer.DoesNotExist() customer = request.user.userinfo.customer if request.method == "POST": event_id = request.POST.get("event_id") event = Event.objects.get(id=event_id) ticket_types = TicketType.objects.filter(event=event) total = 0 order = Order() order.event = event order.customer = customer order.save() for type in ticket_types: bought = request.POST.get("type_"+str(type.id)) if len(bought) > 0: col = randint(1,80) row = randint(1,80) total = total + int(bought) * int(type.price) bought = int(bought) type.buy(bought) for i in range(0, bought): ticket = Ticket() ticket.event = event ticket.type = type ticket.order = order ticket.row = row ticket.column = col col += 1 ticket.save() if total > 0: return render(request, 'payment.html', {'price': total}) else: return redirect(reverse('users:home')) except Customer.DoesNotExist: return_url = reverse('users:home') return render(request, 'info_template.html', {'message':"متاسفانه سطح کاربری شما اجازهی خرید ندارد.", 'return_url': return_url})