Fakultas Ilmu Komputer UI

settings.py 5.64 KB
Newer Older
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
1
2
3
4
5
6
7
8
9
10
11
12
"""
Django settings for pplbackend project.

Generated by 'django-admin startproject' using Django 3.0.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

13
import dj_database_url
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
14
15
16
17
18
19
20
21
22
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

23
#Security keys
24
SECRET_KEY = os.getenv('SECRET_KEY', 'akua')
25

26

Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
27
# SECURITY WARNING: don't run with debug turned on in production!
28
DEBUG = True
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
29

Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
30
ALLOWED_HOSTS = ['*']
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
31
32
33
34
35
36
37


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
38
    'django.contrib.sites',
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
39
40
41
42
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
43
    'django.contrib.auth.hashers',
44
    'registrasi',
45
    'informasi_fasilitas',
46
    'new_rest_api',
47
    'layanan_khusus',
48
49
50
51
52
53
54
55
56

    'rest_auth',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth.registration',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
57
    'multiselectfield',
58
    'oauth2_provider',
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'pplbackend.urls'

74
TEMPLATES_ROOT = os.path.join(BASE_DIR, "templates")
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
75
76
77
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
78
        'DIRS': [TEMPLATES_ROOT],
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        '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',
            ],
        },
    },
]

WSGI_APPLICATION = 'pplbackend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
Bayukanta Iqbal Gunawan's avatar
Bayukanta Iqbal Gunawan committed
99
100
101
102
103
104
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DB_NAME', 'postgres'),
        'USER': os.environ.get('DB_USER', 'postgres'),
        'PASSWORD': os.environ.get('DB_PASSWORD', 'postgres'),
        'HOST': os.environ.get('DB_HOST', 'localhost'),
        'PORT': os.environ.get('DB_PORT', '5432'),
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
105
106
107
    }
}

108
109
110
111
if os.environ.get("DATABASE_URL"):
    DATABASES['default'] = dj_database_url.config()


Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

# Password validation
# https://docs.djangoproject.com/en/3.0/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',
    },
]

131
132
133
134
135
136
# AUTH_USER_MODEL = 'registrasi.BisaGoUser'
# ACCOUNT_AUTHENTICATION_METHOD = 'email'
# ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_UNIQUE_EMAIL = True
# ACCOUNT_USER_MODEL_USERNAME_FIELD = None
# ACCOUNT_USERNAME_REQUIRED = False
137

Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
156
157
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
158
STATIC_URL = '/static/'
Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
159
160
161
162

STATIC_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
163
164
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#Rest API Settings
SITE_ID = 1

AUTHENTICATION_BACKENDS = [
    # Default backend -- used to login by username in Django admin
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",
]

ACCOUNT_DEFAULT_HTTP_PROTOCOL = "http"

SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}

LOGIN_REDIRECT_URL = '/'
REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
192
193
194
195
    'PAGE_SIZE': 10,
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
196
        'rest_framework.authentication.TokenAuthentication',
197
198
199
200
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],
201
}
202
203
204
205
206
207
208

PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.Argon2PasswordHasher',
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]
209
210
211
212
213
214

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
EMAIL_PORT = 587