-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathbase.py
More file actions
279 lines (232 loc) · 7.33 KB
/
Copy pathbase.py
File metadata and controls
279 lines (232 loc) · 7.33 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
"""
Base settings for patchwork project.
"""
import os
ROOT_DIR = os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir
)
#
# Core settings
# https://docs.djangoproject.com/en/2.2/ref/settings/#core-settings
#
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.staticfiles',
'patchwork',
]
MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.admindocs.middleware.XViewMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
TIME_ZONE = 'Australia/Canberra'
USE_I18N = False
USE_TZ = False
TEST_RUNNER = 'patchwork.tests.runner.PatchworkTestRunner'
ROOT_URLCONF = 'patchwork.urls'
_TEMPLATE_DIRS = [
os.path.join(ROOT_DIR, 'templates'),
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': _TEMPLATE_DIRS,
'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.request',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'patchwork.context_processors.site',
'patchwork.context_processors.version',
],
},
},
]
FORM_RENDERER = 'patchwork.forms.PatchworkTableRenderer'
# TODO(stephenfin): Consider changing to BigAutoField when we drop support for
# Django < 3.2
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DEFAULT_FROM_EMAIL = 'Patchwork <patchwork@patchwork.example.com>'
SERVER_EMAIL = DEFAULT_FROM_EMAIL
#
# Auth settings
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth
#
LOGIN_URL = 'auth_login'
LOGIN_REDIRECT_URL = 'user-profile'
#
# Sites settings
# https://docs.djangoproject.com/en/2.2/ref/settings/#sites
#
SITE_ID = 1
#
# Static files settings
# https://docs.djangoproject.com/en/2.2/ref/settings/#static-files
#
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(ROOT_DIR, 'htdocs'),
]
# Database
#
# If you're using a postgres database, connecting over a local unix-domain
# socket, then the following setting should work for you. Otherwise,
# see https://docs.djangoproject.com/en/2.2/ref/settings/#databases
if os.getenv('DATABASE_TYPE') == 'postgres':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': os.environ.get('DATABASE_HOST', 'localhost'),
'PORT': os.environ.get('DATABASE_PORT', ''),
'NAME': os.environ.get('DATABASE_NAME', 'patchwork'),
'USER': os.environ.get('DATABASE_USER', 'patchwork'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD', 'password'),
},
}
elif os.getenv('DATABASE_TYPE') == 'sqlite3':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.environ.get('DATABASE_NAME', ''),
},
}
else: # mysql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': os.getenv('DATABASE_HOST', 'localhost'),
'PORT': os.getenv('DATABASE_PORT', ''),
'NAME': os.getenv('DATABASE_NAME', 'patchwork'),
'USER': os.getenv('DATABASE_USER', 'patchwork'),
'PASSWORD': os.getenv('DATABASE_PASSWORD', 'password'),
'TEST': {
'CHARSET': 'utf8',
},
},
}
#
# Third-party application settings
#
# rest_framework
try:
# django rest framework isn't a standard package in most distros, so
# don't make it compulsory
import rest_framework # NOQA
INSTALLED_APPS += [
'rest_framework',
'rest_framework.authtoken',
'django_filters',
]
except ImportError:
pass
REST_FRAMEWORK = {
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.URLPathVersioning',
'DEFAULT_PAGINATION_CLASS': 'patchwork.api.base.LinkHeaderPagination',
'DEFAULT_FILTER_BACKENDS': (
'patchwork.api.filters.DjangoFilterBackend',
'rest_framework.filters.SearchFilter',
'rest_framework.filters.OrderingFilter',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
'SEARCH_PARAM': 'q',
'ORDERING_PARAM': 'order',
'NON_FIELD_ERRORS_KEY': 'detail',
}
#
# Logging settings
#
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'email': {
'format': '== Mail\n\n%(mail)s\n\n== Traceback\n',
},
},
'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',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
'formatter': 'email',
'include_html': True,
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': True,
},
'patchwork.parser': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': False,
},
'patchwork.management.commands.parsearchive': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': True,
},
'patchwork.management.commands.parsemail': {
'handlers': ['console', 'mail_admins'],
'level': 'WARNING',
'propagate': True,
},
},
}
#
# Patchwork settings
#
DEFAULT_ITEMS_PER_PAGE = 100
CONFIRMATION_VALIDITY_DAYS = 7
NOTIFICATION_DELAY_MINUTES = 10
NOTIFICATION_FROM_EMAIL = DEFAULT_FROM_EMAIL
# Set to True to enable the Patchwork XML-RPC interface
ENABLE_XMLRPC = False
# Set to True to enable the Patchwork REST API
ENABLE_REST_API = True
REST_RESULTS_PER_PAGE = 30
MAX_REST_RESULTS_PER_PAGE = 250
# Set to True to enable redirections or URLs from previous versions
# of patchwork
COMPAT_REDIR = True
# Set to True to always generate https:// links instead of guessing
# the scheme based on current access. This is useful if SSL protocol
# is terminated upstream of the server (e.g. at the load balancer)
FORCE_HTTPS_LINKS = False
# Set to True to hide admin details from the about page (/about)
ADMINS_HIDE = False