common.py 17.5 KB
Newer Older
1
# -*- coding: utf-8 -*-
2 3 4 5
"""
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
6
FEATURES[...]. Modules that extend this one can change the feature
7 8 9 10 11 12 13 14 15 16 17
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
make one call at the end of your site-specific dev file to reset all the
dependent variables (like INSTALLED_APPS) for you.

Longer TODO:
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
18
   just means that we stick them in a dict called FEATURES.
19 20 21 22
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.
"""

23 24
# We intentionally define lots of variables that aren't used, and
# want to import all variables from base settings files
25
# pylint: disable=W0401, W0611, W0614
26

27
import imp
28
import sys
29
import lms.envs.common
30
from lms.envs.common import (
31
    USE_TZ, TECH_SUPPORT_EMAIL, PLATFORM_NAME, BUGS_EMAIL, DOC_STORE_CONFIG, ALL_LANGUAGES, WIKI_ENABLED
32
)
33 34
from path import path

35
from lms.lib.xblock.mixin import LmsBlockMixin
36
from cms.lib.xblock.mixin import CmsBlockMixin
37
from dealer.git import git
Calen Pennington committed
38

39 40
############################ FEATURE CONFIGURATION #############################

41
FEATURES = {
42
    'USE_DJANGO_PIPELINE': True,
David Baumgold committed
43

44
    'GITHUB_PUSH': False,
David Baumgold committed
45

46 47
    # for consistency in user-experience, keep the value of the following 3 settings
    # in sync with the ones in lms/envs/common.py
48
    'ENABLE_DISCUSSION_SERVICE': True,
49 50
    'ENABLE_TEXTBOOK': True,
    'ENABLE_STUDENT_NOTES': True,
David Baumgold committed
51

52
    'AUTH_USE_CERTIFICATES': False,
David Baumgold committed
53

54 55
    # email address for studio staff (eg to request course creation)
    'STUDIO_REQUEST_EMAIL': '',
David Baumgold committed
56

57
    'STUDIO_NPS_SURVEY': True,
David Baumgold committed
58

59 60
    # Segment.io - must explicitly turn it on for production
    'SEGMENT_IO': False,
61

62
    # Enable URL that shows information about the status of various services
63 64
    'ENABLE_SERVICE_STATUS': False,

65
    # Don't autoplay videos for course authors
66 67 68 69
    'AUTOPLAY_VIDEOS': False,

    # If set to True, new Studio users won't be able to author courses unless
    # edX has explicitly added them to the course creator group.
70
    'ENABLE_CREATOR_GROUP': False,
71

72 73 74
    # whether to use password policy enforcement or not
    'ENFORCE_PASSWORD_POLICY': False,

75 76 77
    # If set to True, Studio won't restrict the set of advanced components
    # to just those pre-approved by edX
    'ALLOW_ALL_ADVANCED_COMPONENTS': False,
78 79 80

    # Turn off account locking if failed login attempts exceeds a limit
    'ENABLE_MAX_FAILED_LOGIN_ATTEMPTS': False,
81 82 83

    # Allow editing of short description in course settings in cms
    'EDITABLE_SHORT_DESCRIPTION': True,
84 85 86

    # Hide any Personally Identifiable Information from application logs
    'SQUELCH_PII_IN_LOGS': False,
87

88 89
    # Toggles embargo functionality
    'EMBARGO': False,
90 91 92

    # Turn on/off Microsites feature
    'USE_MICROSITES': False,
93 94 95

    # Allow creating courses with non-ascii characters in the course id
    'ALLOW_UNICODE_COURSE_ID': False,
96 97 98

    # Prevent concurrent logins per user
    'PREVENT_CONCURRENT_LOGINS': False,
99 100 101

    # Turn off Advanced Security by default
    'ADVANCED_SECURITY': False,
102 103 104 105 106 107

    # Temporary feature flag for duplicating xblock leaves
    'ENABLE_DUPLICATE_XBLOCK_LEAF_COMPONENT': False,

    # Temporary feature flag for deleting xblock leaves
    'ENABLE_DELETE_XBLOCK_LEAF_COMPONENT': False,
108
}
109
ENABLE_JASMINE = False
110

111

112
############################# SET PATH INFORMATION #############################
113
PROJECT_ROOT = path(__file__).abspath().dirname().dirname()  # /edx-platform/cms
114 115
REPO_ROOT = PROJECT_ROOT.dirname()
COMMON_ROOT = REPO_ROOT / "common"
116
LMS_ROOT = REPO_ROOT / "lms"
117
ENV_ROOT = REPO_ROOT.dirname()  # virtualenv dir /edx-platform is in
118

119
GITHUB_REPO_ROOT = ENV_ROOT / "data"
120

121
sys.path.append(REPO_ROOT)
122 123 124 125
sys.path.append(PROJECT_ROOT / 'djangoapps')
sys.path.append(COMMON_ROOT / 'djangoapps')
sys.path.append(COMMON_ROOT / 'lib')

126 127 128
# For geolocation ip database
GEOIP_PATH = REPO_ROOT / "common/static/data/geoip/GeoIP.dat"

129 130 131

############################# WEB CONFIGURATION #############################
# This is where we stick our compiled template files.
132 133
from tempdir import mkdtemp_clean
MAKO_MODULE_DIR = mkdtemp_clean('mako')
134
MAKO_TEMPLATES = {}
135 136
MAKO_TEMPLATES['main'] = [
    PROJECT_ROOT / 'templates',
137
    COMMON_ROOT / 'templates',
138 139
    COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates',
    COMMON_ROOT / 'djangoapps' / 'pipeline_js' / 'templates',
140
]
141

142 143 144
for namespace, template_dirs in lms.envs.common.MAKO_TEMPLATES.iteritems():
    MAKO_TEMPLATES['lms.' + namespace] = template_dirs

145
TEMPLATE_DIRS = MAKO_TEMPLATES['main']
146

147
EDX_ROOT_URL = ''
148

149 150
LOGIN_REDIRECT_URL = EDX_ROOT_URL + '/signin'
LOGIN_URL = EDX_ROOT_URL + '/signin'
151 152


153 154 155 156
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'django.core.context_processors.static',
    'django.contrib.messages.context_processors.messages',
157
    'django.core.context_processors.i18n',
158
    'django.contrib.auth.context_processors.auth',  # this is required for admin
159 160
    'django.core.context_processors.csrf',
    'dealer.contrib.django.staff.context_processor',  # access git revision
161
    'contentstore.context_processors.doc_url',
162 163
)

Diana Huang committed
164 165 166 167 168
# use the ratelimit backend to prevent brute force attacks
AUTHENTICATION_BACKENDS = (
    'ratelimitbackend.backends.RateLimitModelBackend',
)

169 170
LMS_BASE = None

171 172 173
#################### CAPA External Code Evaluation #############################
XQUEUE_INTERFACE = {
    'url': 'http://localhost:8888',
174 175 176
    'django_auth': {'username': 'local',
                    'password': 'local'},
    'basic_auth': None,
177 178 179
}


180 181 182 183
################################# Middleware ###################################
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
184 185
    'staticfiles.finders.FileSystemFinder',
    'staticfiles.finders.AppDirectoriesFinder',
Will Daly committed
186
    'pipeline.finders.PipelineFinder',
187 188 189 190 191 192 193 194 195
)

# 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',
)

MIDDLEWARE_CLASSES = (
196
    'request_cache.middleware.RequestCache',
197 198
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
199
    'django.middleware.csrf.CsrfViewMiddleware',
200
    'django.contrib.sessions.middleware.SessionMiddleware',
201
    'method_override.middleware.MethodOverrideMiddleware',
202

203
    # Instead of AuthenticationMiddleware, we use a cache-backed version
204
    'cache_toolbox.middleware.CacheBackedAuthenticationMiddleware',
205
    'student.middleware.UserStandingMiddleware',
206
    'contentserver.middleware.StaticContentServer',
207
    'crum.CurrentRequestUserMiddleware',
208 209 210

    'django.contrib.messages.middleware.MessageMiddleware',
    'track.middleware.TrackMiddleware',
211

212 213 214
    # Allows us to dark-launch particular languages
    'dark_lang.middleware.DarkLangMiddleware',

215 216
    'embargo.middleware.EmbargoMiddleware',

217
    # Detects user-requested locale from 'accept-language' header in http request
Steve Strassmann committed
218
    'django.middleware.locale.LocaleMiddleware',
219

Diana Huang committed
220
    'django.middleware.transaction.TransactionMiddleware',
221 222
    # needs to run after locale middleware (or anything that modifies the request context)
    'edxmako.middleware.MakoMiddleware',
Diana Huang committed
223 224 225

    # catches any uncaught RateLimitExceptions and returns a 403 instead of a 500
    'ratelimitbackend.middleware.RateLimitMiddleware',
226 227 228

    # for expiring inactive sessions
    'session_inactivity_timeout.middleware.SessionInactivityTimeout',
229 230 231

    # use Django built in clickjacking protection
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
232 233
)

234 235 236
# Clickjacking protection can be enabled by setting this to 'DENY'
X_FRAME_OPTIONS = 'ALLOW'

Calen Pennington committed
237 238
############# XBlock Configuration ##########

239 240 241 242 243
# Import after sys.path fixup
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore import prefer_xmodules
from xmodule.x_module import XModuleMixin

Calen Pennington committed
244 245
# This should be moved into an XBlock Runtime/Application object
# once the responsibility of XBlock creation is moved out of modulestore - cpennington
246
XBLOCK_MIXINS = (LmsBlockMixin, CmsBlockMixin, InheritanceMixin, XModuleMixin)
Calen Pennington committed
247

248
# Allow any XBlock in Studio
249 250
# You should also enable the ALLOW_ALL_ADVANCED_COMPONENTS feature flag, so that
# xblocks can be added via advanced settings
251
XBLOCK_SELECT_FUNCTION = prefer_xmodules
Calen Pennington committed
252

253 254 255 256 257 258 259
############################ DJANGO_BUILTINS ################################
# Change DEBUG/TEMPLATE_DEBUG in your environment settings files, not here
DEBUG = False
TEMPLATE_DEBUG = False

# Site info
SITE_ID = 1
260
SITE_NAME = "localhost:8001"
261
HTTPS = 'on'
262
ROOT_URLCONF = 'cms.urls'
263 264 265 266
IGNORABLE_404_ENDS = ('favicon.ico')

# Email
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
267 268 269 270 271
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
272 273 274
DEFAULT_FROM_EMAIL = 'registration@example.com'
DEFAULT_FEEDBACK_EMAIL = 'feedback@example.com'
SERVER_EMAIL = 'devops@example.com'
275
ADMINS = ()
276 277 278
MANAGERS = ADMINS

# Static content
279
STATIC_URL = '/static/' + git.revision + "/"
280
ADMIN_MEDIA_PREFIX = '/static/admin/'
281
STATIC_ROOT = ENV_ROOT / "staticfiles" / git.revision
282 283

STATICFILES_DIRS = [
284
    COMMON_ROOT / "static",
285
    PROJECT_ROOT / "static",
286
    LMS_ROOT / "static",
287

Diana Huang committed
288
    # This is how you would use the textbook images locally
289
    # ("book", ENV_ROOT / "book_images"),
290 291 292 293
]

# Locale/Internationalization
TIME_ZONE = 'America/New_York'  # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
294
LANGUAGE_CODE = 'en'  # http://www.i18nguy.com/unicode/language-identifiers.html
Steve Strassmann committed
295

296
LANGUAGES = lms.envs.common.LANGUAGES
297
USE_I18N = True
298 299
USE_L10N = True

Steve Strassmann committed
300
# Localization strings (e.g. django.po) are under this directory
301
LOCALE_PATHS = (REPO_ROOT + '/conf/locale',)  # edx-platform/conf/locale/
Steve Strassmann committed
302

303 304 305
# Messages
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'

306 307 308 309
############################### Pipeline #######################################

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

310
from rooted_paths import rooted_glob
311 312

PIPELINE_CSS = {
313
    'style-vendor': {
314
        'source_filenames': [
315 316
            'css/vendor/normalize.css',
            'css/vendor/font-awesome.css',
317
            'css/vendor/html5-input-polyfills/number-polyfill.css',
318
            'js/vendor/CodeMirror/codemirror.css',
319 320
            'css/vendor/ui-lightness/jquery-ui-1.8.22.custom.css',
            'css/vendor/jquery.qtip.min.css',
321
            'js/vendor/markitup/skins/simple/style.css',
322
            'js/vendor/markitup/sets/wiki/style.css'
323
        ],
324 325
        'output_filename': 'css/cms-style-vendor.css',
    },
326 327
    'style-vendor-tinymce-content': {
        'source_filenames': [
328
            'css/tinymce-studio-content-fonts.css',
329 330 331 332 333 334 335 336 337 338 339
            'js/vendor/tinymce/js/tinymce/skins/studio-tmce4/content.min.css',
            'css/tinymce-studio-content.css'
        ],
        'output_filename': 'css/cms-style-vendor-tinymce-content.css',
    },
    'style-vendor-tinymce-skin': {
        'source_filenames': [
            'js/vendor/tinymce/js/tinymce/skins/studio-tmce4/skin.min.css'
        ],
        'output_filename': 'css/cms-style-vendor-tinymce-skin.css',
    },
340 341 342 343 344 345
    'style-app': {
        'source_filenames': [
            'sass/style-app.css',
        ],
        'output_filename': 'css/cms-style-app.css',
    },
346 347 348 349 350 351
    'style-app-extend1': {
        'source_filenames': [
            'sass/style-app-extend1.css',
        ],
        'output_filename': 'css/cms-style-app-extend1.css',
    },
352 353 354 355 356
    'style-xmodule': {
        'source_filenames': [
            'sass/style-xmodule.css',
        ],
        'output_filename': 'css/cms-style-xmodule.css',
357 358 359
    },
}

360 361
# test_order: Determines the position of this chunk of javascript on
# the jasmine test page
362
PIPELINE_JS = {
363
    'module-js': {
364 365
        'source_filenames': (
            rooted_glob(COMMON_ROOT / 'static/', 'xmodule/descriptors/js/*.js') +
366 367
            rooted_glob(COMMON_ROOT / 'static/', 'xmodule/modules/js/*.js') +
            rooted_glob(COMMON_ROOT / 'static/', 'coffee/src/discussion/*.js')
368
        ),
369
        'output_filename': 'js/cms-modules.js',
370
        'test_order': 1
371
    },
372 373
}

374 375 376 377
PIPELINE_COMPILERS = (
    'pipeline.compilers.coffee.CoffeeScriptCompiler',
)

378
PIPELINE_CSS_COMPRESSOR = None
379
PIPELINE_JS_COMPRESSOR = None
380 381 382 383

STATICFILES_IGNORE_PATTERNS = (
    "*.py",
    "*.pyc"
384 385 386 387 388 389 390 391 392 393 394 395
    # it would be nice if we could do, for example, "**/*.scss",
    # but these strings get passed down to the `fnmatch` module,
    # which doesn't support that. :(
    # http://docs.python.org/2/library/fnmatch.html
    "sass/*.scss",
    "sass/*/*.scss",
    "sass/*/*/*.scss",
    "sass/*/*/*/*.scss",
    "coffee/*.coffee",
    "coffee/*/*.coffee",
    "coffee/*/*/*.coffee",
    "coffee/*/*/*/*.coffee",
396 397 398 399

    # Symlinks used by js-test-tool
    "xmodule_js",
    "common_static",
400 401 402 403
)

PIPELINE_YUI_BINARY = 'yui-compressor'

404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
################################# CELERY ######################################

# Message configuration

CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CELERY_MESSAGE_COMPRESSION = 'gzip'

# Results configuration

CELERY_IGNORE_RESULT = False
CELERY_STORE_ERRORS_EVEN_IF_IGNORED = True

# Events configuration

CELERY_TRACK_STARTED = True

CELERY_SEND_EVENTS = True
CELERY_SEND_TASK_SENT_EVENT = True

# Exchange configuration

CELERY_DEFAULT_EXCHANGE = 'edx.core'
CELERY_DEFAULT_EXCHANGE_TYPE = 'direct'

# Queues configuration

HIGH_PRIORITY_QUEUE = 'edx.core.high'
DEFAULT_PRIORITY_QUEUE = 'edx.core.default'
LOW_PRIORITY_QUEUE = 'edx.core.low'

CELERY_QUEUE_HA_POLICY = 'all'

CELERY_CREATE_MISSING_QUEUES = True

CELERY_DEFAULT_QUEUE = DEFAULT_PRIORITY_QUEUE
CELERY_DEFAULT_ROUTING_KEY = DEFAULT_PRIORITY_QUEUE

CELERY_QUEUES = {
    HIGH_PRIORITY_QUEUE: {},
    LOW_PRIORITY_QUEUE: {},
    DEFAULT_PRIORITY_QUEUE: {}
}

449 450 451

############################## Video ##########################################

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
YOUTUBE = {
    # YouTube JavaScript API
    'API': 'www.youtube.com/iframe_api',

    # URL to test YouTube availability
    'TEST_URL': 'gdata.youtube.com/feeds/api/videos/',

    # Current youtube api for requesting transcripts.
    # For example: http://video.google.com/timedtext?lang=en&v=j_jEn79vS3g.
    'TEXT_API': {
        'url': 'video.google.com/timedtext',
        'params': {
            'lang': 'en',
            'v': 'set_youtube_id_of_11_symbols_here',
        },
    },
}
469

470 471 472
############################ APPS #####################################

INSTALLED_APPS = (
473
    # Standard apps
474 475 476 477 478
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
479
    'djcelery',
480
    'south',
481
    'method_override',
482

483 484 485
    # Database-backed configuration
    'config_models',

486 487 488
    # Monitor the status of services
    'service_status',

489 490 491
    # Testing
    'django_nose',

492
    # For CMS
493
    'contentstore',
cahrens committed
494
    'course_creators',
495
    'student',  # misleading name due to sharing with lms
Victor Shnayder committed
496
    'course_groups',  # not used in cms (yet), but tests run
497

498
    # Tracking
499
    'track',
500
    'eventtracking.django',
501

502 503 504
    # Monitoring
    'datadog',

505
    # For asset pipelining
David Baumgold committed
506
    'edxmako',
507 508
    'pipeline',
    'staticfiles',
509
    'static_replace',
Chris Dodge committed
510 511 512

    # comment common
    'django_comment_common',
cahrens committed
513 514

    # for course creator table
515 516 517
    'django.contrib.admin',

    # for managing course modes
518 519 520 521
    'course_modes',

    # Dark-launching languages
    'dark_lang',
522

523 524
    # Student identity reverification
    'reverification',
525 526 527

    # User preferences
    'user_api',
528
    'django_openid_auth',
529 530

    'embargo',
531 532 533

    # Monitoring signals
    'monitoring',
534
)
535

536

537 538 539
################# EDX MARKETING SITE ##################################

EDXMKTG_COOKIE_NAME = 'edxloggedin'
540 541
MKTG_URLS = {}
MKTG_URL_LINK_MAP = {
542

543
}
544 545

COURSES_WITH_UNSAFE_CODE = []
546 547 548 549 550 551 552 553 554 555 556 557 558

############################## EVENT TRACKING #################################

TRACK_MAX_EVENT = 10000

TRACKING_BACKENDS = {
    'logger': {
        'ENGINE': 'track.backends.logger.LoggerBackend',
        'OPTIONS': {
            'name': 'tracking'
        }
    }
}
559

560 561 562 563 564 565 566 567
#### PASSWORD POLICY SETTINGS #####

PASSWORD_MIN_LENGTH = None
PASSWORD_MAX_LENGTH = None
PASSWORD_COMPLEXITY = {}
PASSWORD_DICTIONARY_EDIT_DISTANCE_THRESHOLD = None
PASSWORD_DICTIONARY = []

568 569 570
# We're already logging events, and we don't want to capture user
# names/passwords.  Heartbeat events are likely not interesting.
TRACKING_IGNORE_URL_PATTERNS = [r'^/event', r'^/login', r'^/heartbeat']
571
TRACKING_ENABLED = True
572

573 574 575
##### ACCOUNT LOCKOUT DEFAULT PARAMETERS #####
MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = 5
MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS = 15 * 60
576 577


578 579 580 581 582
### Apps only installed in some instances

OPTIONAL_APPS = (
    'edx_jsdraw',
    'mentoring',
Will Daly committed
583 584 585 586 587 588 589

    # edx-ora2
    'submissions',
    'openassessment',
    'openassessment.assessment',
    'openassessment.workflow',
    'openassessment.xblock'
590
)
591

592

593 594 595 596 597 598 599 600 601 602 603 604
for app_name in OPTIONAL_APPS:
    # First attempt to only find the module rather than actually importing it,
    # to avoid circular references - only try to import if it can't be found
    # by find_module, which doesn't work with import hooks
    try:
        imp.find_module(app_name)
    except ImportError:
        try:
            __import__(app_name)
        except ImportError:
            continue
    INSTALLED_APPS += (app_name,)
605 606 607 608

### ADVANCED_SECURITY_CONFIG
# Empty by default
ADVANCED_SECURITY_CONFIG = {}