Question: Python help We're going to write a Bottle program that has users log onto a web site and have the user enter data into the
Python help
We're going to write a Bottle program that has users log onto a web site and have the user enter data into the database or have the user examine data from the database, depending on their role.
One role is that of technician. Techs travel to perfrom maintenance in various cities, and are eventually reimbursed for their expenses. But the techs are required to enter their travel data into a database using a browser. The techs don't see the whole table, they just log in, then enter their trip data in a HTML form and submit it. If successful the tech then sees a confirmation message that the update went OK.
The other role is that of administrator. An admin needs to be able to view the whole trips table in order to analyse the total cost of all this traveling at some point.
So here is the structure and some data for the two database tables. A link to this database is given later in these instructions. First up is the members table. emp_id is an integer primary key, the names and the role of each user are given (tech or admin) as text, and to log in we have username with a password, also text, that is stored after being hashed by sha1. This is the complete data for the members table.

You do not need to add anyone to this members table.
To test your program you'll need the plain text versions of the password hashes for the three techs and the admin. {username: jsmith, password: 12345}, {username: sjones , password: password}, {username: dwilson, pasasword: superman}, and {username: admin, password: default}. Here are the password hashes.

The trips table looks like the following with fields for trip_id (auto-incrementing primary key), emp_id of the employee who made the trip, date, destination, miles, gallons. The date and destination are text, everything else is a number. This is not all the records; there are 29 trip records total from 3 different technicians as indicated by the emp_id value in the table.

This is the table a tech will add a record to. Here's how it should work. First a user points the browser to the default route where they are shown a login form.

Upon submitting the login form your program verifies the username and password and also reads the value of the role field of the members table. The login route should compare the member's password, hashed with sha1, to the password in the db table. Also, the code in the callback for the login route needs to make a decision about what should happen depending on the person's role. Something like the following.
data = {'title': 'Welcome'} if role == 'admin': return template('admin', data) # admin template elif role == 'tech': return template('enter_trip_data', data) # tech template else: return "login failed"
If the role of the user is tech then the user should be shown a template that displays a HTML form that would allow them to enter trip data and submit it to be added to the trips table.

You would read the value of each text box into a variable using the methods we've discussed in the lecture notes. So in the HTML form if the first textbox was named emp_id, then our code can read its value like this
emp_id = request.forms.get('emp_id')
The other textboxes would be read similarly.
This form should be submitted to a route that has code to read the values from the textboxes, package that up as a tuple, then SQL INSERT the new trip record into the trips table of the database. After submitting the data we send a confirmation message and the technician's job is done. The tech should not see the whole database table.
However, if the person who logged in had a role of admin, then they should be shown a template that has administrative options shown in a list. In this case, though, only the first option is an active link. If the admin then clicks the hyperlink then that link makes a GET request to a different route that will read the database and display the trips in a html table. Here's an example template with the link as displayed to the admin. Only the first of the three options shown in the list below is active for this assignment.

When that link is clicked we are directed to a template that displays the whole trips table with date, destination, miles, gallons, and the last name of the technician who made the trip. This requires a join of the two tables.

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
