forked from silverapp/silver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
218 lines (177 loc) · 5.59 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright (c) 2015 Presslabs SRL
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import datetime
import sys
import environ
from silver import HOOK_EVENTS as _HOOK_EVENTS
from django.utils.log import DEFAULT_LOGGING as LOGGING
"""
These settings are used by the ``manage.py`` command.
"""
env = environ.Env()
DEBUG = False
SITE_ID = 1
USE_TZ = True
TIME_ZONE = 'UTC'
try:
import environ
DATABASES = {
'default': env.db("SILVER_DB_URL",
"sqlite:///%s" % os.path.join(os.path.dirname(__file__), "db.sqlite"))
}
except ImportError:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite',
}
}
if "mysql" in DATABASES["default"]["ENGINE"]:
try:
# https://adamj.eu/tech/2020/02/04/how-to-use-pymysql-with-django/
import pymysql
# change mysqlclient version to work with Django 3+,
# as stated on https://github.com/PyMySQL/PyMySQL/issues/790
pymysql.version_info = (1, 4, 6, 'final', 0)
pymysql.install_as_MySQLdb()
except ImportError:
pass
EXTERNAL_APPS = [
# Django autocomplete
'dal',
'dal_select2',
# Django core apps
# 'django_admin_bootstrapped',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.staticfiles',
# Required apps
'django_fsm',
'rest_framework',
'django_filters',
# Dev tools
# 'django_extensions',
]
INTERNAL_APPS = [
'silver',
]
INSTALLED_APPS = EXTERNAL_APPS + INTERNAL_APPS
ROOT_URLCONF = 'silver.urls'
PROJECT_ROOT = os.path.dirname(__file__)
FIXTURE_DIRS = (
PROJECT_ROOT,
PROJECT_ROOT + '/silver/'
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': [
PROJECT_ROOT + '/payment_processors/templates/',
PROJECT_ROOT + '/templates/',
PROJECT_ROOT + '/silver/templates/',
],
'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",
)
}
}
]
MEDIA_ROOT = PROJECT_ROOT + '/app_media/'
MEDIA_URL = '/app_media/'
STATIC_ROOT = PROJECT_ROOT + '/app_static/'
STATIC_URL = '/app_static/'
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
SECRET_KEY = 'secret'
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
),
'DEFAULT_PAGINATION_CLASS': 'silver.api.pagination.LinkHeaderPagination',
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
}
HOOK_EVENTS = _HOOK_EVENTS
SILVER_DEFAULT_DUE_DAYS = 5
SILVER_DOCUMENT_PREFIX = 'documents/'
SILVER_DOCUMENT_STORAGE = None
SILVER_PAYMENT_TOKEN_EXPIRATION = datetime.timedelta(minutes=5)
SILVER_AUTOMATICALLY_CREATE_TRANSACTIONS = True
LOGGING['loggers']['xhtml2pdf'] = {
'level': 'DEBUG',
'handlers': ['console']
}
LOGGING['loggers']['pisa'] = {
'level': 'DEBUG',
'handlers': ['console']
}
LOGGING['loggers']['django'] = {
'level': 'DEBUG',
'handlers': ['console']
}
LOGGING['loggers']['django.security'] = {
'level': 'DEBUG',
'handlers': ['console']
}
LOGGING['formatters'] = LOGGING.get('formatters', {})
LOGGING['formatters']['verbose'] = {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
}
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
PAYMENT_PROCESSORS = {
'manual': {
'class': 'silver.payment_processors.manual.ManualProcessor'
},
}
PAYMENT_METHOD_SECRET = b'YOUR_FERNET_KEY_HERE' # Fernet.generate_key()
CELERY_BROKER_URL = 'redis://localhost:6379/'
CELERY_BEAT_SCHEDULE = {
'generate-pdfs': {
'task': 'silver.tasks.generate_pdfs',
'schedule': datetime.timedelta(seconds=5)
},
}
LOCK_MANAGER_CONNECTION = {'host': 'localhost', 'port': 6379, 'db': 1}
PDF_GENERATION_TIME_LIMIT = 60
TRANSACTION_SAVE_TIME_LIMIT = 5
try:
from settings_local import *
except ImportError:
pass
if sys.argv[0].endswith('pytest'):
from silver.fixtures.test_fixtures import PAYMENT_PROCESSORS
PAYMENT_DUE_DAYS = 5
REST_FRAMEWORK['PAGE_SIZE'] = API_PAGE_SIZE = 5
SILVER_SHOW_PDF_STORAGE_URL = True