E-Library is a web-based application designed to provide a comprehensive platform for managing and accessing a digital library. The application is built using Django and JavaScript, with package management handled by pip for Python and npm for JavaScript.
The application allows users to browse through a vast collection of digital books, each associated with its respective author. Users can also borrow and return books, providing a dynamic and interactive library experience.
The application has two main user roles: User and Administrator. A User can browse the library, borrow books, and return them when finished. An Administrator, on the other hand, has the ability to add, delete, and modify books and authors in the library, providing comprehensive management of the library's content.
The application ensures secure user authentication and role-based access to various features. It also includes robust error handling and user notifications for a smooth user experience.
The project uses a PostgreSQL database for data storage, managed through Django's ORM. It also leverages Cloudinary for efficient and scalable media management.
The application's user interface is designed to be intuitive and user-friendly, ensuring a seamless user experience.
- Access to the application is only possible through a login and password.
- The application has 2 user roles: Reader and Administrator.
- Registration of a new user (with the role of Reader) through the user interface.
Common functionality for both roles includes:
- Logging into the application through a login form.
- Viewing all books in the library.
- Editing information in the profile about the current user logged into the system, including changing the photo.
- If the user will try to access the route that is not exist, the user will be redirected to the 404 page.
- There are tooltips for all interactive elements in the application which provide additional information about the action that will be performed after clicking on the element.
- There are toasts for all create, update and delete operations which provide current user details about what he\she has just done.
- All input fields in this application are mandatory and have a validation on the client side.
Reader functionality:
- Borrowing books from the library.
- Returning books to the library.
- Seeing books that are unavailable and who is reading them.
- Does not have access to the authors' page, if the user tries to access this page, the user will be redirected to the 403 page.
- On the profile page, view the books that the reader is currently reading.
- There was also implemented a special error handling for 500 error, which is simulated on the server side. To see it, you need to check checkbox on profile page.
Administrator functionality:
- Adding new book authors.
- Editing book authors.
- For Adding and Editing book authors operations, implemented complex validations on client and server sides.
- Client side: the input field cannot be empty and should be at least 1 character long.
- Server side: each word must start with a capital letter separated by a space.
- Deleting book authors.
- Adding new books.
- Editing existing books.
- Deleting existing books.
- If a book is already being read by someone, such a book cannot be edited and the author of such a book also cannot be edited. The book must be returned by the reader before it can be edited or deleted.
-
Books
-
Administrator:
-
User:
-
-
Authors
-
My Profile
- Protection of routes by roles through decorators.
- Make a check so that you cannot enter the same title of a book by the same author twice.
- Pagination, if there is a lot of content.
- Use ajax to avoid page reloading.
- Returning a book from the profile page.
- External link field in the books from which the book content could be accessed.
The project was managed using a GitHub Project Board
-
User Model: This is a built-in Django model that represents the users of your application. It includes fields for username, password, email, first name, and last name. The User model is used for authentication and authorization in the Django framework.
-
ProfileImage Model: This model is related to the User model with a one-to-one relationship. It represents the profile image of a user. It includes the following fields:
user
: A one-to-one field linking to the User model. When a User instance is deleted, the associated ProfileImage instance will also be deleted.image
: A field that stores the image of the user's profile. It uses the Cloudinary service for image hosting.
-
Author Model: This model represents the authors of the books in your application. It includes the following field:
name
: A character field with a maximum length of 200 characters that stores the name of the author.
-
Book Model: This model represents the books in your application. It includes the following fields:
title
: A character field with a maximum length of 200 characters that stores the title of the book.author
: A foreign key field linking to the Author model. When an Author instance is deleted, the associated Book instances will not be deleted but theauthor
field will be set to NULL.reader
: A foreign key field linking to the User model. It represents the user who is currently reading the book. When a User instance is deleted, thereader
field in the associated Book instances will be set to NULL.
The User model handles user authentication, the ProfileImage model handles user profile images, the Author model represents book authors, and the Book model represents the books in application and their current reader.
- Google Fonts:
- Google fonts were used to import the 'Open Sans' font into the style.css file which is used on all pages throughout the project.
- Font Awesome 6.5.2:
- Font Awesome was used on all pages throughout the website to add icons for aesthetic and UX purposes.
- Bootstrap 5.3.3:
- Bootstrap was used to assist with the responsiveness and styling of the website.
- jQuery 3.7.1:
- jQuery came with Bootstrap to make the navbar responsive but was also used to show tooltips.
- Google Chrome 124.0.6367.62:
- Google Chrome was used as a browser to render and debug this project.
- Django 4.1.13:
- Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.
- There were also used other libraries in this project.
- ElephantSQL:
- ElephantSQL was used to store data.
- Cloudinary:
- Cloudinary was used to store images.
- Node.js 20.12.2:
- Node.js was used to run JavaScript unit-tests.
- npm 10.7.0:
- npm was used as a package manager for installing dependencies.
- JSHint:
- JSHint was used to check the quality of JavaScript code.
- Jest 26.6.3:
- Jest was used for writing unit-test for JavaScript part of this Project.
- Coverage 7.4.4:
- Coverage was used to measure code coverage of Python code.
- Git 2.39.1:
- Git was used for version control to commit and Push code to GitHub.
- GitHub:
- GitHub was used to store the projects code after being pushed from Git.
- Heroku:
- Heroku was used to deploy the project.
- Bash 5.2.12:
- Bash was used to automate running Test Coverage reports.
- GitHack:
- GitHack was used to render Code coverage reports when you click on it on this page.
- Far Manager 3.0.5700.0:
- Far Manager was used to work with files.
- PyCharm 2024.1:
- PyCharm was used to write all code for this project.
- Microsoft Windows 10.0.19045 Enterprise:
- Windows was used as an operating system for development this project.
-
Testing login with correct credentials
- Navigate to the login page.
- Enter the correct username and password.
- Click the "Sign in" button.
- Verify that you are redirected to the book page of the application.
-
Testing login with incorrect credentials
- Navigate to the login page.
- Enter incorrect username and password.
- Click the "Sign in" button.
- Verify that an error message is displayed.
-
Testing registration with correct data
- Navigate to the registration page.
- Enter correct data into all form fields.
- Click the "Sign Up" button.
- Verify that you are redirected to the book page with a successful login message.
-
Testing registration with incorrect data
- Navigate to the registration page.
- Enter incorrect data into one or more form fields.
- Click the "Sign Up" button.
- Verify that an error message is displayed.
-
Testing viewing the list of books
- Navigate to the books page.
- Verify that a list of all books is displayed.
-
Testing viewing book details
- Login as an Administrator.
- Navigate to the books page.
- Click on edit button one of the books.
- Verify that a page with details of the selected book is displayed.
All additional features and functionality not explicitly mentioned in this section have also been thoroughly tested and are confirmed to be working correctly.
The entire project is covered by unit tests. Test coverage reports can be viewed in the following links:
- HTML
- All errors found by official W3C validator were fixed in separate commit.
- CSS
- No errors were found when passing through the official (Jigsaw) validator
- JavaScript
- No errors were found when passing through the JSHint validator according to settings.
- Python - All errors found by CI Python Linter were fixed in separate commit.
- Accessibility
- Due to the fact that as an initial template I took an open source template and modified it, there may be unused classes in HTML and CSS, because I did not find tool that can check it automatically, I tried to find and remove it manually.
By default, all console commands should be run in git bash terminal.
The project was deployed to Heroku.
The process of deploying this project to Heroku is consist of these main steps.
- You should have accounts on GitHub, Heroku, Cloudinary, ElephantSQL.
- You should create database on ElephantSQL and create models.
- Deploy the project to Heroku.
To get the CLOUDINARY_URL, you need to create an account on Cloudinary and follow the instructions to get the URL:
- Log in to your Cloudinary account.
- Go to the "Dashboard" in section "Product Environment Credentials" you will see "API environment variable". It is your CLOUDINARY_URL.
To get the DATABASE_URL and SECRET_KEY, you need to create an account on ElephantSQL and follow the instructions to get the URL:
- Log in to your ElephantSQL account.
- Click on "Create New Instance".
- Name your database and select the "Tiny Turtle Free" plan.
- Select the data center near you and click "Review".
- Click "Create Instance".
- Click on your new database instance you just created in section Details you will see Password and URL, this corresponds to the SECRET_KEY and DATABASE_URL.
To create models on ElephantSQL you need to do the following steps:
- Clone the project to your local machine, to do it run this command in your terminal:
git clone https://github.com/SVDotsenko/portfolio-project-4.git
- Follow the instruction in env.md file.
- On your local machine, must be installed Python 3.9.19 or higher.
- Create a virtual environment by running this command in your terminal:
python -m venv .venv
- Activate the virtual environment by running this command in your terminal:
source .venv/Scripts/activate
- Install all dependencies from the requirements.txt file by running this command in your terminal:
pip install -r requirements.txt
- Run the following command in your terminal to create models on ElephantSQL:
python manage.py migrate
- Create a superuser by running this command in your terminal:
python manage.py createsuperuser
- The users with role Reader can be created through the sign-up form.
-
Fork this project into you GitHub account:
-
Log in to your Heroku account.
-
Click on the "New" button and select "Create new app".
-
Choose a unique name for your app, select the region and click "Create app".
-
Go to the "Settings" tab and click on "Reveal Config Vars".
-
Add the following config vars from your env.py file
DATABASE_URL
: Your ElephantSQL database URL.SECRET_KEY
: Your ElephantSQL secret key.CLOUDINARY_URL
: Your Cloudinary URL.DJANGO_DEBUG
: False.
-
In the "Deploy" tab, select "GitHub" as the deployment method.
-
Search for the repository you forked earlier and click "Search".
-
Click "Connect" to connect the repository to Heroku.
-
Scroll down to the "Manual deploy" section and click "Deploy Branch".
-
Once the deployment is complete, click "View" to open the live app.
To run this project locally, you need to do the following steps:
-
Follow the instruction from section Creating models on ElephantSQL in this file.
-
Run this command:
python manage.py runserver
To run unit tests locally and see coverage reports, you need:
- On your machine must be installed Node.js.
- Install dependencies from the package.json file by running this command:
npm install
- Run this command to run unit tests:
./coverage.sh
- The browser should be opened a new tabs with the coverage reports.
This template was adopted for the project.