Show QR on Library Card to get recent status
Not this is the result
After selecting select option, camera appears to check the QR on library card.
Now show the QR of the book you want to return
Introduction: In this article, we will explore how to build a Library Management System using Python and PostgreSQL. A Library Management System is a crucial tool for organizing and managing the resources of a library efficiently. We will focus on key functionalities such as user authentication, book management, and transaction tracking. To accomplish this, we will utilize the bcrypt library for password hashing and the psycopg2 library to interact with the PostgreSQL database.
Section 1: Setting up the Environment The first step is to set up the development environment. We need to install Python, PostgreSQL, and the necessary libraries, including bcrypt and psycopg2. Once the environment is ready, we can proceed to the implementation of different functionalities.
Section 2: User Authentication User authentication is a fundamental component of any system. We will implement functions to store and validate usernames and passwords securely using bcrypt for password hashing. Additionally, we will create functions to retrieve the role of a user and determine if a user is a librarian.
Section 3: Book Management Managing books is a core aspect of a library management system. We will implement functions to check the availability of books, retrieve book details based on ISBN, and insert new books into the system. We will also incorporate features to issue books to users and update the available copies accordingly.
Section 4: Transaction Tracking Tracking book transactions is vital for monitoring the borrowing and returning of books. We will create functions to issue books to users, update the transaction status, and calculate the duration a book has been borrowed. This information will be valuable for managing overdue books and maintaining accurate records.
Section 5: User Management Apart from books, managing user data is also essential. We will implement functions to store user information, including personal details and contact information. These functions will ensure the availability of accurate user data for various system operations.
Conclusion: Building a Library Management System using Python and PostgreSQL provides an efficient and organized approach to manage library resources. With user authentication, book management, and transaction tracking functionalities, the system becomes a powerful tool for librarians and library staff. By leveraging the bcrypt library for secure password hashing and the psycopg2 library for seamless interaction with the PostgreSQL database, we ensure data integrity and user privacy. This article serves as a starting point for implementing a robust Library Management System, which can be further enhanced and customized based on specific requirements.
In summary, this article has outlined the process of building a Library Management System using Python and PostgreSQL. By following the provided code snippets and explanations, developers can gain a solid foundation for creating their own library management solutions. With the system in place, librarians can efficiently manage books, track transactions, and provide seamless services to library users.
The application starts with the Streamlit import and the import of two custom modules: sql_queries and utilities. These modules likely contain additional functions and SQL queries used by the application.
The code sets up the basic structure of the application's user interface using Streamlit. It creates a sidebar with a "Login Page" header and two input fields for username and password. The user enters their credentials, and if the "Validate" checkbox is selected, the code calls the validate_password function from the sql_queries module to check if the entered username and password are valid.
If the password is validated successfully, the code retrieves the user's role using the get_user_role function from sql_queries. If the user role is found, it is capitalized and displayed in a subheader.
Next, the code checks if the user is a librarian by calling the is_librarian function from sql_queries. If the user is a librarian, the code displays a tabbed interface with several sections: "Book Management," "Book Issue," "Book Return," "Show Library Card Details," and "User Management."
Within each tab, specific functionality is implemented. For example, in the "Book Management" tab, there is a form to insert a new book, which is created using the create_new_book_form function from the utilities module.
Similarly, in the "Book Issue" and "Book Return" tabs, book issuing and returning functionalities are implemented using the issue_book and return_issued_book functions from the utilities module, respectively.
In the "Show Library Card Details" tab, there is a checkbox that, when selected, calls the show_library_card_details function from utilities to display the library card details.
In the "User Management" tab, there is a form to create a new user. Depending on the selected user type (student or faculty), the create_new_student_form or corresponding function for creating a faculty member is called from utilities.
After the main interface, there is another section in the sidebar with a header and a checkbox for "Show Library Card Details." When this checkbox is selected, it displays the library card details by calling the show_library_card_details function from utilities.
Several functions that interact with a PostgreSQL database using the psycopg2 library. These functions serve different purposes related to managing the Library Management System (LMS). Let's go through each function and describe its functionality:
-
is_student_mobile_present(mobile_number): This function checks if a student with the givenmobile_numberis present in the database. It establishes a connection with the PostgreSQL database, executes a SQL query to count the number of rows matching the mobile number, and returns a boolean indicator. -
is_student_email_present(personal_email): This function checks if a student with the givenpersonal_emailis present in the database. Similar to the previous function, it establishes a database connection, executes a SQL query, and returns a boolean indicator. -
store_username_password(username, password): This function stores theusernameand hashedpasswordin theusers_credentialstable of the database. It uses the bcrypt library to hash the password before storing it securely. -
validate_password(username, entered_password): This function validates the entered password for a givenusername. It retrieves the stored hashed password from the database, hashes the entered password, and compares them for verification. -
insert_user(first_name, last_name, username, email, role): This function inserts a new user into theuserstable with the provided details:first_name,last_name,username,email, androle. -
get_user_role(username): This function retrieves the role of a user with the givenusernamefrom theuserstable. -
get_book_details(isbn): This function retrieves details about a book with the givenisbnfrom thebookstable. -
get_name_and_department_from_student_or_faculty_table(table, username): This function retrieves thefirst_name,middle_name,last_name, anddepartmentof a user from the specifiedtablebased on theusername. -
is_librarian(username): This function checks if a user with the givenusernamehas the role of a librarian. -
is_username_present(username): This function checks if a username is present in thestudenttable. -
insert_new_student_data(values): This function inserts a new student's data into thestudenttable using the providedvalues. -
is_isbn_present(isbn): This function checks if a book with the givenisbnis present in thebookstable. -
insert_new_book(values): This function inserts a new book into thebookstable using the providedvalues. -
issue_book_to_user(username, isbn, librarian_username): This function issues a book to a user with the givenusernameby updating thetransactionstable and theavailable_copiescount of the book in thebookstable. -
Lastly, there is a piece of code at the end that includes a transactional query to retrieve book details for a particular user based on their borrowed transactions.
Overall, these functions provide various functionalities for user management, book management, and transaction handling within the Library Management System.
The utilities.py module in project "LMS" appears to contain several utility functions for various purposes. Here's a breakdown of each function:
-
paste_qr(library_card, qr): This function takes a library card image (library_card) and a QR code image (qr) as input. It pastes the QR code onto the library card image and returns the modified image. -
generate_QR(info_dict): This function generates a QR code image based on the information provided in theinfo_dictdictionary. The dictionary is converted to a string, and then a QR code is generated using theqrcodelibrary. The function returns the bytes value of the QR code image. -
random_password_generator(): This function generates a random password of length 15 using uppercase letters, lowercase letters, and digits. It returns the generated password as a string. -
is_valid_email(email): This function checks if an email address is valid using a regular expression pattern. It returnsTrueif the email is valid andFalseotherwise. -
valid_contact_number(contact_number): This function validates a contact number by checking if it is numeric and has a length of 10. It returnsTrueif the contact number is valid andFalseotherwise. -
contains_special_chars(input_string): This function checks if a string contains any special characters. It returnsTrueif the string contains special characters andFalseotherwise. -
contains_digits(input_string): This function checks if a string contains any digits (numeric characters). It returnsTrueif the string contains digits andFalseotherwise. -
has_trailing_spaces(input_string): This function checks if a string contains trailing spaces on both the left and right sides. It returnsTrueif trailing spaces are found andFalseotherwise. -
get_username_from_QR(window_name): This function captures frames from the camera and detects QR codes. It extracts the username from the decoded QR code data and returns it as a string. -
create_new_student_form(): This function creates a form for entering information about a new student. It uses Streamlit library to create input fields for various student details such as first name, middle name, last name, address, contact number, email, etc. It also performs validation checks on the input fields and displays success or warning messages accordingly. Upon submission, the function inserts the student's data into a database and generates a library card with a QR code. -
random_password_generator(): This function generates a random password. It uses a combination of uppercase letters, lowercase letters, and digits to create a password of length 15 characters. -
is_valid_email(email): This function validates an email address using a regular expression pattern. It checks if the email address has the correct format of username@domain.extension. It returnsTrueif the email is valid, andFalseotherwise. -
valid_contact_number(contact_number): This function validates a contact number. It checks if the contact number is numeric and has a length of 10 digits. It returnsTrueif the contact number is valid, andFalseotherwise. -
contains_special_chars(input_string): This function checks if a string contains any special characters. It defines a string of special characters and loops through each character in the input string to check if it matches any special character. It returnsTrueif a special character is found, andFalseotherwise. -
contains_digits(input_string): This function checks if a string contains any digits (numeric characters). It loops through each character in the input string and checks if it is a digit. It returnsTrueif a digit is found, andFalseotherwise. -
has_trailing_spaces(input_string): This function checks if a string contains trailing spaces on both the left and right sides. It uses therstrip()andlstrip()functions to remove the trailing spaces from the input string and compares it with the original string. If they are not equal, it means there are trailing spaces. It returnsTrueif trailing spaces are found on both sides, andFalseotherwise. -
get_username_from_QR(window_name): This function captures a frame from the camera, converts it to grayscale, and detects QR codes in the frame. It extracts the barcode data from the QR code and returns the username if it is found in the barcode data. It uses thecv2andpyzbarlibraries for image processing and QR code decoding. -
create_new_student_form(): This function creates a form for entering new student information. It uses Streamlit to display input fields for first name, middle name, last name, address, contact number, parent number, email, department, admission year, graduation year, and current address. It performs validation checks on the input values and displays warnings if any validation fails. It also checks if the mobile number and email are already registered in the database. If all the input values are valid, it inserts the student data into the database, generates a library card, and displays a QR code with the student information.





