
Signs for Trucks
Table of Contents
Descripton
This is a README description of our Truck-Signs E-Commerce. The goal of this repository is to provide an online platform where customers can browse, customize, and purchase high-quality truck signs. It includes all the source code and resources necessary to run the application, manage the product catalog, handle orders, and process payments securely.
Prerequisites
To Deploy your Truck-Signs E-Commerce, you need the following:
- VServer with Ubuntu
- Python 3.8
- Docker
Quickstart
Clone-github-Resposiroty
- Clone the folowoing Github Resposiroty
https://github.com/herzogelias/truck_signs_api/
Build-Dockerimage
- Create a Docker Network. Use the following command:
docker network create <Networkname>
- Navigate to the correct directory:
cd truck_signs_api - Start the Prostgress DB.
docker run -d \
--name <Containername> \
--env-file truck_signs_designs/settings/.env \
--network <Networkname> \
--restart always \
postgres:13
- Build the Docker Image. Use the following Command:
docker build -t <Imagename> .
- Run the Docker image:
docker run -d \
--name trucksignsapi \
--network <Networkname> \
-p 8020:8000 \
--restart always \
--env-file truck_signs_designs/settings/.env \
<Imagename>
- Login to you Django Adminpanel: Use the following Link and following Default Data from the env variables:
<your-Ip-Adress>/admin
DJANGO_SUPERUSER_USERNAME=administrator
DJANGO_SUPERUSER_EMAIL=admin@mail.de
DJANGO_SUPERUSER_PASSWORD=administratorlidreifunfD4f!
Usage
Placeholder
You have the Folowing Placeholder in your Docker Build and Run Commands.
Imagename = The name of your Image. You can see that name with the command: ´´´ bash docker images ´´´
Networkname = The name of your Created Docker Network. A list of all Docker Network in your VServer with the following Command: ´´´ bash docker network ls ´´´
Containername = This ist the name of the Container you run. You can see this name with the following Command: ´´´bash docker ps ´´´
Settings
The settings folder inside the trucks_signs_designs folder contains the different setting's configuration for each environment (so far the environments are development, docker testing, and production). Those files are extensions of the base.py file which contains the basic configuration shared among the different environments (for example, the value of the template directory location). In addition, the .env file inside this folder has the environment variables that are mostly sensitive information and should always be configured before use. By default, the environment in use is the decker testing. To change between environments modify the __init.py__ file.
Models
Most of the models do what can be inferred from their name. The following dots are notes about some of the models to make clearer their propose:
- Category Model: The category of the vinyls in the store. It contains the title of the category as well as the basic properties shared among products that belong to a same category. For example, Truck Logo is a category for all vinyls that has a logo of a truck plus some lines of letterings (note that the vinyls are instances of the model Product). Another category is Fire Extinguisher, that is for all vinyls that has a logo of a fire extinguisher.
- Lettering Item Category: This is the category of the lettering, for example: Company Name, VIM NUMBER, ... Each has a different pricing.
- Lettering Item Variations: This contains a foreign key to the Lettering Item Category and the text added by the client.
- Product Variation: This model has the original product as a foreign key, plus the lettering lines (instances of the Lettering Item Variations model) added by the client.
- Order: Contains the cart (in this case the cart is just a vinyl as only one product can be purchased each time). It also contains the contact and shipping information of the client.
- Payment: It has the payment information such as the time of the purchase and the client id in Stripe.
To manage the payments, the payment gateway in use is Stripe.
Brief-Explanation-of-the-Views
Most of the views are CBV imported from rest_framework.generics, and they allow the backend api to do the basic CRUD operations expected, and so they inherit from the ListAPIView, CreateAPIView, RetrieveAPIView, ..., and so on.
The behavior of some of the views had to be modified to address functionalities such as creation of order and payment, as in this case, for example, both functionalities are implemented in the same view, and so a GenericAPIView was the view from which it inherits. Another example of this is the UploadCustomerImage View that takes the vinyl template uploaded by the clients and creates a new product based on it.
Installation
-
Clone the repo:
https://github.com/herzogelias/truck_signs_api/ -
Navigate to the correct directory:
cd truck_signs_api -
Configure a virtual env and set up the database. See Link for configuring Virtual Environment and Link for Database setup.
-
Configure the environment variables.
-
Copy the content of the example env file that is inside the truck_signs_designs folder into a .env file:
cd truck_signs_designs/settings
cp simple_env_config.env .env -
The new .env file should contain all the environment variables necessary to run all the django app in all the environments. However, the only needed variables for the development environment to run are the following:
SECRET_KEY
DB_NAME
DB_USER
DB_PASSWORD
DB_HOST
DB_PORT
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
DJANGO_SUPERUSER_USERNAME=
DJANGO_SUPERUSER_EMAIL=
DJANGO_SUPERUSER_PASSWORD=
DOCKER_DB_NAME=
DOCKER_DB_USER=
DOCKER_DB_PASSWORD=
DOCKER_DB_HOST=
DOCKER_DB_PORT= -
For the database, the default configurations should be:
DOCKER_DB_NAME=trucksigns_db
DOCKER_DB_USER=trucksigns_user
DOCKER_DB_PASSWORD=supertrucksignsuser!
DOCKER_DB_HOST=db
DOCKER_DB_PORT=5432
POSTGRES_USER=trucksigns_user
POSTGRES_PASSWORD=supertrucksignsuser!
POSTGRES_DB=trucksigns_db
DB_NAME=trucksigns_db
DB_USER=trucksigns_user
DB_PASSWORD=supertrucksignsuser!
DB_HOST=localhost
DB_PORT=5432 -
The SECRET_KEY is the django secret key. To generate a new one see: Stackoverflow Link
-
NOTE: not required for exercise
The STRIPE_PUBLISHABLE_KEY and the STRIPE_SECRET_KEY can be obtained from a developer account in Stripe.- To retrieve the keys from a Stripe developer account follow the next instructions:
- Log in into your Stripe developer account (stripe.com) or create a new one (stripe.com > Sign Up). This should redirect to the account's Dashboard.
- Go to Developer > API Keys, and copy both the Publishable Key and the Secret Key.
- To retrieve the keys from a Stripe developer account follow the next instructions:
-
The EMAIL_HOST_USER and the EMAIL_HOST_PASSWORD are the credentials to send emails from the website when a client makes a purchase. This is currently disable, but the code to activate this can be found in views.py in the create order view as comments. Therefore, any valid email and password will work.
-
-
The migrations would like to run automaticly.
-
Congratulations =) !!! The App should be running in localhost:8000
-
Superuser was automaticly Created. Data for the Superuser are configuarted in the following envivonment Variables:
DJANGO_SUPERUSER_USERNAME=administrator
DJANGO_SUPERUSER_EMAIL=admin@mail.de
DJANGO_SUPERUSER_PASSWORD=administratorlidreifunfD4f!
If you don’t set your own values, these defaults will be used automatically. If you prefer, you can specify your own credentials by setting these environment variables to custom values.
NOTE: To create Truck vinyls with Truck logos in them, first create the Category Truck Sign, and then the Product (can have any name). This is to make sure the frontend retrieves the Truck vinyls for display in the Product Grid as it only fetches the products of the category Truck Sign.
Screenshots-of-the-Django-Backend-Admin-Panel
Mobile-View

Desktop-View



Useful-Links
Postgresql-Database
- Setup Database: Digital Ocean Link for Django Deployment on VPS
Docker
- Docker Oficial Documentation
- Dockerizing Django, PostgreSQL, guinicorn, and Nginx:
Django-and-DRF
- Django Official Documentation
- Generate a new secret key: Stackoverflow Link
- Modify the Django Admin:
- Small modifications (add searching, columns, ...): Link
- Modify Templates and css: Link from Medium
- Django Rest Framework Official Documentation
- More about Nested Serializers: Stackoverflow Link
- More about GenericViews: Testdriver.io Link
Miscellaneous
- Create Virual Environment with Virtualenv and Virtualenvwrapper: Link
- Configure CORS
- Setup Django with Cloudinary