예제 #1
0
def operatorFilterBooked(request, operatorId):

    context = {}
    try:
        operator = Operator.objects.get(operator_id=operatorId)
        tickets = Ticket.objects.filter(operator_id=operator.operator_id)
        bookings = []
        try:
            for ticket in tickets:
                bus = Bus.objects.get(busId=ticket.busId)
                customer = Customer.objects.get(customer_id=ticket.passengerId)
                b = Bookings(ticket, customer, bus, operator)
                if b.isCompleted == False and b.isTicketCancelled == False:
                    bookings.append(b)
        except Exception as e:
            print(e)

        context['name'] = operator.name
        context['tickets'] = tickets
        context['bookings'] = bookings
        context['operator'] = operator

        context['test'] = 'test'

        if len(bookings) == 0:
            context['hasNoBookings'] = True
        else:
            context['hasNoBookings'] = False
    except Exception as e:
        print(e)
        messages.warning(request, "Please log in to your accouont ! ")
    return render(request, 'operatorBookings.html', context)
예제 #2
0
def filterCancelled(request, customerId):
    context = {}
    try:
        customer = Customer.objects.get(customer_id=customerId)
        tickets = Ticket.objects.filter(passengerId=customer.customer_id)
        bookings = []

        for ticket in tickets:
            bus = Bus.objects.get(busId=ticket.busId)
            operator = Operator.objects.get(operator_id=bus.operator_id)
            booking = Bookings(ticket, customer, bus, operator)
            if booking.isTicketCancelled:
                bookings.append(booking)

        context['name'] = customer.name
        context['tickets'] = tickets
        context['bookings'] = bookings
        context['customerId'] = customer.customer_id
        if len(bookings) == 0:
            context['hasNoBookings'] = True
        else:
            context['hasNoBookings'] = False
    except Exception as e:
        print(e)
        messages.warning(request, "Please log in to your accouont ! ")
    return render(request, 'myBookings.html', context)
예제 #3
0
def operatorAccount(request, operatorId):

    try:

        operator = Operator.objects.get(operator_id=operatorId)
        tickets = Ticket.objects.filter(operator_id=operator.operator_id)
        context = {}
        context['name'] = operator.name
        context['operatorId'] = operator.operator_id
        context['operator'] = operator
        resultTickets = []
        # edit email

        editEmail = request.POST.get('editEmail')
        if editEmail and editEmail != operator.email:
            operator.email = editEmail
            try:
                operator.save()
                messages.success(request, "Saved Changes ! ")

                return redirect('/operator/dashboard/account/' +
                                str(operator.operator_id))

            except Exception as e:
                print(e)
                messages.warning(
                    request,
                    'Something failed while saving changes ! please try again later '
                )

        # edit email ends here
        try:
            for ticket in tickets:
                # print(ticket)
                bus = Bus.objects.get(busId=ticket.busId)
                customer = Customer.objects.get(customer_id=ticket.passengerId)
                # print(ticket, bus, operator)
                resultTickets.append(Bookings(ticket, customer, bus, operator))

        except Exception as e:
            print(e)
        account = OperatorAccount(operator, resultTickets)
        context['account'] = account
        if len(account.upcommingBookings) > 0:
            context['hasUpcomming'] = True
        else:
            context['hasUpcomming'] = False

        return render(request, 'operatorAccount.html', context)

    except Exception as e:
        print(e)
        return redirect('/operator/dashboard')
        messages.warning(request, 'something failed ! please try later ')
예제 #4
0
def cancelTicketOperator(request, customerId, ticketId):
    context = {}

    try:

        customer = Customer.objects.get(customer_id=customerId)
        ticket = Ticket.objects.get(ticketId=ticketId)
        operator = Operator.objects.get(operator_id=ticket.operator_id)
        bus = Bus.objects.get(busId=ticket.busId)
        context['booking'] = Bookings(ticket, customer, bus, operator)
        seats = Seats.objects.get(busId=ticket.busId,
                                  date=ticket.dateOfJourney)
        context['name'] = customer.name
        if request.method == 'POST':
            try:
                operator.amountInWallet = operator.amountInWallet - ticket.totalFare
                operator.cancelledAmount = operator.cancelledAmount + ticket.totalFare
                customer.wallet = customer.wallet + ticket.totalFare

                oldSeats = seats.seatsBooked
                seatUpdate = []
                for seat in seats.seatsBooked:
                    if ticket.bookedSeats.count(seat) == 0:
                        seatUpdate.append(seat)
                seats.seatsBooked = seatUpdate
                ticket.isCancelled = True

                ticket.save()
                operator.save()

                seats.save()
                customer.save()
                messages.success(request, 'Ticket cancelled sucessfully ! ')
                return redirect('/operator/dashboard/bookings/' +
                                str(operator.operator_id) + '/cancelled')
            except Exception as e:
                print(e)
                messages.warning(request,
                                 'Something failed ! please try later ')

        return render(request, 'cancelTicket.html', context)

    except Exception as e:
        print(e)
        messages.warning(request, 'Something failed ! please try later ')
        return redirect('/operator/dashboard/bookings/' +
                        str(operator.operator_id))