PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/funfactory/settings_base.py

https://github.com/kumar303/funfactory
Python | 311 lines | 164 code | 56 blank | 91 comment | 14 complexity | 217b955cca42c5ffdb33fb7c10c62fb2 MD5 | raw file
  1. # Django settings file for a project based on the playdoh template.
  2. # import * into your settings_local.py
  3. import logging
  4. import os
  5. import socket
  6. from django.utils.functional import lazy
  7. from .manage import ROOT, path
  8. # For backwards compatability, (projects built based on cloning playdoh)
  9. # we still have to have a ROOT_URLCONF.
  10. # For new-style playdoh projects this will be overridden automatically
  11. # by the new installer
  12. ROOT_URLCONF = '%s.urls' % os.path.basename(ROOT)
  13. # Is this a dev instance?
  14. DEV = False
  15. DEBUG = False
  16. TEMPLATE_DEBUG = DEBUG
  17. ADMINS = ()
  18. MANAGERS = ADMINS
  19. DATABASES = {} # See settings_local.
  20. SLAVE_DATABASES = []
  21. DATABASE_ROUTERS = ('multidb.PinningMasterSlaveRouter',)
  22. # Site ID is used by Django's Sites framework.
  23. SITE_ID = 1
  24. ## Logging
  25. LOG_LEVEL = logging.INFO
  26. HAS_SYSLOG = True
  27. SYSLOG_TAG = "http_app_playdoh" # Change this after you fork.
  28. LOGGING_CONFIG = None
  29. LOGGING = {}
  30. # CEF Logging
  31. CEF_PRODUCT = 'Playdoh'
  32. CEF_VENDOR = 'Mozilla'
  33. CEF_VERSION = '0'
  34. CEF_DEVICE_VERSION = '0'
  35. ## Internationalization.
  36. # Local time zone for this installation. Choices can be found here:
  37. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  38. # although not all choices may be available on all operating systems.
  39. # On Unix systems, a value of None will cause Django to use the same
  40. # timezone as the operating system.
  41. # If running in a Windows environment this must be set to the same as your
  42. # system time zone.
  43. TIME_ZONE = 'America/Los_Angeles'
  44. # If you set this to False, Django will make some optimizations so as not
  45. # to load the internationalization machinery.
  46. USE_I18N = True
  47. # If you set this to False, Django will not format dates, numbers and
  48. # calendars according to the current locale
  49. USE_L10N = True
  50. # Gettext text domain
  51. TEXT_DOMAIN = 'messages'
  52. STANDALONE_DOMAINS = [TEXT_DOMAIN, 'javascript']
  53. TOWER_KEYWORDS = {'_lazy': None}
  54. TOWER_ADD_HEADERS = True
  55. # Language code for this installation. All choices can be found here:
  56. # http://www.i18nguy.com/unicode/language-identifiers.html
  57. LANGUAGE_CODE = 'en-US'
  58. ## Accepted locales
  59. # Tells the product_details module where to find our local JSON files.
  60. # This ultimately controls how LANGUAGES are constructed.
  61. PROD_DETAILS_DIR = path('lib/product_details_json')
  62. # On dev instances, the list of accepted locales defaults to the contents of
  63. # the `locale` directory within a project module or, for older Playdoh apps,
  64. # the root locale directory. A localizer can add their locale in the l10n
  65. # repository (copy of which is checked out into `locale`) in order to start
  66. # testing the localization on the dev server.
  67. import glob
  68. import itertools
  69. try:
  70. DEV_LANGUAGES = [
  71. os.path.basename(loc).replace('_', '-')
  72. for loc in itertools.chain(glob.iglob(ROOT + '/locale/*'), # old style
  73. glob.iglob(ROOT + '/*/locale/*'))
  74. if (os.path.isdir(loc) and os.path.basename(loc) != 'templates')
  75. ]
  76. except OSError:
  77. DEV_LANGUAGES = ('en-US',)
  78. # On stage/prod, the list of accepted locales is manually maintained. Only
  79. # locales whose localizers have signed off on their work should be listed here.
  80. PROD_LANGUAGES = (
  81. 'en-US',
  82. )
  83. def lazy_lang_url_map():
  84. from django.conf import settings
  85. langs = settings.DEV_LANGUAGES if settings.DEV else settings.PROD_LANGUAGES
  86. return dict([(i.lower(), i) for i in langs])
  87. LANGUAGE_URL_MAP = lazy(lazy_lang_url_map, dict)()
  88. # Override Django's built-in with our native names
  89. def lazy_langs():
  90. from django.conf import settings
  91. from product_details import product_details
  92. langs = DEV_LANGUAGES if settings.DEV else settings.PROD_LANGUAGES
  93. return dict([(lang.lower(), product_details.languages[lang]['native'])
  94. for lang in langs if lang in product_details.languages])
  95. LANGUAGES = lazy(lazy_langs, dict)()
  96. # Tells the extract script what files to look for L10n in and what function
  97. # handles the extraction. The Tower library expects this.
  98. DOMAIN_METHODS = {
  99. 'messages': [
  100. # Searching apps dirs only exists for historic playdoh apps.
  101. # See playdoh's base settings for how message paths are set.
  102. ('apps/**.py',
  103. 'tower.management.commands.extract.extract_tower_python'),
  104. ('apps/**/templates/**.html',
  105. 'tower.management.commands.extract.extract_tower_template'),
  106. ('templates/**.html',
  107. 'tower.management.commands.extract.extract_tower_template'),
  108. ],
  109. }
  110. # Paths that don't require a locale code in the URL.
  111. SUPPORTED_NONLOCALES = ['media', 'static', 'admin']
  112. ## Media and templates.
  113. # Absolute path to the directory that holds media.
  114. # Example: "/home/media/media.lawrence.com/"
  115. MEDIA_ROOT = path('media')
  116. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  117. # trailing slash if there is a path component (optional in other cases).
  118. # Examples: "http://media.lawrence.com", "http://example.com/media/"
  119. MEDIA_URL = '/media/'
  120. # Absolute path to the directory static files should be collected to.
  121. # Don't put anything in this directory yourself; store your static files
  122. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  123. # Example: "/home/media/media.lawrence.com/static/"
  124. STATIC_ROOT = path('static')
  125. # URL prefix for static files.
  126. # Example: "http://media.lawrence.com/static/"
  127. STATIC_URL = '/static/'
  128. # Make this unique, and don't share it with anybody.
  129. # Set this in your local settings which is not committed to version control.
  130. SECRET_KEY = ''
  131. # List of callables that know how to import templates from various sources.
  132. TEMPLATE_LOADERS = (
  133. 'jingo.Loader',
  134. 'django.template.loaders.filesystem.Loader',
  135. 'django.template.loaders.app_directories.Loader',
  136. )
  137. TEMPLATE_CONTEXT_PROCESSORS = (
  138. 'django.contrib.auth.context_processors.auth',
  139. 'django.core.context_processors.debug',
  140. 'django.core.context_processors.media',
  141. 'django.core.context_processors.request',
  142. 'session_csrf.context_processor',
  143. 'django.contrib.messages.context_processors.messages',
  144. 'funfactory.context_processors.i18n',
  145. 'funfactory.context_processors.globals',
  146. #'jingo_minify.helpers.build_ids',
  147. )
  148. TEMPLATE_DIRS = (
  149. path('templates'),
  150. )
  151. def JINJA_CONFIG():
  152. import jinja2
  153. from django.conf import settings
  154. # from caching.base import cache
  155. config = {'extensions': ['tower.template.i18n', 'jinja2.ext.do',
  156. 'jinja2.ext.with_', 'jinja2.ext.loopcontrols'],
  157. 'finalize': lambda x: x if x is not None else ''}
  158. # if 'memcached' in cache.scheme and not settings.DEBUG:
  159. # We're passing the _cache object directly to jinja because
  160. # Django can't store binary directly; it enforces unicode on it.
  161. # Details: http://jinja.pocoo.org/2/documentation/api#bytecode-cache
  162. # and in the errors you get when you try it the other way.
  163. # bc = jinja2.MemcachedBytecodeCache(cache._cache,
  164. # "%sj2:" % settings.CACHE_PREFIX)
  165. # config['cache_size'] = -1 # Never clear the cache
  166. # config['bytecode_cache'] = bc
  167. return config
  168. ## Middlewares, apps, URL configs.
  169. MIDDLEWARE_CLASSES = (
  170. 'funfactory.middleware.LocaleURLMiddleware',
  171. 'multidb.middleware.PinningRouterMiddleware',
  172. 'django.middleware.common.CommonMiddleware',
  173. 'django.contrib.sessions.middleware.SessionMiddleware',
  174. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  175. 'session_csrf.CsrfMiddleware', # Must be after auth middleware.
  176. 'django.contrib.messages.middleware.MessageMiddleware',
  177. 'commonware.middleware.FrameOptionsHeader',
  178. 'mobility.middleware.DetectMobileMiddleware',
  179. 'mobility.middleware.XMobileMiddleware',
  180. )
  181. INSTALLED_APPS = (
  182. # Local apps
  183. 'funfactory', # Content common to most playdoh-based apps.
  184. 'jingo_minify',
  185. 'tower', # for ./manage.py extract (L10n)
  186. 'cronjobs', # for ./manage.py cron * cmd line tasks
  187. 'django_browserid',
  188. # Django contrib apps
  189. 'django.contrib.auth',
  190. 'django.contrib.contenttypes',
  191. 'django.contrib.sessions',
  192. 'django.contrib.staticfiles',
  193. # 'django.contrib.sites',
  194. # 'django.contrib.messages',
  195. # Uncomment the next line to enable the admin:
  196. # 'django.contrib.admin',
  197. # Uncomment the next line to enable admin documentation:
  198. # 'django.contrib.admindocs',
  199. # Third-party apps, patches, fixes
  200. 'commonware.response.cookies',
  201. 'djcelery',
  202. 'django_nose',
  203. 'session_csrf',
  204. # L10n
  205. 'product_details',
  206. )
  207. # Path to Java. Used for compress_assets.
  208. JAVA_BIN = '/usr/bin/java'
  209. # Sessions
  210. #
  211. # By default, be at least somewhat secure with our session cookies.
  212. SESSION_COOKIE_HTTPONLY = True
  213. ## Auth
  214. BASE_PASSWORD_HASHERS = (
  215. # recommended: 'django_sha2.hashers.BcryptHMACCombinedPasswordVerifier',
  216. #'django_sha2.hashers.SHA512PasswordHasher',
  217. 'django_sha2.hashers.SHA256PasswordHasher',
  218. 'django.contrib.auth.hashers.SHA1PasswordHasher',
  219. 'django.contrib.auth.hashers.MD5PasswordHasher',
  220. 'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher',
  221. )
  222. HMAC_KEYS = { # for bcrypt only
  223. #'2011-01-01': 'cheesecake',
  224. }
  225. from django_sha2 import get_password_hashers
  226. PASSWORD_HASHERS = get_password_hashers(BASE_PASSWORD_HASHERS, HMAC_KEYS)
  227. ## Tests
  228. TEST_RUNNER = 'test_utils.runner.RadicalTestSuiteRunner'
  229. ## Celery
  230. # True says to simulate background tasks without actually using celeryd.
  231. # Good for local development in case celeryd is not running.
  232. CELERY_ALWAYS_EAGER = True
  233. BROKER_CONNECTION_TIMEOUT = 0.1
  234. CELERY_RESULT_BACKEND = 'amqp'
  235. CELERY_IGNORE_RESULT = True
  236. CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
  237. # Time in seconds before celery.exceptions.SoftTimeLimitExceeded is raised.
  238. # The task can catch that and recover but should exit ASAP.
  239. CELERYD_TASK_SOFT_TIME_LIMIT = 60 * 2
  240. ## Arecibo
  241. # when ARECIBO_SERVER_URL is set, it can use celery or the regular wrapper
  242. ARECIBO_USES_CELERY = True
  243. # For absolute urls
  244. try:
  245. DOMAIN = socket.gethostname()
  246. except socket.error:
  247. DOMAIN = 'localhost'
  248. PROTOCOL = "http://"
  249. PORT = 80
  250. ## django-mobility
  251. MOBILE_COOKIE = 'mobile'