generated from thclark/django-rabid-armadillo
/
settings.py
194 lines (163 loc) · 6.64 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import os
def get_db_conf():
"""
Configures database according to the DATABASE_ENGINE environment
variable. Defaults to SQlite.
This method is used to let tests run against different database backends.
"""
database_engine = os.environ.get("DATABASE_ENGINE", "sqlite")
if database_engine == "sqlite":
return {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
elif database_engine == "postgres":
return {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "postgres_db",
"USER": "postgres_user",
"PASSWORD": "postgres_password",
"HOST": "localhost",
"PORT": "5432",
}
# ---------------------------------------------------------------------------
# GENERIC DJANGO SETTINGS FOR THE TEST APP (scroll down for the good stuff)
# ---------------------------------------------------------------------------
DEBUG = True
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"unfold", # <---- COMMENT THIS OUT AND REBOOT SERVER TO DEVELOP ON ORIGINAL DJANGO ADMIN
"django.contrib.admin",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_extensions", # Gives us shell_plus and reset_db for manipulating the test server
"debug_toolbar", # Allows us to inspect SQL statements made when making queries in the admin
"django_json_widget", # Allows us to switch over to a json editing widget instead of our own js widgets for internal development
"django_gcp",
"tests.server.example",
]
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
]
# Required for django_debug_toolbar
if DEBUG:
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(PROJECT_DIR, "django_gcp", "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.template.context_processors.request",
"django.contrib.messages.context_processors.messages",
],
"debug": DEBUG,
},
},
]
ALLOWED_HOSTS = [
"localhost",
".loca.lt",
] # Adding loca.lt allows developers to expose the example server using localtunnel
DATABASES = {"default": get_db_conf()}
ROOT_URLCONF = "tests.server.urls"
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
SECRET_KEY = "secretkey"
ASGI_APPLICATION = "tests.server.asgi.application"
# ---------------------------------------------------------------------------
# HERE'S HOW TO SET UP ERROR REPORTING AND STRUCTURED LOGGING
# ----------------------------------------------------------------------------
GCP_ERROR_REPORTING_SERVICE_NAME = "django-gcp-example"
LOGGING = {
"version": 1,
"disable_existing_loggers": True,
"root": {"handlers": ["gcp_structured_logging", "gcp_error_reporting"]},
"formatters": {
"verbose": {"format": "%(levelname)s %(asctime)s %(module)s " "%(message)s"},
},
"filters": {
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse",
},
"require_debug_true": {
"()": "django.utils.log.RequireDebugTrue",
},
},
"handlers": {
"console": {
"level": "DEBUG",
"filters": ["require_debug_true"],
"class": "logging.StreamHandler",
"formatter": "verbose",
},
"gcp_structured_logging": {
"level": "INFO",
"filters": ["require_debug_false"],
"class": "django_gcp.logging.GoogleStructuredLogsHandler",
},
"gcp_error_reporting": {
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django_gcp.logging.GoogleErrorReportingHandler",
"formatter": "verbose",
},
},
"loggers": {
"django": {
"handlers": ["console", "gcp_structured_logging", "gcp_error_reporting"],
"level": "INFO",
},
"django.server": {
"handlers": ["console", "gcp_structured_logging", "gcp_error_reporting"],
"level": "INFO",
"propagate": False,
},
},
}
# ---------------------------------------------------------------------------
# HERE'S HOW TO SET UP STATIC, MEDIA AND EXTRA STORAGE
# ---------------------------------------------------------------------------
# MEDIA FILES
DEFAULT_FILE_STORAGE = "django_gcp.storage.GoogleCloudMediaStorage"
GCP_STORAGE_MEDIA = {"bucket_name": "example-media-assets"}
MEDIA_URL = f"https://storage.googleapis.com/{GCP_STORAGE_MEDIA['bucket_name']}/"
MEDIA_ROOT = "/media/"
# STATIC FILES (FOR LOCAL DEVELOPMENT OF WIDGETS)
# STATIC_URL = "static/"
# STATIC_ROOT = "./staticfiles"
# STATIC FILES (FOR USING THE CLOUD STORE)
STATICFILES_STORAGE = "django_gcp.storage.GoogleCloudStaticStorage"
GCP_STORAGE_STATIC = {"bucket_name": "example-static-assets"}
STATIC_URL = f"https://storage.googleapis.com/{GCP_STORAGE_STATIC['bucket_name']}/"
STATIC_ROOT = "/static/"
# EXTRA STORES
GCP_STORAGE_EXTRA_STORES = {"extra-versioned": {"bucket_name": "example-extra-versioned-assets"}}
# ---------------------------------------------------------------------------
# HERE'S HOW TO SET UP TASKS
# ---------------------------------------------------------------------------
GCP_TASKS_DEFAULT_QUEUE_NAME = "example-primary"
GCP_TASKS_DELIMITER = "--"
# This is the domain on which the worker app can receive requests
# You can use localtunnel to easily create your own public domain to
# run end-to-end integration tests with a real GCP project
GCP_TASKS_DOMAIN = "https://outrageous-horny-giraffe.loca.lt"
GCP_TASKS_EAGER_EXECUTE = False
GCP_TASKS_REGION = "europe-west1"
GCP_TASKS_RESOURCE_PREFIX = "django-gcp"