· 4 years ago · Mar 06, 2021, 07:40 AM
1
2import os
3from datetime import timedelta
4
5import environ
6
7env = environ.Env(DEBUG=(bool, False))
8
9# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
10BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
11
12# Quick-start development settings - unsuitable for production
13# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
14
15# SECURITY WARNING: keep the secret key used in production secret!
16SECRET_KEY = env('SECRET_KEY')
17
18# SECURITY WARNING: don't run with debug turned on in production!
19DEBUG = env('DEBUG')
20
21ALLOWED_HOSTS = env('ALLOWED_HOSTS', default='*').split(',')
22
23# Application definition
24
25INSTALLED_APPS = [
26 'django.contrib.admin',
27 'django.contrib.auth',
28 'django.contrib.contenttypes',
29 'django.contrib.sessions',
30 'django.contrib.messages',
31 'django.contrib.staticfiles',
32
33 'rest_framework',
34 'corsheaders',
35 'dbbackup',
36 'graphene_django',
37 'django_filters',
38
39 'user_accounts',
40 'accounts',
41 'expenses',
42]
43
44MIDDLEWARE = [
45 'corsheaders.middleware.CorsMiddleware',
46 'django.middleware.security.SecurityMiddleware',
47 'whitenoise.middleware.WhiteNoiseMiddleware' if not DEBUG else None,
48 'django.contrib.sessions.middleware.SessionMiddleware',
49 'django.middleware.common.CommonMiddleware',
50 'django.middleware.csrf.CsrfViewMiddleware',
51 'django.contrib.auth.middleware.AuthenticationMiddleware',
52 'django.contrib.messages.middleware.MessageMiddleware',
53 'django.middleware.clickjacking.XFrameOptionsMiddleware',
54]
55MIDDLEWARE = list(filter(None, MIDDLEWARE))
56
57ROOT_URLCONF = 'backend.urls'
58
59TEMPLATES = [
60 {
61 'BACKEND': 'django.template.backends.django.DjangoTemplates',
62 'DIRS': [],
63 'APP_DIRS': True,
64 'OPTIONS': {
65 'context_processors': [
66 'django.template.context_processors.debug',
67 'django.template.context_processors.request',
68 'django.contrib.auth.context_processors.auth',
69 'django.contrib.messages.context_processors.messages',
70 ],
71 },
72 },
73]
74
75WSGI_APPLICATION = 'backend.wsgi.application'
76
77# Database
78# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
79
80DATABASES = {
81 'default': env.db('DB_URL')
82}
83
84# Password validation
85# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
86
87AUTH_PASSWORD_VALIDATORS = [
88 {
89 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
90 },
91 {
92 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
93 },
94 {
95 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
96 },
97 {
98 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
99 },
100]
101
102# Internationalization
103# https://docs.djangoproject.com/en/3.0/topics/i18n/
104
105LANGUAGE_CODE = 'en-us'
106
107TIME_ZONE = 'UTC'
108
109USE_I18N = True
110
111USE_L10N = True
112
113USE_TZ = True
114
115# Static files (CSS, JavaScript, Images)
116# https://docs.djangoproject.com/en/3.0/howto/static-files/
117
118STATIC_URL = '/app/'
119STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
120# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
121
122REST_FRAMEWORK = {
123 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
124 'PAGE_SIZE': 10,
125 'DEFAULT_RENDERER_CLASSES': ['rest_framework.renderers.JSONRenderer'],
126 'DEFAULT_PERMISSION_CLASSES': (
127 'rest_framework.permissions.IsAdminUser',
128 ),
129 'DEFAULT_AUTHENTICATION_CLASSES': (
130 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
131 )
132}
133
134AUTHENTICATION_BACKENDS = [
135 'graphql_jwt.backends.JSONWebTokenBackend',
136 'django.contrib.auth.backends.ModelBackend',
137]
138
139JWT_AUTH = {
140 'JWT_EXPIRATION_DELTA': timedelta(days=1)
141}
142
143if DEBUG:
144 CORS_ORIGIN_ALLOW_ALL = True
145else:
146 CORS_ORIGIN_WHITELIST = env('CORS_ALLOW', default='').split(',')
147
148if DEBUG:
149 DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
150 DBBACKUP_STORAGE_OPTIONS = {'location': './.backups'}
151else:
152 DBBACKUP_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
153 DBBACKUP_STORAGE_OPTIONS = {
154 'access_key': env('SCALEWAY_ACCESS_KEY'),
155 'secret_key': env('SCALEWAY_SECRET_KEY'),
156 'bucket_name': env('SCALEWAY_BUCKET'),
157 'region_name': env('SCALEWAY_REGION'),
158 'endpoint_url': env('SCALEWAY_ENDPOINT_URL')
159 }
160
161GRAPHENE = {
162 "SCHEMA": "backend.schema.schema",
163 'MIDDLEWARE': [
164 'graphql_jwt.middleware.JSONWebTokenMiddleware',
165 ],
166 'RELAY_CONNECTION_MAX_LIMIT': 1000,
167}
168