I moved more of options in settings.py to the .htsworkflow.ini
authorDiane Trout <diane@caltech.edu>
Tue, 7 Oct 2008 21:15:42 +0000 (21:15 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 7 Oct 2008 21:15:42 +0000 (21:15 +0000)
In this case, the list of admin users were moved to a [admins]
section in the ini file as well as the allowed_ips to [allowed_hosts]
and allowed_analys_ips to [allowed_analysis_hosts].

Currently localhost is always allowed.

htswfrontend/htswfrontend/settings.py

index e48fb055a7db0b102ab7450a746e2e1034d0b10e..98a0ff38974a76f43a647b83074fa3159238cc3b 100644 (file)
@@ -1,14 +1,56 @@
-import ConfigParser
+"""
+Generate settings for the Django Application.
+
+To make it easier to customize the application the settings can be 
+defined in a configuration file read by ConfigParser.
+
+The options understood by this module are (with their defaults):
+
+  [frontend]
+  email_host=localhost
+  email_port=25
+  database_engine=sqlite3
+  database_name=/path/to/db
+
+  [admins]
+  #name1=email1
 
+  [allowed_hosts]
+  #name1=ip
+  localhost=127.0.0.1
+  
+  [allowed_analysis_hosts]
+  #name1=ip
+  localhost=127.0.0.1
+
+"""
+import ConfigParser
 import os
 
+def options_to_list(dest, section_name):
+  """
+  Load a options from section_name and store in a dictionary
+  """
+  if options.has_section(section_name):
+    for name in options.options(section_name):
+      dest.append( options.get(section_name, name) )
+      
+def options_to_dict(dest, section_name):
+  """
+  Load a options from section_name and store in a dictionary
+  """
+  if options.has_section(section_name):
+    for name in options.options(section_name):
+      dest[name] = options.get(section_name, name)
+
 # define your defaults here
 options = ConfigParser.SafeConfigParser(
-           { 'email_host': 'myerslab.stanford.edu',
+           { 'email_host': 'localhost',
              'email_port': '25', 
              'database_engine': 'sqlite3',
              'database_name': 
                os.path.abspath('/htsworkflow/htswfrontend/dev_fctracker.db'),
+             'time_zone': 'America/Los_Angeles',
            })
 
 options.read([os.path.expanduser("~/.htsworkflow.ini"),
@@ -19,9 +61,8 @@ options.read([os.path.expanduser("~/.htsworkflow.ini"),
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 
-ADMINS = (
-     ('Rami Rauch', 'rrauch@stanford.edu'),
-)
+ADMINS = []
+options_to_list(ADMINS, 'admins')
 
 MANAGERS = ADMINS
 
@@ -43,7 +84,7 @@ DATABASE_PORT = ''             # Set to empty string for default. Not used with
 # although not all variations may be possible on all operating systems.
 # If running in a Windows environment this must be set to the same as your
 # system time zone.
-TIME_ZONE = 'America/Los_Angeles'
+TIME_ZONE = options.get('frontend', 'time_zone')
 
 # Language code for this installation. All choices can be found here:
 # http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
@@ -109,8 +150,11 @@ INSTALLED_APPS = (
 )
 
 # Project specific settings
-ALLOWED_IPS = {"74.51.115.100":"HudsonAlpha","64.89.97.100":"HudsonAlpha","127.0.0.1":"Localhost"}
-ALLOWED_ANALYS_IPS = {"171.65.76.194":"Stanford Analysis 1","127.0.0.1":"Localhost"}
+ALLOWED_IPS={'localhost': '127.0.0.1'}
+options_to_dict(ALLOWED_IPS, 'allowed_hosts')
+
+ALLOWED_ANALYS_IPS = {'localhost': '127.0.0.1'}
+options_to_dict(ALLOWED_ANALYS_IPS, 'allowed_analysis_hosts')
 #UPLOADTO_HOME = os.path.abspath('../../uploads')
 #UPLOADTO_CONFIG_FILE = os.path.join(UPLOADTO_HOME, 'eland_config')
 #UPLOADTO_ELAND_RESULT_PACKS = os.path.join(UPLOADTO_HOME, 'eland_results')