Skip to content

API Epic Events (P12 OC D-A Python) : Développez une architecture back-end sécurisée en utilisant Django ORM

Notifications You must be signed in to change notification settings

hmignon/P12_EpicEvents

Repository files navigation

logo-light logo-dark

python-badge django-badge drf-badge postman-badge

black-badge coverage-badge ci-workflow

Contents


About the project

OpenClassrooms Python Developer Project #12: Develop a Secure Back-End Architecture Using Django ORM

Tested on Windows 10 - Python 3.9.5 - Django 4.1 - DRF 3.13.1

Objectives

API-EpicEvents is a Customer Relationship Management (CRM) API designed for Epic Events, an events management company.

Epic Events users can:

  • Create and update a client database
  • Create and manage contracts and organise related events

The RESTful API is implemented with a secured database built with Django ORM and PostgreSQL.

Note: Postman docs are currently only available in French fr-flag, English uk-flag version coming soon.

Post-course optimisation

This project has been optimised after the end of the OpenClassrooms course. To view the previously delivered version, please check this commit.

Improvements made to this project include:

  • Adding a Team model
  • Providing custom management commands to create dummy data
  • Optimising test coverage
  • Improving the admin site interface with Jazzmin
  • Implementing a CI workflow for automating tests
  • General project refactoring

Local development

Clone repository and install dependencies

Windows

git clone https://github.com/hmignon/P12_mignon_helene.git

cd P12_mignon_helene 
python -m venv env 
env\Scripts\activate

pip install -r requirements.txt

MacOS and Linux

git clone https://github.com/hmignon/P12_mignon_helene.git

cd P12_mignon_helene 
python3 -m venv env 
source env/bin/activate

pip install -r requirements.txt

Create PostgreSQL database

Install PostgreSQL. Follow the documentation to run the server.

Create a new PostgreSQL database with SQL shell (psql) : CREATE DATABASE your_db_name;

Environment variables : .env file

To generate a .env file, run python create_dot_env.py and input the info required.

Example of a generated .env file:

SECRET_KEY=j%yuc7l_wwz5t8d=g)zxh6ol@$7*lwx6n0p)(k$dewlr0hf2u-
DATABASE_NAME=your_db_name
DATABASE_USER=your_db_user
DATABASE_PASS=your_db_password

The Django secret key is randomly generated.

Migrate the database

To migrate, run python manage.py migrate. The 3 user teams (manager, sales, support) are automatically created; to learn more about user teams and their permissions, check the API docs.

Create a superuser

Run python manage.py create superuser. Superusers are automatically added to the management team, and have access to the admin site.

Create data with custom management commands

Run the following commands prefixed with python manage.py to create some dummy data:

Command Description
create_data Create a set of all objects (15 users, 50 clients, 20 contracts, 10 events). No extra args.
create_users Create a set of users. Args: -n or --number (default: 15).
create_clients Create a set of clients. Args: -n or --number (default: 50).
create_contracts Create a set of contracts. Args: -n or --number (default: 20).
create_events Create a set of clients. Args: -n or --number (default: 10).
Note: Events are exclusively related to one signed contract (one to one rel); the command will create as many events as possible if the amount provided is higher than available contracts.

Usage

Run the server with python manage.py runserver. The CRM is browsable via:

Note : CRM access to managers and admins is read-only. Creating, updating and deleting elements is available in the admin site.

Admin site

Admin site interface EpicEvents Admin interface

Tha admin site is available at http://127.0.0.1:8000/admin/. Admin site access is granted to managers and superusers.

For a better user experience, the admin interface is customized and jazzed up with Jazzmin.

Testing, coverage and error logging

Run tests locally with python manage.py test.

Check test coverage with coverage run --source='.' manage.py test and coverage report.

Latest coverage report:

latest coverage report

All app errors are logged in to errors.log.

About

API Epic Events (P12 OC D-A Python) : Développez une architecture back-end sécurisée en utilisant Django ORM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages