common.py 12.7 KB
Newer Older
1 2 3 4
"""
This is the common settings file, intended to set sane defaults. If you have a
piece of configuration that's dependent on a set of feature flags being set,
then create a function that returns the calculated value based on the value of
5
MITX_FEATURES[...]. Modules that extend this one can change the feature
6 7 8 9
configuration in an environment specific config file and re-calculate those
values.

We should make a method that calls all these config methods so that you just 
10
make one call at the end of your site-specific dev file to reset all the
11 12
dependent variables (like INSTALLED_APPS) for you.

13
Longer TODO:
14 15 16 17 18 19 20
1. Right now our treatment of static content in general and in particular 
   course-specific static content is haphazard.
2. We should have a more disciplined approach to feature flagging, even if it
   just means that we stick them in a dict called MITX_FEATURES.
3. We need to handle configuration for multiple courses. This could be as 
   multiple sites, but we do need a way to map their data assets.
"""
21
import sys
Piotr Mitros committed
22
import tempfile
23
import glob2
24 25

import djcelery
26 27
from path import path

28
from .askbotsettings import * # this is where LIVESETTINGS_OPTIONS comes from
29

30 31 32 33 34 35 36 37
################################### FEATURES ###################################
COURSEWARE_ENABLED = True
ASKBOT_ENABLED = True
GENERATE_RANDOM_USER_CREDENTIALS = False
PERFSTATS = False

# Features
MITX_FEATURES = {
38 39
    'SAMPLE' : False,
    'USE_DJANGO_PIPELINE' : True,
40
    'DISPLAY_HISTOGRAMS_TO_STAFF' : True,
41 42
}

43 44 45 46 47 48
# Used for A/B testing
DEFAULT_GROUPS = []

# If this is true, random scores will be generated for the purpose of debugging the profile graphs
GENERATE_PROFILE_SCORES = False

49
############################# SET PATH INFORMATION #############################
50
PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /mitx/lms
51
COMMON_ROOT = PROJECT_ROOT.dirname() / "common"
52
ENV_ROOT = PROJECT_ROOT.dirname().dirname() # virtualenv dir /mitx is in
53 54 55 56 57 58 59 60 61 62 63
ASKBOT_ROOT = ENV_ROOT / "askbot-devel"
COURSES_ROOT = ENV_ROOT / "data"

# FIXME: To support multiple courses, we should walk the courses dir at startup
DATA_DIR = COURSES_ROOT

sys.path.append(ENV_ROOT)
sys.path.append(ASKBOT_ROOT)
sys.path.append(ASKBOT_ROOT / "askbot" / "deps")
sys.path.append(PROJECT_ROOT / 'djangoapps')
sys.path.append(PROJECT_ROOT / 'lib')
64
sys.path.append(COMMON_ROOT / 'djangoapps')
65
sys.path.append(COMMON_ROOT / 'lib')
66 67

################################## MITXWEB #####################################
68 69
# This is where we stick our compiled template files. Most of the app uses Mako
# templates
70
MAKO_MODULE_DIR = tempfile.mkdtemp('mako')
Piotr Mitros committed
71 72
MAKO_TEMPLATES = {}
MAKO_TEMPLATES['course'] = [DATA_DIR]
73 74
MAKO_TEMPLATES['sections'] = [DATA_DIR / 'sections']
MAKO_TEMPLATES['custom_tags'] = [DATA_DIR / 'custom_tags']
75 76
MAKO_TEMPLATES['main'] = [PROJECT_ROOT / 'templates',
                          COMMON_ROOT / 'lib' / 'capa' / 'templates',
77 78
                          DATA_DIR / 'info',
                          DATA_DIR / 'problems']
Piotr Mitros committed
79

80 81 82 83
# This is where Django Template lookup is defined. There are a few of these 
# still left lying around.
TEMPLATE_DIRS = (
    PROJECT_ROOT / "templates",
84
    DATA_DIR / "problems",
85 86 87 88
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
89
    'django.core.context_processors.static',
90
    'askbot.context.application_settings',
91
    'django.contrib.messages.context_processors.messages',
92 93 94 95 96 97 98 99
    #'django.core.context_processors.i18n',
    'askbot.user_messages.context_processors.user_messages',#must be before auth
    'django.core.context_processors.auth', #this is required for admin
    'django.core.context_processors.csrf', #necessary for csrf protection
)


# FIXME: 
100 101
# We should have separate S3 staged URLs in case we need to make changes to 
# these assets and test them.
102
LIB_URL = '/static/js/'
103 104 105 106 107

# Dev machines shouldn't need the book
# BOOK_URL = '/static/book/'
BOOK_URL = 'https://mitxstatic.s3.amazonaws.com/book_images/' # For AWS deploys

108 109 110 111
# Configuration option for when we want to grab server error pages
STATIC_GRAB = False
DEV_CONTENT = True

112
# FIXME: Should we be doing this truncation?
113 114
TRACK_MAX_EVENT = 10000 
DEBUG_TRACK_LOG = False
115

116 117 118 119 120 121 122 123 124
MITX_ROOT_URL = ''

COURSE_NAME = "6.002_Spring_2012"
COURSE_NUMBER = "6.002x"
COURSE_TITLE = "Circuits and Electronics"

### Dark code. Should be enabled in local settings for devel. 

ENABLE_MULTICOURSE = False     # set to False to disable multicourse display (see lib.util.views.mitxhome)
125
QUICKEDIT = False
126 127 128

###

129 130 131 132 133 134 135 136
COURSE_DEFAULT = '6.002_Spring_2012'
COURSE_SETTINGS =  {'6.002_Spring_2012': {'number' : '6.002x',
                                          'title'  :  'Circuits and Electronics',
                                          'xmlpath': '6002x/',
                                          }
                    }


137 138 139 140
############################### DJANGO BUILT-INS ###############################
# Change DEBUG/TEMPLATE_DEBUG in your environment settings files, not here
DEBUG = False
TEMPLATE_DEBUG = False
141

142 143 144 145
# Site info
SITE_ID = 1
SITE_NAME = "localhost:8000"
HTTPS = 'on'
146
ROOT_URLCONF = 'mitx.lms.urls'
147
IGNORABLE_404_ENDS = ('favicon.ico')
148

149
# Email
150 151 152 153
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_FROM_EMAIL = 'registration@mitx.mit.edu'
DEFAULT_FEEDBACK_EMAIL = 'feedback@mitx.mit.edu'
ADMINS = (
154
    ('MITx Admins', 'admin@mitx.mit.edu'),
155 156 157
)
MANAGERS = ADMINS

158
# Static content
159 160
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
161
STATIC_ROOT = ENV_ROOT / "staticfiles" 
162 163

# FIXME: We should iterate through the courses we have, adding the static 
164
#        contents for each of them. (Right now we just use symlinks.)
165
STATICFILES_DIRS = [
166
    PROJECT_ROOT / "static",
167
    ASKBOT_ROOT / "askbot" / "skins",
168 169 170
    ("circuits", DATA_DIR / "images"),
    ("handouts", DATA_DIR / "handouts"),
    ("subs", DATA_DIR / "subs"),
171

172 173
# This is how you would use the textbook images locally
#    ("book", ENV_ROOT / "book_images")
174
]
175

176 177 178 179 180
# Locale/Internationalization
TIME_ZONE = 'America/New_York' # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
LANGUAGE_CODE = 'en' # http://www.i18nguy.com/unicode/language-identifiers.html
USE_I18N = True
USE_L10N = True
181

182 183 184
# Messages
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'

185 186 187 188 189 190 191
#################################### AWS #######################################
# S3BotoStorage insists on a timeout for uploaded assets. We should make it 
# permanent instead, but rather than trying to figure out exactly where that
# setting is, I'm just bumping the expiration time to something absurd (100 
# years). This is only used if DEFAULT_FILE_STORAGE is overriden to use S3
# in the global settings.py
AWS_QUERYSTRING_EXPIRE = 10 * 365 * 24 * 60 * 60 # 10 years
192

193
################################### ASKBOT #####################################
194 195 196 197 198 199 200 201
LIVESETTINGS_OPTIONS['MITX_ROOT_URL'] = MITX_ROOT_URL
skin_settings = LIVESETTINGS_OPTIONS[1]['SETTINGS']['GENERAL_SKIN_SETTINGS']
skin_settings['SITE_FAVICON'] = unicode(MITX_ROOT_URL) + skin_settings['SITE_FAVICON']
skin_settings['SITE_LOGO_URL'] = unicode(MITX_ROOT_URL) +  skin_settings['SITE_LOGO_URL']
skin_settings['LOCAL_LOGIN_ICON'] = unicode(MITX_ROOT_URL) + skin_settings['LOCAL_LOGIN_ICON']
LIVESETTINGS_OPTIONS[1]['SETTINGS']['LOGIN_PROVIDERS']['WORDPRESS_SITE_ICON'] = unicode(MITX_ROOT_URL) + LIVESETTINGS_OPTIONS[1]['SETTINGS']['LOGIN_PROVIDERS']['WORDPRESS_SITE_ICON']
LIVESETTINGS_OPTIONS[1]['SETTINGS']['LICENSE_SETTINGS']['LICENSE_LOGO_URL'] = unicode(MITX_ROOT_URL) + LIVESETTINGS_OPTIONS[1]['SETTINGS']['LICENSE_SETTINGS']['LICENSE_LOGO_URL']

Matthew Mongeau committed
202 203
# ASKBOT_EXTRA_SKINS_DIR = ASKBOT_ROOT / "askbot" / "skins"
ASKBOT_EXTRA_SKINS_DIR =  PROJECT_ROOT / "askbot" / "skins"
204
ASKBOT_ALLOWED_UPLOAD_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.tiff')
205
ASKBOT_MAX_UPLOAD_FILE_SIZE = 1024 * 1024 # result in bytes
206

207 208
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
ASKBOT_URL = 'discussion/'
209 210
LOGIN_REDIRECT_URL = MITX_ROOT_URL + '/'
LOGIN_URL = MITX_ROOT_URL + '/'
211

212 213 214
ALLOW_UNICODE_SLUGS = False
ASKBOT_USE_STACKEXCHANGE_URLS = False # mimic url scheme of stackexchange
ASKBOT_CSS_DEVEL = True
215 216 217 218 219

# Celery Settings
BROKER_TRANSPORT = "djkombu.transport.DatabaseTransport"
CELERY_ALWAYS_EAGER = True
djcelery.setup_loader()
Piotr Mitros committed
220

221
################################# SIMPLEWIKI ###################################
222 223
SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True
SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False
224

225
################################# Jasmine ###################################
226
JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee'
227

228 229 230 231
################################# Middleware ###################################
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
232 233
    'staticfiles.finders.FileSystemFinder',
    'staticfiles.finders.AppDirectoriesFinder',
234 235 236 237 238 239 240 241 242 243 244 245
)

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'askbot.skins.loaders.filesystem_load_template_source',
    # 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'util.middleware.ExceptionLoggingMiddleware',
246
    'django.middleware.cache.UpdateCacheMiddleware',
247 248 249
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
250 251

    # Instead of AuthenticationMiddleware, we use a cached backed version
252 253
    #'django.contrib.auth.middleware.AuthenticationMiddleware',
    'cache_toolbox.middleware.CacheBackedAuthenticationMiddleware',
254
    
255 256 257
    'django.contrib.messages.middleware.MessageMiddleware',
    'track.middleware.TrackMiddleware',
    'mitxmako.middleware.MakoMiddleware',
258

259 260 261 262 263 264 265
    'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
    'askbot.middleware.forum_mode.ForumModeMiddleware',
    'askbot.middleware.cancel.CancelActionMiddleware',
    'django.middleware.transaction.TransactionMiddleware',
    'askbot.middleware.view_log.ViewLogMiddleware',
    'askbot.middleware.spaceless.SpacelessMiddleware',
    # 'askbot.middleware.pagesize.QuestionsPageSizeMiddleware',
266
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
267 268
)

269 270 271 272 273 274
############################### Pipeline #######################################

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

PIPELINE_CSS = {
    'application': {
275
        'source_filenames': ['sass/application.scss'],
276 277 278
        'output_filename': 'css/application.css',
    },
    'marketing': {
279
        'source_filenames': ['sass/marketing.scss'],
280 281 282
        'output_filename': 'css/marketing.css',
    },
    'marketing-ie': {
283
        'source_filenames': ['sass/marketing-ie.scss'],
284 285 286
        'output_filename': 'css/marketing-ie.css',
    },
    'print': {
287
        'source_filenames': ['sass/print.scss'],
288 289 290 291
        'output_filename': 'css/print.css',
    }
}

292 293
PIPELINE_ALWAYS_RECOMPILE = ['sass/application.scss', 'sass/marketing.scss', 'sass/marketing-ie.scss', 'sass/print.scss']

294 295
PIPELINE_JS = {
    'application': {
296
        'source_filenames': [pth.replace(PROJECT_ROOT / 'static/', '') for pth in glob2.glob(PROJECT_ROOT / 'static/coffee/src/**/*.coffee')],
297
        'output_filename': 'js/application.js'
298 299
    },
    'spec': {
300
        'source_filenames': [pth.replace(PROJECT_ROOT / 'static/', '') for pth in glob2.glob(PROJECT_ROOT / 'static/coffee/spec/**/*.coffee')],
301
        'output_filename': 'js/spec.js'
302 303 304
    }
}

305
PIPELINE_COMPILERS = [
306 307
    'pipeline.compilers.sass.SASSCompiler',
    'pipeline.compilers.coffee.CoffeeScriptCompiler',
308 309
]

310
PIPELINE_SASS_ARGUMENTS = '-t compressed -r {proj_dir}/static/sass/bourbon/lib/bourbon.rb'.format(proj_dir=PROJECT_ROOT)
311 312

PIPELINE_CSS_COMPRESSOR = None
313
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
314

315
STATICFILES_IGNORE_PATTERNS = (
316 317
    "sass/*",
    "coffee/*",
318
    "*.py",
319
    "*.pyc"
320 321
)

322 323 324
PIPELINE_YUI_BINARY = 'yui-compressor'
PIPELINE_SASS_BINARY = 'sass'
PIPELINE_COFFEE_SCRIPT_BINARY = 'coffee'
325

326 327 328
# Setting that will only affect the MITx version of django-pipeline until our changes are merged upstream
PIPELINE_COMPILE_INPLACE = True

329
################################### APPS #######################################
330 331 332 333 334 335 336 337 338 339
INSTALLED_APPS = (
    # Standard ones that are always installed...
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.humanize',
    'django.contrib.messages',
    'django.contrib.sessions',
    'django.contrib.sites',
    'south',

340 341 342 343
    # For asset pipelining
    'pipeline',
    'staticfiles',

344 345 346 347 348 349 350 351 352 353 354
    # Our courseware
    'circuit',
    'courseware',
    'perfstats',
    'student',
    'static_template_view',
    'staticbook',
    'simplewiki',
    'track',
    'util',

355 356 357
    # For testing
    'django_jasmine',

358 359 360 361 362 363 364 365 366 367
    # For Askbot 
    'django.contrib.sitemaps',
    'django.contrib.admin',
    'django_countries',
    'djcelery',
    'djkombu',
    'askbot',
    'askbot.deps.livesettings',
    'followit',
    'keyedcache',
Matthew Mongeau committed
368
    'robots'
369
)