Weeks 08_09 Lab, 2018 S2
Due: Sunday, 11:59 pm, Week 09
Aim
Develop skills to build a Flask front-end and authentication using Flask Login
Lab instructions
In this lab, you will be implementing part of a FLASK front-end for the car rental system that you
had worked on in week 7. A substantial amount of starter code has been provided for this lab.
You should import this from the Github application used throughout the course
(https://cgi.cse.unsw.edu.au/~cs1531/github/run.cgi/)
When you first import it, you should have a look at what has been provided to you and see where
you have to make changes. Comments have been provided where you need to provide your code.
Your main task is to link the application together (Flask front-end and back-end logic). You must
complete this task individually.
Task 1: Implementation of Flask Login Authentication Module (2 marks)
For this exercise, you will implement a simple authentication module using Flask Login. Carry out the
following tasks:
a. Install the required files
1. In your virtual environment, install the necessary flask plug-ins by typing:
pip3 install –r requirements.txt
b. Implement the flask login route
For this task, you are required to implement the flask route
@app.route('/login', methods=['GET', 'POST'])
as marked in the comments as Task 1. The necessary view components are already provided to you. The
function to validate the authentication details (‘user-name and password’) is also provided in
CarRentalSystem.py
Task 2: Implement the use-case “search for a car by name and model” (4 marks)
For this task, you need to implement the use-case to “search for a car by name and model”.
Once you have logged in with a valid user-name and password, you are taken to a page that has a
link, “search cars”. This launches a page with a list of all cars currently being used by the car rental
system. At the top, you will see a filter with two search fields for “make” and “model” that allows
you to search for cars by a specified “make” OR “model” e.g., when you specify a “make” e.g.,
Honda and click on search, this should load a page to display all the cars in the rental system that
match the specified make as shown below.
Your task is to implement the logic for this filter search. For this task, you will need to carry out
two sub-tasks:
implement the function def car_search(self, name=None, model=None): in the file
CarRentalSystem.py (2 marks)
implement the route @app.route('/cars') in the Flask routes file routes.py to carry out the
necessary search using the function above and pass the results to be displayed to the search page
cars.html which has been provided to you. (2 marks)
Task 3: Implement the use-case “search all car bookings” (4 marks)
For this task, you need to implement the use-case to “list all bookings for a car”. Clicking
on any of the cars on the search result above, loads a page with details about the car. At the
bottom of the page, two buttons are displayed. The button Book enables a new booking to be
created for the car which has already been implemented. The second button See All Bookings
shows a list of current bookings for the car which is to be implemented by you. For this task, you
will need to carry out two sub-tasks:
implement the route @app.route('/cars/bookings/<rego>’) in the Flask routes file
routes.py to retrieve the current bookings for a car and pass the results to be displayed
to the search page bookings.html which you have to implement. (2 marks)
implement the search page route bookings.html which will display the bookings as
described above. The skeleton file is provided to you. (2 marks)
Bonus Task: Implement the Admin System (4 marks)
For this task, you need to implement a simplified solution to the admin use-cases “Add new Car” and
“Generate Rental Report”. On the login page, a separate form for logging-in as an admin is provided.
For this task, you will need to carry out three sub-tasks:
Implement the route @app.route('/login_admin’) in the Flask routes file routes.py
to enable admin users to login using their credentials (1 mark)
Implement the route @app.route('/cars/bookings’) which should display the list of
all current bookings on the system (1 mark)
? Implement the route @app.route('/add_car’) which should allow admin users to
register new cars to the system, using the method provided in CarFactory.py.
Also, provide a meaningful message to the user upon successful car registration,
by making changes to the given car_register_form.html file. (2 marks)
Testing the implementation
You have been provided with some test data to demonstrate your implementation. Once you have
implemented the above tasks, test your implementation with the provided test-data.
Marking
To obtain a mark for this lab you will need to demonstrate:
Upload completed solution by Sunday, week 09 to GitHub (before mid-sem break)
Demonstrate successful implementation of tasks 1, 2 and 3 to your tutor in week 10 lab session
(after mid-sem break)
Please note, students on the Monday lab, as Monday is a public holiday, you have an alternative labtime
scheduled just for this week. Please refer to the course time-table for exact time and location
of week 10 lab.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。