I am experimenting with an web app for searching and buying bus tickets. I came up with a few objects like RequestedRoute, Passenger, and Ticket:
I have some Flask view functions as well. The
home function is called when the user visits the home page. The home page has a form where the user can enter the
destination, etc and there's Search button as well.
def home(): return index.html
search function is called when the user presses the
Search button. A
RequestedRoute object will be created, and a
RequestedRoute.get_available_routes() method will be triggered and the available routes will be listed on the webpage and there will be a
Select button next to each route.
def search(): requested_route = RequestedRoute("fetch data from the HTML form") return "available_routes.html"
The select function will be triggered when the user selects a route and a payment_details.html page containing a form with name, surname, and card credit details will be rendered.
def select(): return "payment_details.html"
My question is this: In the
select function I need to know the number of travelers so that I can let the payment_details.html template know how many user forms to create where the user can enter the name, surname for each passenger. Should I instantiate a RequestedRoute object again? That feels reduntant as I did that once in the
search function when the user searched for available routes. How can I access the
RequestedRoute data again in the select function?