· 7 years ago · Feb 17, 2018, 09:32 AM
1import os
2from myapp import config
3from django.utils.translation import ugettext_lazy as _
4
5# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
6BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7
8# SECURITY WARNING: keep the secret key used in production secret!
9SECRET_KEY = config.SECRET_KEY
10
11# SECURITY WARNING: don't run with debug turned on in production!
12DEBUG = config.DEBUG
13
14ALLOWED_HOSTS = config.ALLOWED_HOSTS
15
16# Application definition
17
18INSTALLED_APPS = (
19 'modeltranslation',
20 'django.contrib.admin',
21 'django.contrib.auth',
22 'django.contrib.contenttypes',
23 'django.contrib.sessions',
24 'django.contrib.messages',
25 'whitenoise.runserver_nostatic',
26 'django.contrib.staticfiles',
27 'myapp',
28)
29
30MIDDLEWARE = (
31 'django.middleware.security.SecurityMiddleware',
32 'whitenoise.middleware.WhiteNoiseMiddleware',
33 'django.contrib.sessions.middleware.SessionMiddleware',
34 'django.middleware.common.CommonMiddleware',
35 'django.middleware.csrf.CsrfViewMiddleware',
36 'django.contrib.auth.middleware.AuthenticationMiddleware',
37 'django.contrib.messages.middleware.MessageMiddleware',
38 # 'django_country.middleware.CountryMiddleware',
39 'django.middleware.clickjacking.XFrameOptionsMiddleware',
40)
41
42ROOT_URLCONF = 'project.urls'
43
44TEMPLATES = [
45 {
46 'BACKEND': 'django.template.backends.django.DjangoTemplates',
47 'DIRS': [],
48 'APP_DIRS': True,
49 'OPTIONS': {
50 'context_processors': [
51 'django.template.context_processors.debug',
52 'django.template.context_processors.request',
53 'django.contrib.auth.context_processors.auth',
54 'django.contrib.messages.context_processors.messages',
55 'django_settings_export.settings_export',
56 ],
57 },
58 },
59]
60
61WSGI_APPLICATION = 'project.wsgi.application'
62
63# Settings for email sending
64try:
65 EMAIL_HOST = os.environ['EMAIL_HOST']
66except KeyError:
67 EMAIL_HOST = config.EMAIL_HOST
68try:
69 EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']
70except KeyError:
71 EMAIL_HOST_PASSWORD = config.EMAIL_HOST_PASSWORD
72try:
73 EMAIL_HOST_USER = os.environ['EMAIL_HOST_USER']
74except KeyError:
75 EMAIL_HOST_USER = config.EMAIL_HOST_USER
76try:
77 EMAIL_USE_TLS = os.environ['EMAIL_USE_TLS'] or False
78except KeyError:
79 EMAIL_USE_TLS = config.EMAIL_USE_TLS
80try:
81 EMAIL_PORT = os.environ['EMAIL_PORT']
82except KeyError:
83 EMAIL_PORT = config.EMAIL_PORT
84
85try:
86 DKIM_SELECTOR = os.environ['DKIM_SELECTOR']
87except KeyError:
88 DKIM_SELECTOR = config.DKIM_SELECTOR
89try:
90 DKIM_DOMAIN = os.environ['DKIM_DOMAIN']
91except KeyError:
92 DKIM_DOMAIN = config.DKIM_DOMAIN
93try:
94 DKIM_PRIVATE_KEY = os.environ['DKIM_PRIVATE_KEY']
95except KeyError:
96 DKIM_PRIVATE_KEY = config.DKIM_PRIVATE_KEY
97if DKIM_PRIVATE_KEY:
98 EMAIL_BACKEND = 'email_backend.DKIMBackend'
99
100try:
101 SITE_HOST = os.environ['SITE_HOST']
102except KeyError:
103 SITE_HOST = config.SITE_HOST
104
105DEFAULT_FROM_EMAIL = 'info@project.net'
106DEFAULT_ACCOUNT_EMAIL = 'accounts@project.net'
107
108# Database
109
110DATABASES = {
111 'default': {
112 'ENGINE': 'django.db.backends.sqlite3',
113 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
114 }
115}
116
117# Bring database configuration from database url if dj_database_url is installed
118try:
119 import dj_database_url
120 db_url = config.DATABASE_URL
121 DATABASES['default'] = dj_database_url.config(default=db_url)
122except:
123 pass
124
125
126# Internationalization
127
128LANGUAGE_CODE = 'en'
129
130LANGUAGES = (
131 ('en', _('English')),
132)
133
134LOCALE_PATHS = (
135 os.path.join(BASE_DIR, 'locale/'),
136)
137
138TIME_ZONE = 'UTC'
139
140USE_I18N = True
141
142USE_L10N = True
143
144USE_TZ = True
145
146USE_S3 = config.USE_S3
147
148if USE_S3: # Only use Amazon S3 in production
149
150 # Amazon AWS Specific settings:
151
152 AWS_HEADERS = { # see http://developer.yahoo.com/performance/rules.html#expires
153 'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
154 'Cache-Control': 'max-age=94608000',
155 }
156
157 AWS_STORAGE_BUCKET_NAME = config.AWS_STORAGE_BUCKET_NAME
158 AWS_ACCESS_KEY_ID = config.AWS_ACCESS_KEY_ID
159 AWS_SECRET_ACCESS_KEY = config.AWS_SECRET_ACCESS_KEY
160
161 # Tell django-storages that when coming up with the URL for an item in S3 storage, keep
162 # it simple - just use this domain plus the path. (If this isn't set, things get complicated).
163 # This controls how the `static` template tag from `staticfiles` gets expanded, if you're using it.
164 # We also use it in the next setting.
165 AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
166
167 MEDIAFILES_LOCATION = 'media'
168 MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
169 DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
170
171# Braintree settings
172try:
173 BRAINTREE_MERCHANT_ID = os.environ['BRAINTREE_MERCHANT_ID']
174except KeyError:
175 BRAINTREE_MERCHANT_ID = config.BRAINTREE_MERCHANT_ID
176try:
177 BRAINTREE_PUBLIC_KEY = os.environ['BRAINTREE_PUBLIC_KEY']
178except KeyError:
179 BRAINTREE_PUBLIC_KEY = config.BRAINTREE_PUBLIC_KEY
180try:
181 BRAINTREE_PRIVATE_KEY = os.environ['BRAINTREE_PRIVATE_KEY']
182except KeyError:
183 BRAINTREE_PRIVATE_KEY = config.BRAINTREE_PRIVATE_KEY
184try:
185 BRAINTREE_SANDBOX_MODE = os.environ['BRAINTREE_SANDBOX_MODE']
186except KeyError:
187 BRAINTREE_SANDBOX_MODE = config.BRAINTREE_SANDBOX_MODE
188try:
189 PAYMENT_HOST = os.environ['BRAINTREE_PAYMENT_HOST']
190except KeyError:
191 PAYMENT_HOST = config.BRAINTREE_PAYMENT_HOST
192
193PAYMENT_USES_SSL = False
194PAYMENT_MODEL = 'mysite.Payment'
195PAYMENT_VARIANTS = {'default': ('payments.dummy.DummyProvider', {})}
196PAYMENT_VARIANTS = {'default': ('payments.braintree.BraintreeProvider', {'merchant_id': BRAINTREE_MERCHANT_ID,
197 'public_key': BRAINTREE_PUBLIC_KEY,
198 'private_key': BRAINTREE_PRIVATE_KEY,
199 'sandbox': BRAINTREE_SANDBOX_MODE})}
200
201
202# Static files (CSS, JavaScript, Images)
203
204try:
205 STATIC_ROOT = os.environ['STATIC_ROOT']kijk
206except KeyError:
207 STATIC_ROOT = config.STATIC_ROOT
208
209STATIC_URL = '/static/'
210
211MEDIA_DIR_NAME = 'media'
212
213MEDIA_ROOT = os.path.join(BASE_DIR, MEDIA_DIR_NAME)
214if not USE_S3: # Use local filesystem in development mode
215 MEDIA_URL = '/media/'
216
217try:
218 GOOGLE_MAPS_V3_APIKEY = config.GOOGLE_MAPS_V3_APIKEY
219except:
220 GOOGLE_MAPS_V3_APIKEY = ''
221
222# For enabling HTTPS in the production server
223PRODUCTION_SERVER = False
224try:
225 if config.PRODUCTION_SERVER == True:
226 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
227 PRODUCTION_SERVER = True
228except:
229 pass