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