A system to keep track of books borrowed in a school library.
There are two types of users in the system, librarians and administrators
An administrative officer of the school. Administrators can manage students, staff and users.
Administrators can:
- Register new students
- Delete students who are no longer in the school 1
- Register new staff
- Remove staff who no longer work in the school 1
- Add new users
- Delete existing users
- View Unreturned books
- View Damaged books
A librarian who can records all borrowed books.
Librarians can:
- View a list of unreturned books 2
- Record a new borrow transaction
- Record the return of a book
- Report a book as damaged or lost
- Add new books to the inventory
A file containing all the SQL commands used to create the database. It is run immediately the database is created.
A table that keeps the records of all the people involved in the system. It's columns are:
- id: The primary key
- first_name
- middle_name
- surname
- birthdate: uses the ISO8601 date format
A table that stores the information of all the users who can log in to the system. It's columns are:
- username: The username used in logging in
- password_hash:: The hashed password of the user
- user_role: A string that identifies whether the user is an administrator or librarian
- id: Primary key
- person_id: A Foreign key that links to the id in the people table
A table that stores the data of the staff of the school. It's columns are:
- id: Primary key
- person_id: A Foreign key that links to the id in the people table
- job_title
A table that stores the data of the students of the school. It's columns are:
- admission_no: Primary key
- person_id: A Foreign key that links to the id in the people table
- class
A table that stores the data of all the books in the school library. It's columns are:
- id: Primary key
- title
- publication_date: Uses the ISO8601 date format
- qauntity: The number of copies of this book in the inventory
- category
- reference: An integer that is 1 if the book is a reference book and 0 if it is not. A reference book cannot be borrowed
A table that stores all the records of borrowing. The records are permanent. It's columns are:
- id: Primary key
- book_id: A foreign key to identify the book being borrowed
- person_id: A foreign key to identify the person borrowing the book
- person_role: Whether the person was a member of staff or a student when the book was borrowed
- date_borrowed: uses the ISO8601 date format
- date_returned uses the ISO8601 date format. If the book is not returned, the value is NULL
This is a table that stores keeps track of all the books that have been borrowed. This is a separate table to prevents wasting time searching the borrows table as the number of borrows increases.
- borrow_id: A foreign key that links to the borrows table
- date_expected: Uses the ISO8601 date format. This date is on week after the book was borrowed.
This table keeps record of all the books that have been damaged
- book_id: A foreign key that links to the id in the books table
- report_date: Uses the ISO8601 date format
The css and javascript files used in the project are stored in this folder.
This folder contains the html templates used in the project.
This is the base template that all other templates inherit from. It links the bootstrap css and javascript files. It has two blocks:
-
title: This contains the title to be displayed in the title head element and in a heading tag in the main body.
-
body: This is the main content of the page.
It also includes a navbar for easy navigation that changes depending on the role of the user logged in.
It has a footer that displays dismissible flashed messages as alerts.
This template contains the login form. It submits to the /login
route.
This template contains a form that could be used to search for a member of staff. It takes two variables:
- title: The Title of the page to be displayed.
- action: The route that the form is submitted to.
This template displays a list of staff, each with a button to carry out some action. The button submits the person_id
of the member of staff to a specified route. It takes the variables:
- title: The title of the page to be displayed. It also serves as the label for the button.
- staff: A list of the staff that are to be displayed.
- action: The route to which the selected
person_id
will be submitted to.
This template contains a form that could be used to search for a student. It takes two variables:
- title: The Title of the page to be displayed.
- action: The route that the form is submitted to.
- classes: A list of all the classes a student could be in.
This template displays a list of students, each with a button to carry out some action. The button submits the admission_no
of the student to a specified route. It takes the variables:
- title: The title of the page to be displayed. It also serves as the label for the button.
- staff: A list of the staff that are to be displayed.
- action: The route to which the selected
admission_no
will be submitted to.
This template displays a list of unreturned books and optionally a button submits the borrow_id
to a specified route. It takes the variables:
- title: The title of the page to be displayed. It also serves as the label for the button if any.
- action: The route to which the
borrow_id
will be submitted. - student_borrows: A list of information (in the form of a dictionary) about books borrowed by students.
- staff_borrows: A list of information (in the form of a dictionary) about books borrowed by staff.
This template displays a form for a member of staff to be added. The form is submitted to /staff/add
.
This template displays a form for a student to be added. The form is submitted to /students/add
. It takes the variable:
- classes: A list of the classes a student can possibly be in.
This template displays a form for a user to be added. The form is submitted to /users/add
. It takes the variable:
- roles: A list of the roles a user can play.
This template displays a list of books that have been reported to be damaged. It takes the variable:
- books: A list of the books that were reported damaged along with the date it was reported.
This template shows a list of the actions the admin can take:
- Manage Students
/students
- Manage Staff
/staff
- Manage Users
/users
- View Reports
/reports
A menu to select the reports to view:
- Unreturned Books
/reports/unreturned
- Damage Report
/reports/damaged
A menu to select the action to carry out related to staff:
- Add Staff
/staff/add
- Remove Staff
/staff/remove
A menu to select the action to carry out related to students:
- Add Student
/student/add
- Remove Student
/student/remove
A menu to select the action to carry out related to users:
- Add User
/users/add
- Remove Remove
/users/remove
This template displays a list of users, each with a button to carry out some action. The button submits the id
of the user to a specified route. It takes the variables:
- title: The title of the page to be displayed. It also serves as the label for the button.
- users: A list of the users that are to be displayed.
- action: The route to which the selected
person_id
will be submitted to.
This template shows a list of the actions the admin can take:
- Add Book
/add_book
- Borrow
/borrow
- Return
/return
- Report Damage
/damage
This template diaplays a form for adding books to the inventory. It is submitted to /add_book
.
This template displays a form for searching for a book. It takes the variables:
- action: The route to which the form will be submitted.
- role: If a person has previously been selected, this will be either 'staff' or 'student'.
- person_id: If a person has previously been selected, this will be their
person_id
This template displays a list of books along with a button that submits the book_id
to a specified route. It's variables are:
- title: The title of the page to be displayed. It also serves as the label for the button.
- action: The route to which the form will be submitted.
- books: The list of books to be displayed.
- extra_info: A dictionary of extra information to be submitted alongside the
book_id
.
A menu to select the kind of person who is borrowing a book:
- Student Borrow
/borrow/student
- Staff Borrow
/borrow/staff
-
CLASSES: A list that contains all the classes that students can be in.
-
ROLES: A dictionary with the roles that users can have and their proper representations.
An sqlite database called library.sqlite
is connected to. If it was just created, then schema.sql
is run. A cursor to query the database is also created.
When the database is created, a test person is inserted and then linked to two users, 'admin' and 'librarian', both with the password 'test'.
This is a decorator to ensure that the user is an administrator. It checks the user's session to see if the role is set to "admin"
.
This is a decorator to ensure that the user is an librarian. It checks the user's session to see if the role is set to "librarian"
.
It takes two arguments:
title
: The title of the rendered page and the label of the button.action
: The route to which the button associated with each unreturned book submits data.
Queries the database to get the list of unreturned books and using that returns a rendered 'unreturned.html'
template with the title, title
which submits the form to action
.
A replacement for url_for
which returns None
if a BuildError
is encountered. This is necessary for url paths with variables not to break the 'base.html'
template.
A filter that formats headings by replacing underscores with spaces and capitalizing every word.
Renders the appropriate home page template depending on the role of the user. The user is redirected to the login page if not logged in.
-
GET: Renders the login page.
-
POST: Checks the user's credentials and redirects to the index if they are correct. Otherwise the user is redirected back to the login.
The default value of action
is 'choose'.
-
/students/choose
displays a menu for choosing an action. -
/students/add
displays a form for entering the student's information. When the form is submitted, the data is validated and the student is added to the database. -
/students/remove
displays a form for searching for a student. The matching students are then displayed along with a button for submitting theiradmission_no
to/students/delete
. -
/students/delete
sets theclass
of the student whoseadmission_no
was received to'Retired'
.
The default value of action
is 'choose'.
-
/staff/choose
displays a menu for choosing an action. -
/staff/add
displays a form for entering the staff member's information. When the form is submitted, the data is validated and the staff member is added to the database. -
/staff/remove
displays a form for searching for a staff member. The matching staff are then displayed along with a button for submitting theirperson_id
to/staff/delete
. -
/staff/delete
sets thejob_title
of the staff member whoseperson_id
was received to'Retired'
.
The default value of action
is 'choose'.
-
/users/choose
displays a menu for choosing an action. -
/users/add
(GET) displays a form for searching for a staff member to add as a user. The form is submitted to/users/add_list
. -
/users/add_list
(POST) displays a list of staff members that match the search. Buttons corresponding to each member of staff submit theirperson_id
to/users/add
. -
/users/add
(POST) displays a form that asks for the username, password and role of the user repeatedly until they are entered and submits to itself. When the details are entered, it enters the user into the database using theperson_id
supplied from/users/add_list
and redirects the user to the home page. -
/users/remove
displays a list of the users currently registered along with buttons that submit theperson_id
of the user to itself. If aperson_id
is submitted to it, it deletes the user with thatperson_id
.
A list of reports for the admin to see.
Displays a form for adding books which updates the database when submitted.
Allows the person who is borrowing the book to be searched for and submits the person_id
or admission_no
to process_borrow.
Records the borrow in the database and redirects to the home page.
Brings a form to search for the book that is damaged and generates a list of the books that meet the search criteria with buttons that the book_id
submit to /process_damage
.
Records the damage in the database and redirects to the home page.
Logs the user out and redirects to the login page.
Displays some information about the creator