Coverage for ApiJO_Back\settings.py: 100%
31 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-13 15:18 +0200
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-13 15:18 +0200
1"""
2Django settings for ApiJO_Back project.
4Generated by 'django-admin startproject' using Django 5.2.
6For more information on this file, see
7https://docs.djangoproject.com/en/5.2/topics/settings/
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/5.2/ref/settings/
11"""
12import os
13from pathlib import Path
14from decouple import config
15from datetime import timedelta, datetime
18# Build paths inside the project like this: BASE_DIR / 'subdir'.
19BASE_DIR = Path(__file__).resolve().parent.parent
21def parse_duration(hms_string):
22 t = datetime.strptime(hms_string, "%H:%M:%S")
23 return timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
27# Quick-start development settings - unsuitable for production
28# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
30# SECURITY WARNING: keep the secret key used in production secret!
31SECRET_KEY = config('SECRET_KEY')
33# SECURITY WARNING: don't run with debug turned on in production!
34DEBUG = config('DEBUG', cast=bool)
35ALLOWED_HOSTS = config('ALLOWED_HOSTS').split(',')
36CORS_ALLOWED_ORIGINS = config("CORS_ALLOWED_ORIGINS").split(",")
37CORS_ALLOW_CREDENTIALS = True
40INSTALLED_APPS = [
41 'django.contrib.auth',
42 'django.contrib.contenttypes',
43 'django.contrib.sessions',
44 'django.contrib.messages',
45 'django.contrib.staticfiles',
46 'django.contrib.sites',
47 #tiers
48 'rest_framework',
49 'django_extensions',
50 'corsheaders',
51 #local
52 'api.apps.ApiConfig',
53 'users.apps.UsersConfig',
54 'authentication.apps.AuthenticationConfig',
55 'payment.apps.PaymentConfig',
56 'qr_code_service.apps.QrcodeConfig',
57 # swagger
58 'drf_spectacular',
59]
60SIMPLE_JWT = {
61 'ACCESS_TOKEN_LIFETIME': parse_duration(config('ACCESS_TOKEN_LIFETIME')),
62 'REFRESH_TOKEN_LIFETIME': parse_duration(config('REFRESH_TOKEN_LIFETIME')),
63 'ROTATE_REFRESH_TOKENS': False,
64 'ALGORITHM': 'HS256',
65 'SIGNING_KEY': SECRET_KEY,
66}
67AUTH_USER_MODEL = 'users.User'
69MIDDLEWARE = [
70 'django.middleware.security.SecurityMiddleware',
71 'django.contrib.sessions.middleware.SessionMiddleware',
72 'django.middleware.common.CommonMiddleware',
73 'django.middleware.csrf.CsrfViewMiddleware',
74 'django.contrib.auth.middleware.AuthenticationMiddleware',
75 'django.contrib.messages.middleware.MessageMiddleware',
76 'django.middleware.clickjacking.XFrameOptionsMiddleware',
77 'corsheaders.middleware.CorsMiddleware',
78 'django.middleware.common.CommonMiddleware',
80]
81REST_FRAMEWORK = {
82 'DEFAULT_AUTHENTICATION_CLASSES': (
83 'rest_framework_simplejwt.authentication.JWTAuthentication',
84 ),
85 'DEFAULT_RENDERER_CLASSES': (
86 'rest_framework.renderers.JSONRenderer',
87 ),
88 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
89}
91ROOT_URLCONF = 'ApiJO_Back.urls'
92WSGI_APPLICATION = 'ApiJO_Back.wsgi.application'
94# Database
95# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
96DATABASES = {
97 'default': {
98 'ENGINE': 'django.db.backends.postgresql',
99 'NAME': config('DATABASE_NAME'),
100 'USER': config('DATABASE_USER'),
101 'PASSWORD': config('DATABASE_PASSWORD'),
102 'HOST': config('DATABASE_HOST'),
103 'PORT': config('DATABASE_PORT'),
104 }
105}
107# Password validation
108# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
110AUTH_PASSWORD_VALIDATORS = [
111 {
112 'NAME': 'authentication.validators.passwordValidator.StrongPasswordValidator',
113 },
114]
116# Internationalization
117# https://docs.djangoproject.com/en/5.2/topics/i18n/
119LANGUAGE_CODE = 'fr-FR'
121TIME_ZONE = 'Europe/Paris'
123USE_I18N = True
125USE_TZ = True
128# Static files (CSS, JavaScript, Images)
129# https://docs.djangoproject.com/en/5.2/howto/static-files/
131STATIC_URL = 'static/'
132STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
134# Default primary key field type
135# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
137DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
138APPEND_SLASH = True
140TEMPLATES = [
141 {
142 'BACKEND': 'django.template.backends.django.DjangoTemplates',
143 'DIRS': [], # ou ton dossier templates personnalisé
144 'APP_DIRS': True, # <- doit être True pour trouver les templates des apps
145 'OPTIONS': {
146 'context_processors': [
147 'django.template.context_processors.debug',
148 'django.template.context_processors.request',
149 'django.contrib.auth.context_processors.auth',
150 'django.contrib.messages.context_processors.messages',
151 ],
152 },
153 },
154]