Fakultas Ilmu Komputer UI

settings.py 5.67 KB
Newer Older
Samuel Dimas's avatar
Samuel Dimas committed
1
2
3
4
5
6
7
8
9
10
11
12
"""
Django settings for digipus project.

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

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
14
import os

Putu Agastya's avatar
Putu Agastya committed
15
import dj_database_url
16
from decouple import config
17
from django.contrib.messages import constants as messages
Samuel Dimas's avatar
Samuel Dimas committed
18
19
20
21
22
23
24
25
26

# 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/

# SECURITY WARNING: keep the secret key used in production secret!
27
SECRET_KEY = config("SECRET_KEY")
Samuel Dimas's avatar
Samuel Dimas committed
28
29

# SECURITY WARNING: don't run with debug turned on in production!
30
DEBUG = config("DEBUG", cast=bool)
Samuel Dimas's avatar
Samuel Dimas committed
31

32
ALLOWED_HOSTS = ["*"]
Samuel Dimas's avatar
Samuel Dimas committed
33
34
35
36
37


# Application definition

INSTALLED_APPS = [
38
39
40
41
42
43
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
44
    'django.contrib.humanize',
45
46
47
48
    "authentication.apps.AuthenticationConfig",
    "app.apps.AppConfig",
    "register.apps.RegisterConfig",
    "administration.apps.AdministrationConfig",
49
    'crispy_forms',
50
    "news.apps.NewsConfig",
51
    "traffic_statistics",
Azhar Rais's avatar
Azhar Rais committed
52
    "forum",
53
    "rest_framework",
54
    'userguide'
Samuel Dimas's avatar
Samuel Dimas committed
55
56
57
]

MIDDLEWARE = [
58
59
60
61
62
63
64
65
66
    "django.middleware.security.SecurityMiddleware",
    "whitenoise.middleware.WhiteNoiseMiddleware",
    "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",
Samuel Dimas's avatar
Samuel Dimas committed
67
68
]

69
70
SESSION_SAVE_EVERY_REQUEST = True

71
ROOT_URLCONF = "digipus.urls"
Samuel Dimas's avatar
Samuel Dimas committed
72
73
74

TEMPLATES = [
    {
75
76
77
78
79
80
81
82
83
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [os.path.join(BASE_DIR, "templates")],
        "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",
84
85
                
                "authentication.views.kontributor_notif_context"
Samuel Dimas's avatar
Samuel Dimas committed
86
87
88
89
90
            ],
        },
    },
]

91
WSGI_APPLICATION = "digipus.wsgi.application"
Samuel Dimas's avatar
Samuel Dimas committed
92
93
94
95


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
96
97
is_local = config("IS_LOCAL", cast=bool, default=False)
is_heroku = config("IS_HEROKU", cast=bool, default=False)
98
is_gitlab = config("IS_GITLAB", cast=bool, default=False)
Putu Agastya's avatar
Putu Agastya committed
99
100
101

if is_local:
    DATABASES = {
102
103
104
105
106
107
        "default": {
            "ENGINE": "django.db.backends.postgresql",
            "NAME": config("DB_NAME"),
            "USER": config("DB_USER"),
            "PASSWORD": config("DB_PASSWORD"),
            "HOST": config("DB_HOST"),
108
            "PORT": config("DB_PORT", 5432),
Putu Agastya's avatar
Putu Agastya committed
109
        }
Samuel Dimas's avatar
Samuel Dimas committed
110
    }
Putu Agastya's avatar
Putu Agastya committed
111
elif is_heroku:
112
    DATABASES = {}
Putu Agastya's avatar
Putu Agastya committed
113
    database_url = os.getenv("DATABASE_URL")
114
115
    DATABASES["default"] = dj_database_url.parse(
        database_url, conn_max_age=600)
116
117
118
elif is_gitlab:
    DATABASES = {}
    database_url = config("DATABASE_URL", cast=str, default=False)
119
120
    DATABASES["default"] = dj_database_url.parse(
        database_url, conn_max_age=600)
Putu Agastya's avatar
Putu Agastya committed
121
else:
122
123
    DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3",
                             "NAME": os.path.join(BASE_DIR, "db.sqlite3"), }}
Samuel Dimas's avatar
Samuel Dimas committed
124

125
STATICFILES_DIRS = (os.path.join(BASE_DIR, "staticfiles"),)
Putu Agastya's avatar
Putu Agastya committed
126

Samuel Dimas's avatar
Samuel Dimas committed
127
128
129
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

130
AUTH_USER_MODEL = "authentication.User"
131

Samuel Dimas's avatar
Samuel Dimas committed
132
AUTH_PASSWORD_VALIDATORS = [
133
    {"NAME": "app.utils.PasswordValidator.PasswordPolicyValidator", },
Samuel Dimas's avatar
Samuel Dimas committed
134
135
136
137
138
139
]


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

140
LANGUAGE_CODE = "en-us"
Samuel Dimas's avatar
Samuel Dimas committed
141

142
TIME_ZONE = "Asia/Jakarta"
Samuel Dimas's avatar
Samuel Dimas committed
143
144
145
146
147
148
149

USE_I18N = True

USE_L10N = True

USE_TZ = True

150
151
152
153
154
155
156
157
158
159
MESSAGE_TAGS = {
    messages.DEBUG: 'alert-info',
    messages.INFO: 'alert-info',
    messages.SUCCESS: 'alert-success',
    messages.WARNING: 'alert-warning',
    messages.ERROR: 'alert-danger',
}

GOOGLE_RECAPTCHA_SECRET_KEY = config('GOOGLE_RECHAPTCHA', default= "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe")
GOOGLE_RECAPTCHA_SITE_KEY = config('CLIENT_RECHAPTCHA', default= "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI")
Samuel Dimas's avatar
Samuel Dimas committed
160
161
162
163

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

164
STATIC_ROOT = os.path.join(BASE_DIR, "static")
Putu Agastya's avatar
Putu Agastya committed
165

166
STATIC_URL = "/static/"
Putu Agastya's avatar
Putu Agastya committed
167

Putu Agastya's avatar
Putu Agastya committed
168
STATIC_DIRS = [
169
    os.path.join(BASE_DIR, "static"),
Putu Agastya's avatar
Putu Agastya committed
170
]
171
172
173
174
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
175
176

LOGOUT_REDIRECT_URL = "/"
177
178

CRISPY_TEMPLATE_PACK = 'bootstrap4'
179
180
181
182
183

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
184
185
186
187
188
189
190
191
192
193
194
}

# Mail
# https://docs.djangoproject.com/en/3.1/topics/email/

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = config('EMAIL_HOST', default='smtp.gmail.com') # use Google Mail SMTP as default
EMAIL_PORT = config('EMAIL_PORT', default=587) # use Google Mail SMTP as default
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default="pmplclass2020@gmail.com")
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default="pmpldigipusemail")
EMAIL_USE_TLS = True
195
EMAIL_USE_SSL = False