0

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 departure, destination, etc and there's Search button as well.

def home():
    return index.html 

The 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?

  • Why would RequestedRoute know anything about the number of travelers in the party? That information seems unneeded for calculating the available routes. – Bart van Ingen Schenau Oct 5 '18 at 11:46
  • @BartvanIngenSchenau some routes on the database have no more seats available for instance. Therefore, RequestedRoute.get_available_routes() has to send the number of travellers to the SQL query. – multigoodverse Oct 5 '18 at 12:00
1

There is no reason for the select function to know that the search function has used the number of travelers to filter the set of available routes.

If the RequestedRoute class did not use the party size, this information would have to be passed to the select function by the front-end HTML form.
When the select function doesn't know if the RequestedRoute class has information on the (exact) party size, then that information should also be provided by the front-end HTML form.

So, my recommendation would be that the "available_routes.html" page contains a (hidden) field with the party size, so that the select function can pick the information from there.

  • Yes, Javascript seems to be the answer here. – multigoodverse Dec 11 '18 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.