Advertisement
Guest User

Untitled

a guest
Jun 26th, 2018
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.53 KB | None | 0 0
  1.  
  2. import os, json
  3.  
  4. # a massive hack to see if we're testing, in which case we use different settings
  5. import sys
  6. TESTING = 'test' in sys.argv
  7.  
  8. # go through environment variables and override them
  9. def 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.  
  15. DEBUG = (get_from_env('DEBUG', '1') == '1')
  16. TEMPLATE_DEBUG = DEBUG
  17.  
  18. # add admins of the form:
  19. #    ('Ben Adida', 'ben@adida.net'),
  20. # if you want to be emailed about errors.
  21. ADMINS = (
  22. )
  23.  
  24. MANAGERS = ADMINS
  25.  
  26. # is this the master Helios web site?
  27. MASTER_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
  31. SHOW_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
  35. SHOW_USER_INFO = (get_from_env('SHOW_USER_INFO', '1') == '1')
  36.  
  37. DATABASES = {
  38.     'default': {
  39.         'ENGINE': 'django.db.backends.postgresql_psycopg2',
  40.         'NAME': 'helios'
  41.     }
  42. }
  43.  
  44. SOUTH_DATABASE_ADAPTERS = {'default':'south.db.postgresql_psycopg2'}
  45.  
  46. # override if we have an env variable
  47. if 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.
  61. TIME_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
  65. LANGUAGE_CODE = 'en-us'
  66.  
  67. SITE_ID = 1
  68.  
  69. # If you set this to False, Django will make some optimizations so as not
  70. # to load the internationalization machinery.
  71. USE_I18N = True
  72.  
  73. # Absolute path to the directory that holds media.
  74. # Example: "/home/media/media.lawrence.com/"
  75. MEDIA_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/"
  80. MEDIA_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/".
  85. STATIC_URL = '/media/'
  86.  
  87. # Make this unique, and don't share it with anybody.
  88. SECRET_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.  
  94. ALLOWED_HOSTS = get_from_env('ALLOWED_HOSTS', 'localhost').split(",")
  95.  
  96. # Secure Stuff
  97. if (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.  
  104. SESSION_COOKIE_HTTPONLY = True
  105.  
  106. # let's go with one year because that's the way to do it now
  107. STS = False
  108. if (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.  
  115. SECURE_BROWSER_XSS_FILTER = True
  116. SECURE_CONTENT_TYPE_NOSNIFF = True
  117.  
  118. # List of callables that know how to import templates from various sources.
  119. TEMPLATE_LOADERS = (
  120.     'django.template.loaders.filesystem.Loader',
  121.     'django.template.loaders.app_directories.Loader'
  122. )
  123.  
  124. MIDDLEWARE_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.  
  138. ROOT_URLCONF = 'urls'
  139.  
  140. ROOT_PATH = os.path.dirname(__file__)
  141. TEMPLATE_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.  
  147. INSTALLED_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.  
  172. MEDIA_ROOT = ROOT_PATH + "media/"
  173.  
  174. # a relative path where voter upload files are stored
  175. VOTER_UPLOAD_REL_PATH = "voters/%Y/%m/%d"
  176.  
  177.  
  178. # Change your email settings
  179. DEFAULT_FROM_EMAIL = get_from_env('DEFAULT_FROM_EMAIL', 'ben@adida.net')
  180. DEFAULT_FROM_NAME = get_from_env('DEFAULT_FROM_NAME', 'Ben for Helios')
  181. SERVER_EMAIL = '%s <%s>' % (DEFAULT_FROM_NAME, DEFAULT_FROM_EMAIL)
  182.  
  183. LOGIN_URL = '/auth/'
  184. LOGOUT_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.
  188. URL_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"
  193. SECURE_URL_HOST = get_from_env("SECURE_URL_HOST", URL_HOST).rstrip("/")
  194.  
  195. # election stuff
  196. SITE_TITLE = get_from_env('SITE_TITLE', 'Helios Voting')
  197. MAIN_LOGO_URL = get_from_env('MAIN_LOGO_URL', '/static/logo.png')
  198. ALLOW_ELECTION_INFO_URL = (get_from_env('ALLOW_ELECTION_INFO_URL', '0') == '1')
  199.  
  200. # FOOTER links
  201. FOOTER_LINKS = json.loads(get_from_env('FOOTER_LINKS', '[]'))
  202. FOOTER_LOGO_URL = get_from_env('FOOTER_LOGO_URL', None)
  203.  
  204. WELCOME_MESSAGE = get_from_env('WELCOME_MESSAGE', "This is the default message")
  205.  
  206. HELP_EMAIL_ADDRESS = get_from_env('HELP_EMAIL_ADDRESS', 'help@heliosvoting.org')
  207.  
  208. AUTH_TEMPLATE_BASE = "~/tendenci/tendenci-helios/tendenci/themes/nova/templates/default-fullwidth.html"
  209. HELIOS_TEMPLATE_BASE = "~/tendenci/tendenci-helios/tendenci/themes/nova/templates/default-fullwidth.html"
  210. HELIOS_ADMIN_ONLY = False
  211. HELIOS_VOTERS_UPLOAD = True
  212. HELIOS_VOTERS_EMAIL = True
  213.  
  214. # are elections private by default?
  215. HELIOS_PRIVATE_DEFAULT = False
  216.  
  217. # authentication systems enabled
  218. #AUTH_ENABLED_AUTH_SYSTEMS = ['password','facebook','twitter', 'google', 'yahoo']
  219. AUTH_ENABLED_AUTH_SYSTEMS = get_from_env('AUTH_ENABLED_AUTH_SYSTEMS', 'google').split(",")
  220. AUTH_DEFAULT_AUTH_SYSTEM = get_from_env('AUTH_DEFAULT_AUTH_SYSTEM', None)
  221.  
  222. # google
  223. GOOGLE_CLIENT_ID = get_from_env('GOOGLE_CLIENT_ID', '')
  224. GOOGLE_CLIENT_SECRET = get_from_env('GOOGLE_CLIENT_SECRET', '')
  225.  
  226. # facebook
  227. FACEBOOK_APP_ID = get_from_env('FACEBOOK_APP_ID','')
  228. FACEBOOK_API_KEY = get_from_env('FACEBOOK_API_KEY','')
  229. FACEBOOK_API_SECRET = get_from_env('FACEBOOK_API_SECRET','')
  230.  
  231. # twitter
  232. TWITTER_API_KEY = ''
  233. TWITTER_API_SECRET = ''
  234. TWITTER_USER_TO_FOLLOW = 'heliosvoting'
  235. TWITTER_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
  238. TWITTER_DM_TOKEN = {"oauth_token": "", "oauth_token_secret": "", "user_id": "", "screen_name": ""}
  239.  
  240. # LinkedIn
  241. LINKEDIN_API_KEY = ''
  242. LINKEDIN_API_SECRET = ''
  243.  
  244. # CAS (for universities)
  245. CAS_USERNAME = get_from_env('CAS_USERNAME', "")
  246. CAS_PASSWORD = get_from_env('CAS_PASSWORD', "")
  247. CAS_ELIGIBILITY_URL = get_from_env('CAS_ELIGIBILITY_URL', "")
  248. CAS_ELIGIBILITY_REALM = get_from_env('CAS_ELIGIBILITY_REALM', "")
  249.  
  250. # Clever
  251. CLEVER_CLIENT_ID = get_from_env('CLEVER_CLIENT_ID', "")
  252. CLEVER_CLIENT_SECRET = get_from_env('CLEVER_CLIENT_SECRET', "")
  253.  
  254. # email server
  255. EMAIL_HOST = get_from_env('EMAIL_HOST', 'localhost')
  256. EMAIL_PORT = int(get_from_env('EMAIL_PORT', "2525"))
  257. EMAIL_HOST_USER = get_from_env('EMAIL_HOST_USER', '')
  258. EMAIL_HOST_PASSWORD = get_from_env('EMAIL_HOST_PASSWORD', '')
  259. EMAIL_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
  264. if get_from_env('EMAIL_USE_AWS', '0') == '1':
  265.     EMAIL_BACKEND = 'django_ses.SESBackend'
  266.  
  267. # set up logging
  268. import logging
  269. logging.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"
  277. BROKER_URL = "django://"
  278. CELERY_RESULT_DBURI = DATABASES['default']
  279. import djcelery
  280. djcelery.setup_loader()
  281.  
  282.  
  283. # for testing
  284. TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner'
  285. # this effectively does CELERY_ALWAYS_EAGER = True
  286.  
  287. # Rollbar Error Logging
  288. ROLLBAR_ACCESS_TOKEN = get_from_env('ROLLBAR_ACCESS_TOKEN', None)
  289. if 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
  299. TENDENCI_CAS_URL = 'http://tendenci:9000/cas/'
  300. TENDENCI_GROUPS_URL = 'http://tendenci:9000/helios/groups/'
  301.  
  302. TENDENCI_CAS_URL = 'http://tendenci:9000/cas/'
  303. TENDENCI_GROUPS_URL = 'http://tendenci:9000/helios/groups/'
  304.  
  305. STATICFILES_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.  
  314. THEMES_DIR = '~/tendenci/tendenci-helios/tendenci/themes/'
  315.  
  316. from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
  317.  
  318. TEMPLATE_CONTEXT_PROCESSORS += (
  319.     'helios_tendenci.context_processors.theme',
  320. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement