Welcome to the final part of pset 7 from CS50. In this week’s post we will implement the History feature of Finance. This will be a fairly short post, as we are just displaying the whole history of a user’s account. Luckily, we already have all the data we need. So, it is really a matter of gathering the data that we need and displaying it to our user. As all of my other tutorials have started, we will begin with looking at the html that we need.

The following html file should look very similar to the ones we have implemented in earlier weeks. Here we are creating a table to show all of the transactions that our user has made. You will see some new html tags that we have not used up to this point. However, they should be rather self explanatory. For more information on the <table> tag and associated tags W3Schools is an excellent resource. Basically, the <thead> tag allows us to create the columns on top of our table, and the <tbody> tag will house the rows that will show all of the transaction data. The Jinja for loop will execute on the data that we pass when we render the html. Therefore, each row will have a <td>, or cell, that contains the symbol, shares, total price, and a timestamp for each transaction.

The following Python code snippet is rather short and straight forward. Here, we want to get all the transaction data associated with the current user. We can get all this information from the the transactions table that we created earlier. Notice, that unlike other functions that we have written, we are not explicitly stating that the user must arrive via the post method. This is because the user does not need to fill out a form in our html, because they are not making a transaction. The user is merely looking at the transactions that they have already made. The render_template method then renders our history.html file and pass in the table from our SQL query. The Jinja statements will then execute on this data.

If you have reached this point, you have now successfully completed all the necessary requirements for the Finance problem set. I encourage you to look at the personal touch section and try to implement some of these features on your own. By now, you have all the skills necessary for these items. Implementing these personal touch items will test those skills and give you a good feel for where you are at in the process. Feel free to comment below with questions on these person touch items if you run into road blocks. Remember to share this post on your favorite social media platform. As always…Happy Programming!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s