Bartosz Stebel | f5b1a21 | 2023-02-04 23:47:44 +0100 | [diff] [blame] | 1 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
| 2 | import os |
| 3 | from django.contrib.messages import constants as messages |
| 4 | from pathlib import Path |
| 5 | |
| 6 | #: The base directory for logs and database. |
| 7 | BASE_DIR = Path('/opt/mailman/web') |
| 8 | |
| 9 | #: Default list of admins who receive the emails from error logging. |
| 10 | ADMINS = ( |
| 11 | ('Mailman Suite Admin', 'root@localhost'), |
| 12 | ) |
| 13 | |
| 14 | #: Hosts/domain names that are valid for this site; required if DEBUG is False. |
| 15 | #: See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts |
| 16 | ALLOWED_HOSTS = [ |
| 17 | "localhost", # Archiving API from Mailman, keep it. |
| 18 | # "lists.your-domain.org", |
| 19 | # Add here all production URLs you may have. |
| 20 | ] |
| 21 | |
| 22 | #: Enable Development Mode. |
| 23 | DEBUG = False |
| 24 | |
| 25 | |
| 26 | #: URL Configuration for Django |
| 27 | ROOT_URLCONF = 'mailman_web.urls' |
| 28 | |
| 29 | |
| 30 | #: Default list of django applications. |
| 31 | #: Each social account provider is an application and by default no social auth |
| 32 | #: providers are enabled. To enable a social auth provider, you can add them |
| 33 | #: to list of INSTALLED_APPS. For example:: |
| 34 | #: |
| 35 | #: DJANGO_SOCIAL_AUTH_PROVIDERS = [ |
| 36 | #: 'allauth.socialaccount.providers.openid', |
| 37 | #: 'django_mailman3.lib.auth.fedora', |
| 38 | #: 'allauth.socialaccount.providers.github', |
| 39 | #: 'allauth.socialaccount.providers.gitlab', |
| 40 | #: 'allauth.socialaccount.providers.google', |
| 41 | #: 'allauth.socialaccount.providers.facebook', |
| 42 | #: 'allauth.socialaccount.providers.twitter', |
| 43 | #: 'allauth.socialaccount.providers.stackexchange', |
| 44 | #: ] |
| 45 | #: INSTALLED_APPS += DJANGO_SOCIAL_AUTH_PROVIDERS |
| 46 | #: |
| 47 | #: A full list of providers can be found at |
| 48 | #: https://django-allauth.readthedocs.io/en/latest/providers.html |
| 49 | #: Please also note that extra configuration is required after |
| 50 | #: a provider is enabled. Django-allauth's documentation mentioned |
| 51 | #: above provides more details about how to configure one. |
| 52 | INSTALLED_APPS = [ |
| 53 | 'hyperkitty', |
| 54 | 'postorius', |
| 55 | 'django_mailman3', |
| 56 | 'django.contrib.admin', |
| 57 | 'django.contrib.auth', |
| 58 | 'django.contrib.contenttypes', |
| 59 | 'django.contrib.sessions', |
| 60 | 'django.contrib.sites', |
| 61 | 'django.contrib.messages', |
| 62 | 'django.contrib.staticfiles', |
| 63 | 'rest_framework', |
| 64 | 'django_gravatar', |
| 65 | 'compressor', |
| 66 | 'haystack', |
| 67 | 'django_extensions', |
| 68 | 'django_q', |
| 69 | 'allauth', |
| 70 | 'allauth.account', |
| 71 | 'allauth.socialaccount', |
| 72 | ] |
| 73 | |
| 74 | |
| 75 | #: Default Django Middlewares. |
| 76 | MIDDLEWARE = ( |
| 77 | 'django.contrib.sessions.middleware.SessionMiddleware', |
| 78 | 'django.middleware.common.CommonMiddleware', |
| 79 | 'django.middleware.csrf.CsrfViewMiddleware', |
| 80 | 'django.middleware.locale.LocaleMiddleware', |
| 81 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 82 | 'django.contrib.messages.middleware.MessageMiddleware', |
| 83 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 84 | 'django.middleware.security.SecurityMiddleware', |
| 85 | 'django_mailman3.middleware.TimezoneMiddleware', |
| 86 | 'postorius.middleware.PostoriusMiddleware', |
| 87 | ) |
| 88 | |
| 89 | #: Default Template finders. |
| 90 | TEMPLATES = [ |
| 91 | { |
| 92 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 93 | 'DIRS': [], |
| 94 | 'APP_DIRS': True, |
| 95 | 'OPTIONS': { |
| 96 | 'context_processors': [ |
| 97 | 'django.template.context_processors.debug', |
| 98 | 'django.template.context_processors.i18n', |
| 99 | 'django.template.context_processors.media', |
| 100 | 'django.template.context_processors.static', |
| 101 | 'django.template.context_processors.tz', |
| 102 | 'django.template.context_processors.csrf', |
| 103 | 'django.template.context_processors.request', |
| 104 | 'django.contrib.auth.context_processors.auth', |
| 105 | 'django.contrib.messages.context_processors.messages', |
| 106 | 'django_mailman3.context_processors.common', |
| 107 | 'hyperkitty.context_processors.common', |
| 108 | 'postorius.context_processors.postorius', |
| 109 | ], |
| 110 | }, |
| 111 | }, |
| 112 | ] |
| 113 | |
| 114 | #: Wsgi application import path. This will be used by the WSGI server which |
| 115 | #: will be used to deploy this application. |
| 116 | WSGI_APPLICATION = 'mailman_web.wsgi.application' |
| 117 | |
| 118 | #: Default Database to be used. |
| 119 | #: Example for PostgreSQL (**recommanded for production**):: |
| 120 | #: |
| 121 | #: 'default': { |
| 122 | #: 'ENGINE': 'django.db.backends.postgresql_psycopg2', |
| 123 | #: 'NAME': 'database_name', |
| 124 | #: 'USER': 'database_user', |
| 125 | #: 'PASSWORD': 'database_password', |
| 126 | #: 'HOST': 'localhost', |
| 127 | #: } |
| 128 | #: |
| 129 | #: For MySQL/MariaDB also add the following to the the configuration:: |
| 130 | #: |
| 131 | #: 'OPTIONS': {'charset': 'utf8mb4'} # Enable utf8 4-byte encodings. |
| 132 | #: |
| 133 | #: Check out |
| 134 | #: `Django documentation |
| 135 | #: <https://docs.djangoproject.com/en/3.0/ref/settings/#databases>`_ for |
| 136 | #: more details. |
| 137 | DATABASES = { |
| 138 | 'default': { |
| 139 | 'ENGINE': 'django.db.backends.sqlite3', |
| 140 | 'NAME': os.path.join(BASE_DIR, 'mailman-web.db'), |
| 141 | 'HOST': '', |
| 142 | 'PORT': '', |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | # Maintain type of autogenerated keys going forward |
| 147 | # https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys |
| 148 | DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' |
| 149 | |
| 150 | |
| 151 | #: Default password validators. |
| 152 | AUTH_PASSWORD_VALIDATORS = [ |
| 153 | { |
| 154 | 'NAME': |
| 155 | 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa: E501 |
| 156 | }, |
| 157 | { |
| 158 | 'NAME': |
| 159 | 'django.contrib.auth.password_validation.MinimumLengthValidator', |
| 160 | }, |
| 161 | { |
| 162 | 'NAME': |
| 163 | 'django.contrib.auth.password_validation.CommonPasswordValidator', |
| 164 | }, |
| 165 | { |
| 166 | 'NAME': |
| 167 | 'django.contrib.auth.password_validation.NumericPasswordValidator', |
| 168 | }, |
| 169 | ] |
| 170 | |
| 171 | #: Default Language code. |
| 172 | LANGUAGE_CODE = 'en-us' |
| 173 | |
| 174 | #: Default timezone. |
| 175 | TIME_ZONE = 'UTC' |
| 176 | |
| 177 | #: Enable internationalization. |
| 178 | USE_I18N = True |
| 179 | |
| 180 | #: Enable localization. |
| 181 | USE_L10N = True |
| 182 | |
| 183 | #: Use the timezone information. |
| 184 | USE_TZ = True |
| 185 | |
| 186 | |
| 187 | #: Default path where static files will be placed. |
| 188 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') |
| 189 | |
| 190 | #: URL prefix for static files. |
| 191 | #: Example: "http://example.com/static/", "http://static.example.com/" |
| 192 | STATIC_URL = '/static/' |
| 193 | |
| 194 | #: Additional locations of static files |
| 195 | STATICFILES_DIRS = ( |
| 196 | # Put strings here, like "/home/html/static" or "C:/www/django/static". |
| 197 | # Always use forward slashes, even on Windows. |
| 198 | # Don't forget to use absolute paths, not relative paths. |
| 199 | # BASE_DIR + '/static/', |
| 200 | ) |
| 201 | |
| 202 | #: List of finder classes that know how to find static files in |
| 203 | #: various locations. |
| 204 | STATICFILES_FINDERS = ( |
| 205 | 'django.contrib.staticfiles.finders.FileSystemFinder', |
| 206 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', |
| 207 | # 'django.contrib.staticfiles.finders.DefaultStorageFinder', |
| 208 | 'compressor.finders.CompressorFinder', |
| 209 | ) |
| 210 | |
| 211 | |
| 212 | #: Default Django URL to redirect to for Login. |
| 213 | LOGIN_URL = 'account_login' |
| 214 | #: Default Django URL to redirect to after a successful login. |
| 215 | LOGIN_REDIRECT_URL = 'list_index' |
| 216 | #: Default Django URL to Logout the user. |
| 217 | LOGOUT_URL = 'account_logout' |
| 218 | |
| 219 | #: If you enable email reporting for error messages, this is where those emails |
| 220 | #: will appear to be coming from. Make sure you set a valid domain name, |
| 221 | #: otherwise the emails may get rejected. |
| 222 | #: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SERVER_EMAIL |
| 223 | SERVER_EMAIL = 'root@localhost.local' |
| 224 | |
| 225 | #: The default implementation to send out emails. This can be customized to |
| 226 | #: something else for testing purposes. |
| 227 | #: https://docs.djangoproject.com/en/dev/topics/email/#email-backends |
| 228 | EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' |
| 229 | |
| 230 | MESSAGE_TAGS = { |
| 231 | messages.ERROR: 'danger' |
| 232 | } |
| 233 | |
| 234 | |
| 235 | #: Default Logging configuration. |
| 236 | LOGGING = { |
| 237 | 'version': 1, |
| 238 | 'disable_existing_loggers': False, |
| 239 | 'filters': { |
| 240 | 'require_debug_false': { |
| 241 | '()': 'django.utils.log.RequireDebugFalse' |
| 242 | } |
| 243 | }, |
| 244 | 'handlers': { |
| 245 | 'mail_admins': { |
| 246 | 'level': 'ERROR', |
| 247 | 'filters': ['require_debug_false'], |
| 248 | 'class': 'django.utils.log.AdminEmailHandler' |
| 249 | }, |
| 250 | 'file': { |
| 251 | 'level': 'INFO', |
| 252 | 'class': 'logging.handlers.WatchedFileHandler', |
| 253 | 'filename': os.path.join(BASE_DIR, 'logs', 'mailmanweb.log'), |
| 254 | 'formatter': 'verbose', |
| 255 | }, |
| 256 | 'console': { |
| 257 | 'class': 'logging.StreamHandler', |
| 258 | 'formatter': 'simple', |
| 259 | }, |
| 260 | }, |
| 261 | 'loggers': { |
| 262 | 'django.request': { |
| 263 | 'handlers': ['mail_admins', 'file'], |
| 264 | 'level': 'ERROR', |
| 265 | 'propagate': True, |
| 266 | }, |
| 267 | 'django': { |
| 268 | 'handlers': ['file'], |
| 269 | 'level': 'ERROR', |
| 270 | 'propagate': True, |
| 271 | }, |
| 272 | 'hyperkitty': { |
| 273 | 'handlers': ['file'], |
| 274 | 'level': 'DEBUG', |
| 275 | 'propagate': True, |
| 276 | }, |
| 277 | 'postorius': { |
| 278 | 'handlers': ['console', 'file'], |
| 279 | 'level': 'INFO', |
| 280 | }, |
| 281 | 'q': { |
| 282 | 'level': 'WARNING', |
| 283 | 'propagate': False, |
| 284 | 'handlers': ['console', 'file'], |
| 285 | }, |
| 286 | }, |
| 287 | 'formatters': { |
| 288 | 'verbose': { |
| 289 | 'format': '%(levelname)s %(asctime)s %(process)d %(name)s %(message)s' # noqa: E501 |
| 290 | }, |
| 291 | 'simple': { |
| 292 | 'format': '%(levelname)s %(message)s' |
| 293 | }, |
| 294 | }, |
| 295 | } |
| 296 | |
| 297 | #: Current Django Site being served. This is used to customize the web host |
| 298 | #: being used to serve the current website. For more details about Django |
| 299 | #: site, see: https://docs.djangoproject.com/en/dev/ref/contrib/sites/ |
| 300 | SITE_ID = 1 |