Fakultas Ilmu Komputer UI

settings.py 5.19 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",
Samuel Dimas's avatar
Samuel Dimas committed
53
54
55
]

MIDDLEWARE = [
56
57
58
59
60
61
62
63
64
    "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
65
66
]

67
68
SESSION_SAVE_EVERY_REQUEST = True

69
ROOT_URLCONF = "digipus.urls"
Samuel Dimas's avatar
Samuel Dimas committed
70
71
72

TEMPLATES = [
    {
73
74
75
76
77
78
79
80
81
        "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",
Samuel Dimas's avatar
Samuel Dimas committed
82
83
84
85
86
            ],
        },
    },
]

87
WSGI_APPLICATION = "digipus.wsgi.application"
Samuel Dimas's avatar
Samuel Dimas committed
88
89
90
91


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

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

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

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

126
AUTH_USER_MODEL = "authentication.User"
127

Samuel Dimas's avatar
Samuel Dimas committed
128
AUTH_PASSWORD_VALIDATORS = [
129
130
131
132
    {"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", },
Samuel Dimas's avatar
Samuel Dimas committed
133
134
135
136
137
138
]


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

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

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

USE_I18N = True

USE_L10N = True

USE_TZ = True

149
150
151
152
153
154
155
156
157
158
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
159
160
161
162

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

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

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

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

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

LOGOUT_REDIRECT_URL = "/"
176
177

CRISPY_TEMPLATE_PACK = 'bootstrap4'