StudE-Backend/stude/config/settings.py

200 lines
5.2 KiB
Python
Raw Normal View History

2023-06-26 18:58:20 +08:00
"""
Django settings for stude project.
Generated by 'django-admin startproject' using Django 4.2.2.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from pathlib import Path
from dotenv import load_dotenv # Python dotenv
import os
load_dotenv() # loads the configs from .env
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = str(os.getenv('SECRET_KEY'))
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*', '127.0.0.1', 'localhost', '10.0.10.32', '10.0.10.8']
2023-06-26 18:58:20 +08:00
2023-06-26 20:36:58 +08:00
# Email credentials
EMAIL_HOST = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = ''
EMAIL_USE_TLS = False
2023-06-26 20:36:58 +08:00
if (DEBUG == True):
EMAIL_HOST = str(os.getenv('DEV_EMAIL_HOST'))
EMAIL_HOST_USER = str(os.getenv('DEV_EMAIL_HOST_USER'))
EMAIL_HOST_PASSWORD = str(os.getenv('DEV_EMAIL_HOST_PASSWORD'))
EMAIL_PORT = str(os.getenv('DEV_EMAIL_PORT'))
else:
EMAIL_HOST = str(os.getenv('PROD_EMAIL_HOST'))
EMAIL_HOST_USER = str(os.getenv('PROD_EMAIL_HOST_USER'))
EMAIL_HOST_PASSWORD = str(os.getenv('PROD_EMAIL_HOST_PASSWORD'))
EMAIL_PORT = str(os.getenv('PROD_EMAIL_PORT'))
EMAIL_USE_TLS = str(os.getenv('PROD_EMAIL_TLS'))
2023-06-26 20:36:58 +08:00
2023-06-26 18:58:20 +08:00
# Application definition
INSTALLED_APPS = [
2023-07-01 11:40:49 +08:00
'daphne',
2023-06-26 18:58:20 +08:00
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_simplejwt',
2023-06-26 19:10:04 +08:00
'djoser',
2023-06-26 20:36:58 +08:00
'accounts',
2023-06-26 22:06:05 +08:00
'student_status',
2023-06-27 14:16:40 +08:00
'courses',
'year_levels',
2023-06-27 15:48:43 +08:00
'semesters',
2023-06-27 18:15:31 +08:00
'subjects',
2023-06-27 21:12:03 +08:00
'study_groups',
'studygroup_messages',
2023-06-26 18:58:20 +08:00
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
2023-06-26 22:10:29 +08:00
"whitenoise.middleware.WhiteNoiseMiddleware",
2023-06-26 18:58:20 +08:00
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
2023-06-26 22:10:29 +08:00
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
2023-06-26 18:58:20 +08:00
ROOT_URLCONF = 'config.urls'
2023-07-01 11:40:49 +08:00
ASGI_APPLICATION = "config.asgi.application"
2023-06-26 18:58:20 +08:00
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR / 'templates',
],
2023-06-26 18:58:20 +08:00
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
2023-06-26 19:10:04 +08:00
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
2023-06-26 19:10:04 +08:00
)
}
2023-06-26 18:58:20 +08:00
WSGI_APPLICATION = 'config.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
2023-06-26 19:45:58 +08:00
AUTH_USER_MODEL = 'accounts.CustomUser'
DJOSER = {
'SEND_ACTIVATION_EMAIL': True,
'SEND_CONFIRMATION_EMAIL': True,
'EMAIL': {
'activation': 'config.email.ActivationEmail'
},
2023-06-26 19:45:58 +08:00
'ACTIVATION_URL': 'activation/{uid}/{token}',
'USER_AUTHENTICATION_RULES': ['djoser.authentication.TokenAuthenticationRule'],
'SERIALIZERS': {
'user': 'accounts.serializers.CustomUserSerializer',
'user_create': 'accounts.serializers.UserRegistrationSerializer',
},
}
2023-06-26 18:58:20 +08:00
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Manila'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
2023-06-26 18:58:20 +08:00
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DOMAIN = ''
if (DEBUG):
DOMAIN = 'exp'
else:
DOMAIN = 'stude'
SITE_NAME = 'Stud-E'