| 1 |
import os |
| 2 |
import sys |
| 3 |
|
| 4 |
import environ |
| 5 |
|
| 6 |
env = environ.Env() |
| 7 |
|
| 8 |
|
| 9 |
def abspath(*args): |
| 10 |
"""Join path arguments and return their absolute path""" |
| 11 |
return os.path.abspath(os.path.join(*args)) |
| 12 |
|
| 13 |
|
| 14 |
DEBUG = True |
| 15 |
SECRET_KEY = "CHANGE_THIS_TO_SOMETHING_UNIQUE_AND_SECURE" |
| 16 |
|
| 17 |
PROJECT_ROOT = abspath(os.path.dirname(__file__)) |
| 18 |
GUARDIAN_MODULE_PATH = abspath(PROJECT_ROOT, "..") |
| 19 |
sys.path.insert(0, GUARDIAN_MODULE_PATH) |
| 20 |
|
| 21 |
DATABASES = {"default": env.db(default="sqlite:///example.db")} |
| 22 |
|
| 23 |
INSTALLED_APPS = ( |
| 24 |
"django.contrib.auth", |
| 25 |
"django.contrib.contenttypes", |
| 26 |
"django.contrib.sessions", |
| 27 |
"django.contrib.sites", |
| 28 |
"django.contrib.admin", |
| 29 |
"django.contrib.messages", |
| 30 |
"django.contrib.staticfiles", |
| 31 |
"guardian", |
| 32 |
"posts", |
| 33 |
"articles", |
| 34 |
"core", |
| 35 |
) |
| 36 |
|
| 37 |
if "GRAPPELLI" in os.environ: |
| 38 |
try: |
| 39 |
__import__("grappelli") |
| 40 |
INSTALLED_APPS = ("grappelli",) + INSTALLED_APPS |
| 41 |
except ImportError: |
| 42 |
print("django-grappelli not installed") |
| 43 |
|
| 44 |
MIDDLEWARE = ( |
| 45 |
"django.middleware.common.CommonMiddleware", |
| 46 |
"django.contrib.sessions.middleware.SessionMiddleware", |
| 47 |
"django.middleware.csrf.CsrfViewMiddleware", |
| 48 |
"django.contrib.auth.middleware.AuthenticationMiddleware", |
| 49 |
"django.contrib.messages.middleware.MessageMiddleware", |
| 50 |
) |
| 51 |
|
| 52 |
STATIC_ROOT = abspath(PROJECT_ROOT, "..", "public", "static") |
| 53 |
STATIC_URL = "/static/" |
| 54 |
STATICFILES_DIRS = [abspath(PROJECT_ROOT, "static")] |
| 55 |
GUARDIAN_RAISE_403 = True |
| 56 |
|
| 57 |
ROOT_URLCONF = "urls" |
| 58 |
|
| 59 |
SITE_ID = 1 |
| 60 |
|
| 61 |
USE_I18N = True |
| 62 |
USE_L10N = True |
| 63 |
USE_TZ = True |
| 64 |
TIME_ZONE = "UTC" |
| 65 |
|
| 66 |
LOGIN_REDIRECT_URL = "/" |
| 67 |
|
| 68 |
TEST_RUNNER = "django.test.runner.DiscoverRunner" |
| 69 |
|
| 70 |
AUTHENTICATION_BACKENDS = ( |
| 71 |
# This custom backend is needed as long as https://github.com/django/django/commit/d4e4520efb553d2bfcc68ac8cf007c0c402d4845 |
| 72 |
# is not added to a Django release, after that we can just enable it for the relevant versions (>5.1.2). |
| 73 |
"core.backends.CustomModelBackend", |
| 74 |
"guardian.backends.ObjectPermissionBackend", |
| 75 |
) |
| 76 |
|
| 77 |
GUARDIAN_GET_INIT_ANONYMOUS_USER = "core.models.get_custom_anon_user" |
| 78 |
|
| 79 |
PASSWORD_HASHERS = ("django.contrib.auth.hashers.PBKDF2PasswordHasher",) |
| 80 |
|
| 81 |
AUTH_USER_MODEL = "core.CustomUser" |
| 82 |
GUARDIAN_USER_OBJ_PERMS_MODEL = "articles.BigUserObjectPermission" |
| 83 |
GUARDIAN_GROUP_OBJ_PERMS_MODEL = "articles.BigGroupObjectPermission" |
| 84 |
|
| 85 |
GUARDIAN_MONKEY_PATCH_USER = False |
| 86 |
GUARDIAN_MONKEY_PATCH_GROUP = False |
| 87 |
|
| 88 |
|
| 89 |
TEMPLATES = [ |
| 90 |
{ |
| 91 |
"BACKEND": "django.template.backends.django.DjangoTemplates", |
| 92 |
"DIRS": (os.path.join(os.path.dirname(__file__), "templates"),), |
| 93 |
"OPTIONS": { |
| 94 |
"debug": DEBUG, |
| 95 |
"loaders": ( |
| 96 |
"django.template.loaders.filesystem.Loader", |
| 97 |
"django.template.loaders.app_directories.Loader", |
| 98 |
), |
| 99 |
"context_processors": ( |
| 100 |
"core.context_processors.version", |
| 101 |
"django.contrib.auth.context_processors.auth", |
| 102 |
"django.template.context_processors.debug", |
| 103 |
"django.template.context_processors.i18n", |
| 104 |
"django.template.context_processors.media", |
| 105 |
"django.template.context_processors.static", |
| 106 |
"django.template.context_processors.request", |
| 107 |
"django.template.context_processors.tz", |
| 108 |
"django.contrib.messages.context_processors.messages", |
| 109 |
), |
| 110 |
}, |
| 111 |
}, |
| 112 |
] |
| 113 |
|
| 114 |
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |