achief

Base.py

May 26th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.25 KB | None | 0 0
  1. import os
  2. from pathlib import Path
  3.  
  4. # used to generate the SECRET_KEY
  5. from django.core.exceptions import ImproperlyConfigured
  6. from dotenv import load_dotenv
  7.  
  8. load_dotenv()
  9.  
  10. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  11. BASE_DIR = Path(__file__).resolve().parent.parent
  12.  
  13.  
  14. # Quick-start development settings - unsuitable for production
  15. # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
  16.  
  17.  
  18. # SECURITY WARNING: don't run with debug turned on in production!
  19. DEBUG = True
  20.  
  21. # Application definition
  22.  
  23. INSTALLED_APPS = [
  24.     "django.contrib.admin",
  25.     "django.contrib.auth",
  26.     "django.contrib.contenttypes",
  27.     "django.contrib.sessions",
  28.     "django.contrib.messages",
  29.     "django.contrib.staticfiles",
  30.     "django.contrib.sites",
  31.     # External Packages
  32.     "rest_framework",
  33.     "rest_framework.authtoken",
  34.     # "corsheaders",
  35.     "drf_spectacular",
  36.     "allauth",
  37.     "allauth.account",
  38.     "allauth.socialaccount",
  39.     # Allauth Third-party Providers
  40.     "allauth.socialaccount.providers.facebook",
  41.     "allauth.socialaccount.providers.github",
  42.     "allauth.socialaccount.providers.google",
  43.     # Internal Apps
  44.     "myapp",
  45.     "myotherapp",
  46.     "severalmoreapps",
  47. ]
  48.  
  49. MIDDLEWARE = [
  50.     "django.middleware.security.SecurityMiddleware",
  51.     # Whitenoise enables static files in production
  52.     "whitenoise.middleware.WhiteNoiseMiddleware",
  53.     "django.contrib.sessions.middleware.SessionMiddleware",
  54.     "django.middleware.common.CommonMiddleware",
  55.     "django.middleware.csrf.CsrfViewMiddleware",
  56.     "django.contrib.auth.middleware.AuthenticationMiddleware",
  57.     "django.contrib.messages.middleware.MessageMiddleware",
  58.     "django.middleware.clickjacking.XFrameOptionsMiddleware",
  59. ]
  60.  
  61. REST_FRAMEWORK = {
  62.     "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
  63.     "DEFAULT_AUTHENTICATION_CLASSES": [
  64.         "rest_framework.authentication.TokenAuthentication",
  65.         "rest_framework.authentication.BasicAuthentication",
  66.     ],
  67.     # This sets all classes and functions as requiring user authentication
  68.     "DEFAULT_PERMISSION_CLASSES": [
  69.         # "rest_framework.permissions.IsAuthenticated",
  70.         "rest_framework.permissions.IsAdminUser"
  71.     ],
  72. }
  73.  
  74. ROOT_URLCONF = "project.urls"
  75.  
  76. TEMPLATES = [
  77.     {
  78.         "BACKEND": "django.template.backends.django.DjangoTemplates",
  79.         "DIRS": [],
  80.         "APP_DIRS": True,
  81.         "OPTIONS": {
  82.             "context_processors": [
  83.                 "django.template.context_processors.debug",
  84.                 "django.template.context_processors.request",
  85.                 "django.contrib.auth.context_processors.auth",
  86.                 "django.contrib.messages.context_processors.messages",
  87.                 # `allauth` needs this
  88.                 "django.template.context_processors.request",
  89.             ],
  90.         },
  91.     },
  92. ]
  93.  
  94. WSGI_APPLICATION = "project.wsgi.application"
  95.  
  96. # Database section
  97.  
  98. # Password validation
  99. # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
  100.  
  101. AUTH_PASSWORD_VALIDATORS = [
  102.     {
  103.         "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  104.     },
  105.     {
  106.         "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  107.     },
  108.     {
  109.         "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
  110.     },
  111.     {
  112.         "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
  113.     },
  114. ]
  115.  
  116.  
  117. # Internationalization
  118. # https://docs.djangoproject.com/en/4.2/topics/i18n/
  119.  
  120. LANGUAGE_CODE = "en-us"
  121.  
  122. TIME_ZONE = "UTC"
  123.  
  124. USE_I18N = True
  125.  
  126. USE_TZ = True
  127.  
  128. DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
  129.  
  130. SPECTACULAR_SETTINGS = {
  131.     "TITLE": "Eve-Connect Backend",
  132. }
  133.  
  134. SITE_ID = 1
  135.  
  136. AUTHENTICATION_BACKENDS = [
  137.     # Needed to login by username in Django admin, regardless of `allauth`
  138.     "django.contrib.auth.backends.ModelBackend",
  139.     # `allauth` specific authentication methods, such as login by e-mail
  140.     "allauth.account.auth_backends.AuthenticationBackend",
  141. ]
  142.  
  143. EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
  144.  
  145. ACCOUNT_USERNAME_REQUIRED = False
  146. ACCOUNT_AUTHENTICATION_METHOD = "email"
  147. ACCOUNT_EMAIL_REQUIRED = True
  148. ACCOUNT_UNIQUE_EMAIL = True
  149.  
  150. SOCIALACCOUNT_PROVIDERS = {
  151.     "google": {
  152.         "SCOPE": [
  153.             "profile",
  154.             "email",
  155.         ],
  156.         "AUTH_PARAMS": {
  157.             "access_type": "online",
  158.         },
  159.         "OAUTH_PKCE_ENABLED": True,
  160.     },
  161.     "facebook": {
  162.         "METHOD": "oauth2",
  163.         "SDK_URL": "//connect.facebook.net/{locale}/sdk.js",
  164.         "SCOPE": ["email", "public_profile"],
  165.         "AUTH_PARAMS": {"auth_type": "reauthenticate"},
  166.         "INIT_PARAMS": {"cookie": True},
  167.         "FIELDS": [
  168.             "id",
  169.             "first_name",
  170.             "last_name",
  171.             "middle_name",
  172.             "name",
  173.             "name_format",
  174.             "picture",
  175.             "short_name",
  176.         ],
  177.         "EXCHANGE_TOKEN": True,
  178.         "VERIFIED_EMAIL": False,
  179.         "VERSION": "v13.0",
  180.         "GRAPH_API_URL": "https://graph.facebook.com/v13.0",
  181.     },
  182. }
  183.  
  184. STATIC_URL = "static/"
  185. STATIC_FILES_DIRS = [os.path.join(BASE_DIR, "static")]
  186. STATIC_ROOT = os.path.join(BASE_DIR, "staticroot")
  187.  
Advertisement
Add Comment
Please, Sign In to add comment