spacepaste

  1.  
  2. import os, json
  3. # a massive hack to see if we're testing, in which case we use different settings
  4. import sys
  5. TESTING = 'test' in sys.argv
  6. # go through environment variables and override them
  7. def get_from_env(var, default):
  8. if not TESTING and os.environ.has_key(var):
  9. return os.environ[var]
  10. else:
  11. return default
  12. DEBUG = (get_from_env('DEBUG', '1') == '1')
  13. TEMPLATE_DEBUG = DEBUG
  14. # add admins of the form:
  15. # ('Ben Adida', 'ben@adida.net'),
  16. # if you want to be emailed about errors.
  17. ADMINS = (
  18. )
  19. MANAGERS = ADMINS
  20. # is this the master Helios web site?
  21. MASTER_HELIOS = (get_from_env('MASTER_HELIOS', '0') == '1')
  22. # show ability to log in? (for example, if the site is mostly used by voters)
  23. # if turned off, the admin will need to know to go to /auth/login manually
  24. SHOW_LOGIN_OPTIONS = (get_from_env('SHOW_LOGIN_OPTIONS', '1') == '1')
  25. # sometimes, when the site is not that social, it's not helpful
  26. # to display who created the election
  27. SHOW_USER_INFO = (get_from_env('SHOW_USER_INFO', '1') == '1')
  28. DATABASES = {
  29. 'default': {
  30. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  31. 'NAME': 'helios'
  32. }
  33. }
  34. SOUTH_DATABASE_ADAPTERS = {'default':'south.db.postgresql_psycopg2'}
  35. # override if we have an env variable
  36. if get_from_env('DATABASE_URL', None):
  37. import dj_database_url
  38. DATABASES['default'] = dj_database_url.config()
  39. DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
  40. DATABASES['default']['CONN_MAX_AGE'] = 600
  41. # require SSL
  42. DATABASES['default']['OPTIONS'] = {'sslmode': 'require'}
  43. # Local time zone for this installation. Choices can be found here:
  44. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  45. # although not all choices may be available on all operating systems.
  46. # If running in a Windows environment this must be set to the same as your
  47. # system time zone.
  48. TIME_ZONE = 'America/Los_Angeles'
  49. # Language code for this installation. All choices can be found here:
  50. # http://www.i18nguy.com/unicode/language-identifiers.html
  51. LANGUAGE_CODE = 'en-us'
  52. SITE_ID = 1
  53. # If you set this to False, Django will make some optimizations so as not
  54. # to load the internationalization machinery.
  55. USE_I18N = True
  56. # Absolute path to the directory that holds media.
  57. # Example: "/home/media/media.lawrence.com/"
  58. MEDIA_ROOT = ''
  59. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  60. # trailing slash if there is a path component (optional in other cases).
  61. # Examples: "http://media.lawrence.com", "http://example.com/media/"
  62. MEDIA_URL = ''
  63. # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
  64. # trailing slash.
  65. # Examples: "http://foo.com/media/", "/media/".
  66. STATIC_URL = '/media/'
  67. # Make this unique, and don't share it with anybody.
  68. SECRET_KEY = get_from_env('SECRET_KEY', 'replaceme')
  69. # If debug is set to false and ALLOWED_HOSTS is not declared, django raises "CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False."
  70. # If in production, you got a bad request (400) error
  71. #More info: https://docs.djangoproject.com/en/1.7/ref/settings/#allowed-hosts (same for 1.6)
  72. ALLOWED_HOSTS = get_from_env('ALLOWED_HOSTS', 'localhost').split(",")
  73. # Secure Stuff
  74. if (get_from_env('SSL', '0') == '1'):
  75. SECURE_SSL_REDIRECT = True
  76. SESSION_COOKIE_SECURE = True
  77. # tuned for Heroku
  78. SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
  79. SESSION_COOKIE_HTTPONLY = True
  80. # let's go with one year because that's the way to do it now
  81. STS = False
  82. if (get_from_env('HSTS', '0') == '1'):
  83. STS = True
  84. # we're using our own custom middleware now
  85. # SECURE_HSTS_SECONDS = 31536000
  86. # not doing subdomains for now cause that is not likely to be necessary and can screw things up.
  87. # SECURE_HSTS_INCLUDE_SUBDOMAINS = True
  88. SECURE_BROWSER_XSS_FILTER = True
  89. SECURE_CONTENT_TYPE_NOSNIFF = True
  90. # List of callables that know how to import templates from various sources.
  91. TEMPLATE_LOADERS = (
  92. 'django.template.loaders.filesystem.Loader',
  93. 'django.template.loaders.app_directories.Loader'
  94. )
  95. MIDDLEWARE_CLASSES = (
  96. # make all things SSL
  97. #'sslify.middleware.SSLifyMiddleware',
  98. # secure a bunch of things
  99. 'djangosecure.middleware.SecurityMiddleware',
  100. 'helios.security.HSTSMiddleware',
  101. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  102. 'django.middleware.common.CommonMiddleware',
  103. 'django.contrib.sessions.middleware.SessionMiddleware',
  104. 'django.contrib.auth.middleware.AuthenticationMiddleware'
  105. )
  106. ROOT_URLCONF = 'urls'
  107. ROOT_PATH = os.path.dirname(__file__)
  108. TEMPLATE_DIRS = (
  109. ROOT_PATH,
  110. os.path.join(ROOT_PATH, 'templates')
  111. )
  112. INSTALLED_APPS = (
  113. # 'django.contrib.auth',
  114. # 'django.contrib.contenttypes',
  115. 'djangosecure',
  116. 'django.contrib.sessions',
  117. #'django.contrib.sites',
  118. ## needed for queues
  119. 'djcelery',
  120. 'kombu.transport.django',
  121. ## in Django 1.7 we now use built-in migrations, no more south
  122. ## 'south',
  123. ## HELIOS stuff
  124. 'helios_auth',
  125. 'helios',
  126. 'server_ui',
  127. )
  128. ##
  129. ## HELIOS
  130. ##
  131. MEDIA_ROOT = ROOT_PATH + "media/"
  132. # a relative path where voter upload files are stored
  133. VOTER_UPLOAD_REL_PATH = "voters/%Y/%m/%d"
  134. # Change your email settings
  135. DEFAULT_FROM_EMAIL = get_from_env('DEFAULT_FROM_EMAIL', 'ben@adida.net')
  136. DEFAULT_FROM_NAME = get_from_env('DEFAULT_FROM_NAME', 'Ben for Helios')
  137. SERVER_EMAIL = '%s <%s>' % (DEFAULT_FROM_NAME, DEFAULT_FROM_EMAIL)
  138. LOGIN_URL = '/auth/'
  139. LOGOUT_ON_CONFIRMATION = False
  140. # The two hosts are here so the main site can be over plain HTTP
  141. # while the voting URLs are served over SSL.
  142. URL_HOST = get_from_env("URL_HOST", "http://localhost:8000").rstrip("/")
  143. # IMPORTANT: you should not change this setting once you've created
  144. # elections, as your elections' cast_url will then be incorrect.
  145. # SECURE_URL_HOST = "https://localhost:8443"
  146. SECURE_URL_HOST = get_from_env("SECURE_URL_HOST", URL_HOST).rstrip("/")
  147. # election stuff
  148. SITE_TITLE = get_from_env('SITE_TITLE', 'Helios Voting')
  149. MAIN_LOGO_URL = get_from_env('MAIN_LOGO_URL', '/static/logo.png')
  150. ALLOW_ELECTION_INFO_URL = (get_from_env('ALLOW_ELECTION_INFO_URL', '0') == '1')
  151. # FOOTER links
  152. FOOTER_LINKS = json.loads(get_from_env('FOOTER_LINKS', '[]'))
  153. FOOTER_LOGO_URL = get_from_env('FOOTER_LOGO_URL', None)
  154. WELCOME_MESSAGE = get_from_env('WELCOME_MESSAGE', "This is the default message")
  155. HELP_EMAIL_ADDRESS = get_from_env('HELP_EMAIL_ADDRESS', 'help@heliosvoting.org')
  156. AUTH_TEMPLATE_BASE = "server_ui/templates/base.html"
  157. HELIOS_TEMPLATE_BASE = "server_ui/templates/base.html"
  158. HELIOS_ADMIN_ONLY = False
  159. HELIOS_VOTERS_UPLOAD = True
  160. HELIOS_VOTERS_EMAIL = True
  161. # are elections private by default?
  162. HELIOS_PRIVATE_DEFAULT = False
  163. # authentication systems enabled
  164. #AUTH_ENABLED_AUTH_SYSTEMS = ['password','facebook','twitter', 'google', 'yahoo']
  165. AUTH_ENABLED_AUTH_SYSTEMS = get_from_env('AUTH_ENABLED_AUTH_SYSTEMS', 'google').split(",")
  166. AUTH_DEFAULT_AUTH_SYSTEM = get_from_env('AUTH_DEFAULT_AUTH_SYSTEM', None)
  167. # google
  168. GOOGLE_CLIENT_ID = get_from_env('GOOGLE_CLIENT_ID', '')
  169. GOOGLE_CLIENT_SECRET = get_from_env('GOOGLE_CLIENT_SECRET', '')
  170. # facebook
  171. FACEBOOK_APP_ID = get_from_env('FACEBOOK_APP_ID','')
  172. FACEBOOK_API_KEY = get_from_env('FACEBOOK_API_KEY','')
  173. FACEBOOK_API_SECRET = get_from_env('FACEBOOK_API_SECRET','')
  174. # twitter
  175. TWITTER_API_KEY = ''
  176. TWITTER_API_SECRET = ''
  177. TWITTER_USER_TO_FOLLOW = 'heliosvoting'
  178. TWITTER_REASON_TO_FOLLOW = "we can direct-message you when the result has been computed in an election in which you participated"
  179. # the token for Helios to do direct messaging
  180. TWITTER_DM_TOKEN = {"oauth_token": "", "oauth_token_secret": "", "user_id": "", "screen_name": ""}
  181. # LinkedIn
  182. LINKEDIN_API_KEY = ''
  183. LINKEDIN_API_SECRET = ''
  184. # CAS (for universities)
  185. CAS_USERNAME = get_from_env('CAS_USERNAME', "")
  186. CAS_PASSWORD = get_from_env('CAS_PASSWORD', "")
  187. CAS_ELIGIBILITY_URL = get_from_env('CAS_ELIGIBILITY_URL', "")
  188. CAS_ELIGIBILITY_REALM = get_from_env('CAS_ELIGIBILITY_REALM', "")
  189. # Clever
  190. CLEVER_CLIENT_ID = get_from_env('CLEVER_CLIENT_ID', "")
  191. CLEVER_CLIENT_SECRET = get_from_env('CLEVER_CLIENT_SECRET', "")
  192. # email server
  193. EMAIL_HOST = get_from_env('EMAIL_HOST', 'localhost')
  194. EMAIL_PORT = int(get_from_env('EMAIL_PORT', "2525"))
  195. EMAIL_HOST_USER = get_from_env('EMAIL_HOST_USER', '')
  196. EMAIL_HOST_PASSWORD = get_from_env('EMAIL_HOST_PASSWORD', '')
  197. EMAIL_USE_TLS = (get_from_env('EMAIL_USE_TLS', '0') == '1')
  198. # to use AWS Simple Email Service
  199. # in which case environment should contain
  200. # AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  201. if get_from_env('EMAIL_USE_AWS', '0') == '1':
  202. EMAIL_BACKEND = 'django_ses.SESBackend'
  203. # set up logging
  204. import logging
  205. logging.basicConfig(
  206. level = logging.DEBUG,
  207. format = '%(asctime)s %(levelname)s %(message)s'
  208. )
  209. # set up django-celery
  210. # BROKER_BACKEND = "kombu.transport.DatabaseTransport"
  211. BROKER_URL = "django://"
  212. CELERY_RESULT_DBURI = DATABASES['default']
  213. import djcelery
  214. djcelery.setup_loader()
  215. # for testing
  216. TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner'
  217. # this effectively does CELERY_ALWAYS_EAGER = True
  218. # Rollbar Error Logging
  219. ROLLBAR_ACCESS_TOKEN = get_from_env('ROLLBAR_ACCESS_TOKEN', None)
  220. if ROLLBAR_ACCESS_TOKEN:
  221. print "setting up rollbar"
  222. MIDDLEWARE_CLASSES += ('rollbar.contrib.django.middleware.RollbarNotifierMiddleware',)
  223. ROLLBAR = {
  224. 'access_token': ROLLBAR_ACCESS_TOKEN,
  225. 'environment': 'development' if DEBUG else 'production',
  226. }
  227. # Tendenci
  228. # Add trailing slash to the URLs
  229. TENDENCI_CAS_URL = 'http://tendenci:9000/cas/'
  230. TENDENCI_GROUPS_URL = 'http://tendenci:9000/helios/groups/'
  231.