|
| 1 | +""" |
| 2 | +Django settings for onestop project. |
| 3 | +
|
| 4 | +Generated by 'django-admin startproject' using Django 3.1.1. |
| 5 | +
|
| 6 | +For more information on this file, see |
| 7 | +https://docs.djangoproject.com/en/3.1/topics/settings/ |
| 8 | +
|
| 9 | +For the full list of settings and their values, see |
| 10 | +https://docs.djangoproject.com/en/3.1/ref/settings/ |
| 11 | +""" |
| 12 | + |
| 13 | +import os |
| 14 | +from pathlib import Path |
| 15 | + |
| 16 | +from decouple import config |
| 17 | + |
| 18 | +# Added from https://simpleisbetterthancomplex.com/tips/2016/09/06/django-tip-14-messages-framework.html |
| 19 | +from django.contrib.messages import constants as messages |
| 20 | + |
| 21 | + |
| 22 | +# Build paths inside the project like this: BASE_DIR / 'subdir'. |
| 23 | +BASE_DIR = Path(__file__).resolve().parent.parent |
| 24 | +TEMPLATE_DIR = os.path.join(BASE_DIR, "templates") |
| 25 | + |
| 26 | +# Static files (CSS, JavaScript, Images) |
| 27 | +# https://docs.djangoproject.com/en/3.1/howto/static-files/ |
| 28 | + |
| 29 | +# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' |
| 30 | + |
| 31 | +STATIC_URL = "/static/" |
| 32 | +# Where static files will be collected (by manage.py collectstatic) during deployment |
| 33 | +STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") |
| 34 | + |
| 35 | +# Location of static files |
| 36 | +STATICFILES_DIRS = [ |
| 37 | + os.path.join(BASE_DIR, "static"), |
| 38 | +] # A list of directories with statics files, usually out of the default search path of Django |
| 39 | + |
| 40 | + |
| 41 | +# Base url to serve media files |
| 42 | +MEDIA_URL = "/media/" |
| 43 | + |
| 44 | +# Path where media is stored |
| 45 | +MEDIA_ROOT = os.path.join(BASE_DIR, "media") |
| 46 | + |
| 47 | +# Quick-start development settings - unsuitable for production |
| 48 | +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ |
| 49 | + |
| 50 | +# SECURITY WARNING: keep the secret key used in production secret! |
| 51 | +SECRET_KEY = config("SECRET_KEY") |
| 52 | +GOOGLE_RECAPTCHA_SECRET_KEY = config("GOOGLE_RECAPTCHA_SECRET_KEY") |
| 53 | + |
| 54 | +# SECURITY WARNING: don't run with debug turned on in production! |
| 55 | +DEBUG = config('DEBUG', default=False, cast=bool) |
| 56 | + |
| 57 | +ALLOWED_HOSTS = ["localhost", "127.0.0.1"] |
| 58 | +INTERNAL_IPS = [ |
| 59 | + "127.0.0.1", |
| 60 | +] |
| 61 | + |
| 62 | +if DEBUG: |
| 63 | + import socket # only if you haven't already imported this |
| 64 | + hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) |
| 65 | + INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"] |
| 66 | + |
| 67 | + |
| 68 | +# Application definition |
| 69 | + |
| 70 | +INSTALLED_APPS = [ |
| 71 | + # 'whitenoise.runserver_nostatic', |
| 72 | + 'jazzmin', |
| 73 | + "django.contrib.admin", |
| 74 | + "django.contrib.auth", |
| 75 | + "django.contrib.contenttypes", |
| 76 | + "django.contrib.sessions", |
| 77 | + "django.contrib.messages", |
| 78 | + "django.contrib.staticfiles", |
| 79 | + "users.apps.UsersConfig", |
| 80 | + "store.apps.StoreConfig", |
| 81 | + "dictionary", |
| 82 | + "simple_history", |
| 83 | + "django_comments_xtd", |
| 84 | + "django_comments", |
| 85 | + "blog", |
| 86 | + "equeue", |
| 87 | + "translation", |
| 88 | + "django.contrib.sites", |
| 89 | + "django_summernote", |
| 90 | + "django_extensions", |
| 91 | + "rest_framework", |
| 92 | + "django_social_share", |
| 93 | + "debug_toolbar", |
| 94 | +] |
| 95 | + |
| 96 | +MIDDLEWARE = [ |
| 97 | + "debug_toolbar.middleware.DebugToolbarMiddleware", |
| 98 | + "django.middleware.security.SecurityMiddleware", |
| 99 | + "whitenoise.middleware.WhiteNoiseMiddleware", |
| 100 | + "django.contrib.sessions.middleware.SessionMiddleware", |
| 101 | + "django.middleware.common.CommonMiddleware", |
| 102 | + "django.middleware.csrf.CsrfViewMiddleware", |
| 103 | + "django.contrib.auth.middleware.AuthenticationMiddleware", |
| 104 | + "django.contrib.messages.middleware.MessageMiddleware", |
| 105 | + "django.middleware.clickjacking.XFrameOptionsMiddleware", |
| 106 | + # 'audit_log.middleware.UserLoggingMiddleware', |
| 107 | + "simple_history.middleware.HistoryRequestMiddleware", |
| 108 | +] |
| 109 | + |
| 110 | +ROOT_URLCONF = "onestop.urls" |
| 111 | + |
| 112 | +TEMPLATES = [ |
| 113 | + { |
| 114 | + "BACKEND": "django.template.backends.django.DjangoTemplates", |
| 115 | + # 'DIRS': [BASE_DIR / 'templates'], |
| 116 | + "DIRS": [TEMPLATE_DIR, os.path.join(BASE_DIR, "templates/onestop")], |
| 117 | + "APP_DIRS": True, |
| 118 | + "OPTIONS": { |
| 119 | + "context_processors": [ |
| 120 | + "django.template.context_processors.debug", |
| 121 | + "django.template.context_processors.request", |
| 122 | + "django.contrib.auth.context_processors.auth", |
| 123 | + "django.contrib.messages.context_processors.messages", |
| 124 | + ], |
| 125 | + }, |
| 126 | + }, |
| 127 | +] |
| 128 | + |
| 129 | +WSGI_APPLICATION = "onestop.wsgi.application" |
| 130 | + |
| 131 | + |
| 132 | +# Database |
| 133 | +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases |
| 134 | + |
| 135 | +# DATABASES = { |
| 136 | +# 'default': { |
| 137 | +# 'ENGINE': 'django.db.backends.sqlite3', |
| 138 | +# 'NAME': BASE_DIR / 'db.sqlite3', |
| 139 | +# } |
| 140 | +# } |
| 141 | + |
| 142 | +DATABASES = { |
| 143 | + "default": { |
| 144 | + # 'ENGINE': 'mysql.connector.django', |
| 145 | + "ENGINE": "django.db.backends.mysql", |
| 146 | + "NAME": config("MYSQL_DATABASE"), |
| 147 | + "USER": config("MYSQL_USER"), |
| 148 | + "PASSWORD": config("MYSQL_PASSWORD"), |
| 149 | + "HOST": config("MYSQL_HOST", default='localhost'), |
| 150 | + "PORT": config("MYSQL_PORT", default=3306, cast=int), |
| 151 | + "OPTIONS": { |
| 152 | + # "init_command": "SET sql_mode='STRICT_TRANS_TABLES'", |
| 153 | + "charset": "utf8mb4", |
| 154 | + }, |
| 155 | + # 'OPTIONS': {'charset': 'utf8mb4',}, |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | + |
| 160 | +# Password validation |
| 161 | +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators |
| 162 | + |
| 163 | +AUTH_PASSWORD_VALIDATORS = [ |
| 164 | + { |
| 165 | + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", |
| 166 | + }, |
| 167 | + { |
| 168 | + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", |
| 169 | + }, |
| 170 | + { |
| 171 | + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", |
| 172 | + }, |
| 173 | + { |
| 174 | + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", |
| 175 | + }, |
| 176 | +] |
| 177 | + |
| 178 | + |
| 179 | +# Internationalization |
| 180 | +# https://docs.djangoproject.com/en/3.1/topics/i18n/ |
| 181 | + |
| 182 | +LANGUAGE_CODE = "en-us" |
| 183 | + |
| 184 | +TIME_ZONE = "UTC" |
| 185 | + |
| 186 | +USE_I18N = True |
| 187 | + |
| 188 | +USE_L10N = True |
| 189 | + |
| 190 | +USE_TZ = True |
| 191 | + |
| 192 | + |
| 193 | +# Added from https://simpleisbetterthancomplex.com/tips/2016/09/06/django-tip-14-messages-framework.html |
| 194 | +# Changes the default string representation (message tags) of messages to Bootstrap classes |
| 195 | +MESSAGE_TAGS = { |
| 196 | + messages.DEBUG: "alert-info", |
| 197 | + messages.INFO: "alert-info", |
| 198 | + messages.SUCCESS: "alert-success", |
| 199 | + messages.WARNING: "alert-warning", |
| 200 | + messages.ERROR: "alert-danger", |
| 201 | +} |
| 202 | + |
| 203 | +# https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys |
| 204 | +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" |
| 205 | +LOGIN_REDIRECT_URL = "/" |
| 206 | + |
| 207 | +# Either enable sending mail messages to the console: |
| 208 | +# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' |
| 209 | + |
| 210 | +EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" |
| 211 | +EMAIL_HOST = config("_EMAIL_HOST") |
| 212 | +EMAIL_USE_SSL = True |
| 213 | +EMAIL_PORT = 465 |
| 214 | +EMAIL_HOST_USER = config("_EMAIL_HOST_USER") |
| 215 | +EMAIL_HOST_PASSWORD = config("_EMAIL_HOST_PASSWORD") |
| 216 | +DEFAULT_FROM_EMAIL = "Oshinglish Admin <[email protected]>" |
| 217 | + |
| 218 | +X_FRAME_OPTIONS = "SAMEORIGIN" |
| 219 | +SUMMERNOTE_THEME = "bs4" # Show summernote with Bootstrap4 |
| 220 | +COMMENTS_APP = "django_comments_xtd" |
| 221 | +SITE_ID = 1 |
| 222 | +COMMENTS_XTD_MAX_THREAD_LEVEL = 0 # site wide default |
| 223 | +COMMENTS_XTD_MAX_THREAD_LEVEL_BY_APP_MODEL = { |
| 224 | + # Objects of the app blog, model post, can be nested |
| 225 | + # up to thread level 1. |
| 226 | + "blog.post": 3, |
| 227 | +} |
| 228 | +# COMMENTS_XTD_LIST_ORDER = ('thread_id', 'order') |
| 229 | +COMMENTS_XTD_CONFIRM_EMAIL = True |
| 230 | +# To help obfuscating comments before they are sent for confirmation. |
| 231 | +COMMENTS_XTD_SALT = b"Timendi causa est nescire. " b"Aequam memento rebus in arduis servare mentem." |
| 232 | + |
| 233 | +# Source mail address used for notifications. |
| 234 | +COMMENTS_XTD_FROM_EMAIL = "[email protected]" |
| 235 | + |
| 236 | +# Contact mail address to show in messages. |
| 237 | +COMMENTS_XTD_CONTACT_EMAIL = "[email protected]" |
| 238 | +COMMENTS_XTD_APP_MODEL_OPTIONS = { |
| 239 | + "blog.post": { |
| 240 | + "allow_flagging": True, |
| 241 | + "allow_feedback": True, |
| 242 | + "show_feedback": True, |
| 243 | + "who_can_post": "all", # Valid values: 'all', users' |
| 244 | + } |
| 245 | +} |
| 246 | +DJANGORESIZED_DEFAULT_SIZE = [700, 500] |
| 247 | + |
| 248 | +JAZZMIN_SETTINGS = { |
| 249 | + # "site_title": "Oshinglish Admin", |
| 250 | + "site_brand": "Oshinglish Admin", |
| 251 | + "show_ui_builder":True, |
| 252 | + "site_logo": "images/favicon.ico", |
| 253 | + "login_logo": "images/favicon.ico", |
| 254 | + # "user_avatar": "user.profile.image.url" |
| 255 | + } |
| 256 | + |
| 257 | +JAZZMIN_UI_TWEAKS = { |
| 258 | + "navbar_small_text": False, |
| 259 | + "footer_small_text": False, |
| 260 | + "body_small_text": False, |
| 261 | + "brand_small_text": False, |
| 262 | + "brand_colour": False, |
| 263 | + "accent": "accent-primary", |
| 264 | + "navbar": "navbar-white navbar-light", |
| 265 | + "no_navbar_border": False, |
| 266 | + "navbar_fixed": False, |
| 267 | + "layout_boxed": False, |
| 268 | + "footer_fixed": False, |
| 269 | + "sidebar_fixed": False, |
| 270 | + "sidebar": "sidebar-dark-primary", |
| 271 | + "sidebar_nav_small_text": False, |
| 272 | + "sidebar_disable_expand": False, |
| 273 | + "sidebar_nav_child_indent": False, |
| 274 | + "sidebar_nav_compact_style": False, |
| 275 | + "sidebar_nav_legacy_style": False, |
| 276 | + "sidebar_nav_flat_style": False, |
| 277 | + "theme": "united", |
| 278 | + "dark_mode_theme": None, |
| 279 | + "button_classes": { |
| 280 | + "primary": "btn-outline-primary", |
| 281 | + "secondary": "btn-outline-secondary", |
| 282 | + "info": "btn-outline-info", |
| 283 | + "warning": "btn-outline-warning", |
| 284 | + "danger": "btn-outline-danger", |
| 285 | + "success": "btn-outline-success" |
| 286 | + } |
| 287 | +} |
| 288 | + |
| 289 | +# MANAGERS = ( |
| 290 | +# ('Oshinglish Blog', '[email protected]'), |
| 291 | +# ) |
| 292 | + |
| 293 | +# https://docs.djangoproject.com/en/4.0/topics/logging/#django.utils.log.AdminEmailHandler |
| 294 | +# LOGGING = { |
| 295 | +# 'version': 1, |
| 296 | +# 'disable_existing_loggers': False, |
| 297 | +# 'formatters': { |
| 298 | +# 'verbose': { |
| 299 | +# 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}', |
| 300 | +# 'style': '{', |
| 301 | +# }, |
| 302 | +# 'simple': { |
| 303 | +# 'format': '{levelname} {message}', |
| 304 | +# 'style': '{', |
| 305 | +# }, |
| 306 | +# }, |
| 307 | +# 'filters': { |
| 308 | +# 'require_debug_false': { |
| 309 | +# '()': 'django.utils.log.RequireDebugFalse', |
| 310 | +# }, |
| 311 | +# }, |
| 312 | +# 'handlers': { |
| 313 | +# 'file': { |
| 314 | +# 'level': 'INFO', |
| 315 | +# # 'filters': ['require_debug_false'], |
| 316 | +# 'class': 'logging.FileHandler', |
| 317 | +# 'filename': f'{BASE_DIR}/onestop/debug.log', |
| 318 | +# 'formatter': 'verbose' |
| 319 | +# }, |
| 320 | +# 'mail_admins': { |
| 321 | +# 'level': 'ERROR', |
| 322 | +# 'class': 'django.utils.log.AdminEmailHandler', |
| 323 | +# # 'filters': ['special'] |
| 324 | +# } |
| 325 | +# }, |
| 326 | +# 'loggers': { |
| 327 | +# 'django': { |
| 328 | +# 'handlers': ['file'], |
| 329 | +# 'propagate': True, |
| 330 | +# }, |
| 331 | +# 'django.request': { |
| 332 | +# 'handlers': ['mail_admins'], |
| 333 | +# 'level': 'ERROR', |
| 334 | +# 'propagate': False, |
| 335 | +# } |
| 336 | +# } |
| 337 | +# } |
0 commit comments