· 10 years ago · Mar 13, 2016, 01:48 PM
1"""
2Django settings for elearning_academy project.
3
4Generated by 'django-admin startproject' using Django 1.8.6.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/1.8/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/1.8/ref/settings/
11"""
12
13import logging.config
14import os
15import sys
16import warnings
17from ConfigParser import ConfigParser
18from datetime import datetime
19
20# Build paths inside the project like this: os.path.join(PROJECT_DIR, ...)
21PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
22
23config = ConfigParser()
24config.read(os.path.join(PROJECT_DIR, 'elearning_academy/settings.ini'))
25
26
27def get_main_caches():
28 """
29 Return list of caches defined for dev and prod work
30
31 :rtype: list[str]
32 """
33 main_caches = config.get('caches', 'main')
34 main_caches = main_caches.split(',')
35 return list(set(main_caches)) # Keep unique only
36
37
38def get_test_caches():
39 """
40 Return list of caches defined for testing
41
42 :rtype: list[str]
43 """
44 test_caches = config.get('caches', 'test')
45 test_caches = test_caches.split(',')
46 return list(set(test_caches)) # Keep unique only
47
48
49def validate_caches():
50 """
51 Checks if there are no common cache servers in test in main (dev and production)
52 """
53 main_cache = set(get_main_caches())
54 test_cache = set(get_test_caches())
55
56 if main_cache & test_cache:
57 warnings.warn('There are common cache server for tests and prod. '
58 'Test caches are cleared on running unit tests and this might lead to unwanted behaviour',
59 RuntimeWarning)
60
61
62DEBUG = config.getboolean('debug', 'debug')
63
64ADMINS = config.items('admins')
65
66MANAGERS = ADMINS
67
68validate_caches()
69
70CACHES = {
71 'default': {
72 'BACKEND': 'django_redis.cache.RedisCache',
73 'LOCATION': get_main_caches(),
74 },
75}
76
77DATABASES = {
78 'default': {
79 'ENGINE': config.get('database', 'engine'),
80 'NAME': config.get('database', 'db_name'),
81 'USER': config.get('database', 'user'),
82 'PASSWORD': config.get('database', 'password'),
83 'HOST': config.get('database', 'host'),
84 'PORT': config.get('database', 'port'),
85 },
86}
87
88# Cache for tests should be different from cache for main development and production
89# Running on sqlite for fast db creation
90if 'test' in sys.argv:
91 DATABASES = {
92 'default': {
93 'ENGINE': 'django.db.backends.sqlite3',
94 'NAME': 'test_sqlite.db',
95 },
96 }
97
98 CACHES = {
99 'default': {
100 'BACKEND': 'django_redis.cache.RedisCache',
101 'LOCATION': get_test_caches(),
102 },
103 }
104
105
106ALLOWED_HOSTS = config.get('production', 'allowed_hosts')
107
108TIME_ZONE = 'Asia/Kolkata'
109
110LANGUAGE_CODE = 'en-us'
111
112SITE_ID = 1
113
114USE_I18N = True
115
116USE_L10N = True
117
118USE_TZ = True
119
120MEDIA_ROOT = os.path.join(PROJECT_DIR, 'elearning_academy/media/')
121
122MEDIA_URL = '/media/'
123
124STATIC_ROOT = os.path.join(PROJECT_DIR, 'elearning_academy/staticfiles')
125
126STATIC_URL = '/static/'
127
128STATICFILES_DIRS = (
129 os.path.join(PROJECT_DIR, 'elearning_academy/static'),
130)
131
132STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
133
134# Make this unique, and don't share it with anybody.
135SECRET_KEY = config.get('secrets', 'secret_key')
136
137MIDDLEWARE_CLASSES = (
138 'django.contrib.sessions.middleware.SessionMiddleware',
139 'django.middleware.csrf.CsrfViewMiddleware',
140 'django.contrib.auth.middleware.AuthenticationMiddleware',
141 'django.contrib.messages.middleware.MessageMiddleware',
142 # Uncomment the next line for logging username in server access logs
143 # 'elearning_academy.log_uname_middleware.LogUsernameMiddleware',
144 'django.middleware.common.CommonMiddleware',
145 'django.middleware.clickjacking.XFrameOptionsMiddleware',
146)
147
148ROOT_URLCONF = 'elearning_academy.urls'
149
150WSGI_APPLICATION = 'elearning_academy.wsgi.application'
151
152TEMPLATES = [
153 {
154 'BACKEND': 'django.template.backends.django.DjangoTemplates',
155 'DIRS': [
156 os.path.join(PROJECT_DIR, 'elearning_academy/templates'),
157 ],
158 'APP_DIRS': True,
159 'OPTIONS': {
160 'context_processors': [
161 'django.contrib.auth.context_processors.auth',
162 'django.contrib.messages.context_processors.messages',
163 'django.template.context_processors.debug',
164 'django.template.context_processors.i18n',
165 'django.template.context_processors.media',
166 'django.template.context_processors.request',
167 'django.template.context_processors.static',
168 'elearning_academy.context_processor.my_global_name',
169 ],
170 'debug': config.getboolean('debug', 'template_debug'),
171 },
172 },
173]
174
175INSTALLED_APPS = (
176 'django.contrib.auth',
177 'django.contrib.contenttypes',
178 'django.contrib.sessions',
179 'django.contrib.sites',
180 'django.contrib.messages',
181 'django.contrib.staticfiles',
182 'django.contrib.humanize',
183 'django.contrib.admin',
184 'django.contrib.admindocs',
185
186 # Project Apps
187 'util',
188 'chat',
189
190 'registration',
191 'user_profile',
192 'notification',
193
194 'courseware',
195 'quiz',
196 'video',
197 'concept',
198 'document',
199 'progress',
200 'quiz_template',
201 'marks',
202 'premium',
203 'discussion_forum',
204 'report_grading_app',
205 'schedule',
206 'suggestion_box',
207
208 'upload',
209 'download',
210 'plagiarism',
211 'assignments',
212 'evaluate',
213 'cribs',
214 'crib_management',
215
216 # Third party apps
217 'rest_framework',
218 'dajaxice',
219 'formtools',
220)
221
222SESSION_ENGINE = "django.contrib.sessions.backends.cache"
223
224LOGGING_CONFIG = None
225LOGGING = {
226 'version': 1,
227 'disable_existing_loggers': False,
228 'formatters': {
229 'verbose': {
230 'format': '%(levelname)s [%(asctime)s] [%(name)s] [%(module)s] [Process:%(process)d] '
231 '[Thread:%(thread)d] %(message)s'
232 },
233 'simple': {
234 'format': '%(levelname)s %(message)s'
235 },
236 },
237 'handlers': {
238 'console': {
239 'level': 'DEBUG',
240 'class': 'logging.StreamHandler',
241 'formatter': 'simple'
242 },
243 'file_django': {
244 'level': 'DEBUG',
245 'class': 'logging.FileHandler',
246 'filename': os.path.join(PROJECT_DIR, 'logs/django.log'),
247 'formatter': 'verbose'
248 },
249 'file_application': {
250 'level': 'DEBUG',
251 'class': 'logging.FileHandler',
252 'filename': os.path.join(PROJECT_DIR, 'logs/application.log'),
253 'formatter': 'verbose',
254 },
255 'mail_admins': {
256 'level': 'ERROR',
257 'class': 'django.utils.log.AdminEmailHandler'
258 },
259 },
260 'loggers': {
261 '': {
262 'handlers': ['file_application'],
263 'level': 'INFO',
264 },
265 'requests': {
266 'handlers': ['file_application'],
267 'level': 'WARNING',
268 },
269 'django': {
270 'handlers': ['file_django', 'mail_admins'],
271 'level': 'INFO',
272 'propagate': False,
273 },
274 },
275
276}
277logging.config.dictConfig(LOGGING)
278
279# Settings for Django Rest Framework
280# http://www.django-rest-framework.org/api-guide/settings/
281REST_FRAMEWORK = {
282
283 'DEFAULT_PAGINATION_CLASS': 'util.core.StandardResultSetPagination',
284
285 'DEFAULT_AUTHENTICATION_CLASSES': (
286 'rest_framework.authentication.SessionAuthentication',
287 ),
288
289 'DEFAULT_PERMISSION_CLASSES': (
290 'rest_framework.permissions.IsAuthenticated',
291 ),
292
293 'DEFAULT_THROTTLE_RATES': {
294 'user': '200/min'
295 }
296}
297
298LOGIN_REDIRECT_URL = '/courseware/'
299
300EMAIL_HOST = config.get('email', 'host')
301EMAIL_PORT = config.get('email', 'port')
302
303EMAIL_HOST_USER = config.get('email', 'user')
304EMAIL_HOST_PASSWORD = config.get('email', 'password')
305EMAIL_USE_TLS = config.get('email', 'use_TLS')
306EMAIL_BACKEND = config.get('email', 'backend')
307
308DEFAULT_FROM_DOMAIN = config.get('email', 'default_from_domain')
309EMAIL_SUBJECT_PREFIX = config.get('email', 'subject_prefix')
310
311SERVER_EMAIL = '{localpart}@{domain}'.format(localpart=config.get('email', 'server_email'), domain=DEFAULT_FROM_DOMAIN)
312DEFAULT_FROM_EMAIL = '{localpart}@{domain}'.format(localpart=config.get('email', 'default_from_email'),
313 domain=DEFAULT_FROM_DOMAIN)
314
315SCHEME = config.get('server', 'scheme')
316MY_SERVER = '{scheme}://{domain}'.format(scheme=SCHEME, domain=config.get('server', 'ip'))
317MY_SITE_NAME = config.get('server', 'name')
318
319DEFAULT_CONCEPT_IMAGE = config.get('server', 'default_concept_image')
320TITLE_ICON = config.get('server', 'title_icon')
321
322MAX_CONCURRENT_CONNECTIONS = config.getint('server', 'max_concurrent_conns')
323
324FIXTURE_DIRS = [
325 os.path.join(PROJECT_DIR, 'elearning_academy/fixtures'),
326]
327
328# Chat Settings
329CHAT_SERVER = config.get('chatserver', 'ip')
330TORNADO_PORT = config.get('chatserver', 'port')