diff --git a/cust/templates/cust/data_view.html b/cust/templates/cust/data_view.html index eeaa429260c12efb6bab9f393a47eb7bc4f5b2b2..406385883d2dbe53a2e94ae633289bffe0b5f5f7 100644 --- a/cust/templates/cust/data_view.html +++ b/cust/templates/cust/data_view.html @@ -24,13 +24,14 @@ <table class=""> <thead> <tr> - <th scope="col">Images</th> - <th scope="col">Date</th> - <th scope="col">Time</th> - <th scope="col">Film Title</th> - <th scope="col">Trailer Description</th> - <th scope="col">Age Rating</th> - <th scope="col">Duration</th> + <th scope="col" class="w3-blue">Images</th> + <th scope="col" class="w3-blue">Date</th> + <th scope="col" class="w3-blue">Time</th> + <th scope="col" class="w3-blue">Film Title</th> + <th scope="col" class="w3-blue">Trailer Description</th> + <th scope="col" class="w3-blue">Age Rating</th> + <th scope="col" class="w3-blue">Duration</th> + <th scope="col" class="w3-blue"></th> </tr> </thead> <tbody> @@ -46,30 +47,17 @@ <td>{{ i.trailerDescription }}</td> <td>{{ i.ageRating }}</td> <td>{{ i.filmDuration }}</td> + <td> + {% load custom_filters %} + <a class="w3-button w3-green button4" style="margin-right: 10px;" href="{% url 'cust:ticket' i|get_id %}">Select Showing</a> + <br> + </td> </tr> {% endfor %} </tbody> </table> - <p><center> Select a Movie</center></p> - <table class=""> - {% comment %} <form action="{% url 'test' %}" method="get"> - <label>Select:</label> - <input type="stringformat" name="data" id="data"> - <br> - <button type="submit">View Data</button> - </form> {% endcomment %} - <form action="{% url 'cust:ticket' %}" method="get"><center> - <select name="data" id="data"> - {% for movie in movies %} - <option value="{{ movie.filmTitle }}">{{ movie.filmTitle }}</option> - {% endfor %} - </select> - <p> </p> - <input class="w3-button w3-green button4" style="margin-right: 10px;" type="submit" value="Submit"> - </center></form> - </table> <br> {% elif not data %} <h1 class="w3-margin"><center>There are no showings on the {{selected_date}}</center></h1> diff --git a/cust/templates/cust/ticket.html b/cust/templates/cust/ticket.html index 3ed59763a0cdda81768f8de523db515432cdc5ef..5a2c27e0bbff47e92f042b3dd88e004f35642878 100644 --- a/cust/templates/cust/ticket.html +++ b/cust/templates/cust/ticket.html @@ -22,37 +22,33 @@ <br> <div class="w3-container w3-card w3-round"> - <p>Selected Movie: {{ selected_data }} </p> + <p>Selected Movie: </p> <table class=""> <thead> <tr> - <th scope="col">Images</th> - <th scope="col">Date</th> - <th scope="col">Time</th> - <th scope="col">Film Title</th> - <th scope="col">Trailer Description</th> - <th scope="col">Age Rating</th> - <th scope="col">Duration</th> + <th scope="col" class="w3-blue">Images</th> + <th scope="col" class="w3-blue">Film Name</th> + <th scope="col" class="w3-blue">Age Rating</th> + <th scope="col" class="w3-blue">Duration</th> + <th scope="col" class="w3-blue">Trailer Description</th> </tr> </thead> <tbody> - {% for i in results %} - + {% for i in cursor %} <tr> - <td scope="row"> + <th scope="row"> <img style="height: 100px; width: auto;" src="{{ todos.name }}" class="card-img-top" alt="..."> - </td> - <td>{{ i.date }}</td> - <td>{{ i.showingTime }}</td> - <td>{{ i.filmTitle }}</td> - <td>{{ i.trailerDescription }}</td> - <td>{{ i.ageRating }}</td> - <td>{{ i.filmDuration }}</td> + </th> + <th scope="row">{{ i.Name }}</th> + <td>{{ i.Rating }}</td> + <td>{{ i.Duration }}</td> + <td>{{ i.TrailerDescription }}</td> + + </tr> {% endfor %} - </tbody> </table> <br> @@ -62,7 +58,7 @@ <input type="number" name="tickets" id="tickets" min="1" max="10" value="1"> <br> <p> </p> - <button type="submit" class="w3-button w3-green button4" style="margin-right: 10px;" href="{% url 'cust:payment'%}"> Proceed to Booking</button> + <button type="submit" class="w3-button w3-green button4" style="margin-right: 10px;" href="{% url 'cust:payment'%}"> Proceed to Payment</button> </center></form> {% comment %} </table> <table class=""> diff --git a/cust/urls.py b/cust/urls.py index 7c4d3a18f3d0f9bca86ffb45ef998349d50b8198..61491ee00188734d8fa26df55e08b38b645d5f4b 100644 --- a/cust/urls.py +++ b/cust/urls.py @@ -7,7 +7,7 @@ urlpatterns = [ path('select_date/', views.select_date, name='selectdate'), path('view_data/', views.view_data, name='view_data'), - path('view_data/ticket/', views.ticket, name='ticket'), + path('view_data/ticket/<str:pk>/', views.ticket, name='ticket'), path('view_data/ticket/book_tickets/', views.book_tickets, name='book_tickets'), path('view_data/ticket/book_tickets/payment/', views.payment, name='payment'), path('view_data/ticket/book_tickets/booking_confirmation/', views.confirmation, name='confirmation'), diff --git a/cust/views.py b/cust/views.py index 12c77d67dae6c9d2dce89ea50c79bd85aaabb2b7..0ee12f9c1e117d7b54d2db10293e5c2aa9054548 100644 --- a/cust/views.py +++ b/cust/views.py @@ -83,16 +83,50 @@ def view_data(request): context = {'results': results, 'selected_date': selected_date, 'movies': movies, 'data': data} return render(request, 'cust/data_view.html', context) +def ticket(request, pk, message=None): + + Showings_id = ObjectId(pk) + + results = Showings.find_one({ "_id" : Showings_id }) + #selected_data = request.GET.get('data') + film_name = results["filmTitle"] + showing_date = results["date"] + + regex = re.compile(film_name, re.IGNORECASE) + query = {'Name': {'$regex': regex}} + + cursor = Films.find(query) + + if request.POST.get('tickets'): + numb_of_tickets = int(request.POST.get('tickets')) + + tickets_available = results["ticketsLeft"] + + + if numb_of_tickets > tickets_available: + print("not ennough tickets") + message = (f"There are not enough tickets available. \n Tickets Available: {tickets_available} ") + return redirect('view-film-error-st',pk=pk , message=message) + + + context = { + 'cursor': cursor, + 'film_id': pk, + 'date': showing_date, + 'message': message, + 'results': results, + } + return render(request, 'cust/ticket.html', context) def confirmation(request): number = random.randint(1, 10000000) return render(request, 'cust/confirmation.html', {'number': number}) -def ticket(request): - selected_data = request.GET.get('data') - results = Showings.find({'filmTitle': selected_data}) - context = {'results': results, 'selected_data': selected_data} - return render(request, 'cust/ticket.html', context) +# def ticket(request): +# selected_data = request.GET.get('data') +# results = Showings.find({'filmTitle': selected_data}) +# context = {'results': results, 'selected_data': selected_data} +# return render(request, 'cust/ticket.html', context) def book_tickets(request): selected_ticketsnum = request.GET.get('tickets')