2 Generate settings for the Django Application.
4 To make it easier to customize the application the settings can be
5 defined in a configuration file read by ConfigParser.
7 The options understood by this module are (with their defaults):
12 database=<section_name>
16 name=/path/to/database
25 [allowed_analysis_hosts]
36 from django.conf import global_settings
38 from htsworkflow.util.api import make_django_secret_key
40 HTSWORKFLOW_ROOT = os.path.abspath(os.path.split(htsworkflow.__file__)[0])
41 LOGGER = logging.getLogger(__name__)
44 __docformat__ = "restructuredtext en"
46 def options_to_list(options, dest, section_name, option_name):
48 Load a options from section_name and store in a dictionary
50 if options.has_option(section_name, option_name):
51 opt = options.get(section_name, option_name)
52 dest.extend( shlex.split(opt) )
54 def options_to_dict(dest, section_name):
56 Load a options from section_name and store in a dictionary
58 if options.has_section(section_name):
59 for name in options.options(section_name):
60 dest[name] = options.get(section_name, name)
62 # define your defaults here
63 options = ConfigParser.SafeConfigParser()
65 def save_options(filename, options):
67 ini_stream = open(filename, 'w')
68 options.write(ini_stream)
71 LOGGER.debug("Error saving setting: %s" % (str(e)))
73 INI_FILE = options.read([os.path.expanduser("~/.htsworkflow.ini"),
74 '/etc/htsworkflow.ini',])
76 # OptionParser will use the dictionary passed into the config parser as
77 # 'Default' values in any section. However it still needs an empty section
78 # to exist in order to retrieve anything.
79 if not options.has_section('frontend'):
80 options.add_section('frontend')
81 if not options.has_section('bcprinter'):
82 options.add_section('bcprinter')
85 # Django settings for elandifier project.
88 TEMPLATE_DEBUG = DEBUG
91 options_to_list(options, ADMINS, 'frontend', 'admins')
94 options_to_list(options, MANAGERS, 'frontend', 'managers')
96 if options.has_option('front', 'default_pm'):
97 DEFAULT_PM=int(options.get('frontend', 'default_pm'))
101 AUTHENTICATION_BACKENDS = (
102 'htsworkflow.frontend.samples.auth_backend.HTSUserModelBackend', )
103 CUSTOM_USER_MODEL = 'samples.HTSUser'
105 EMAIL_HOST='localhost'
106 if options.has_option('frontend', 'email_host'):
107 EMAIL_HOST = options.get('frontend', 'email_host')
110 if options.has_option('frontend', 'email_port'):
111 EMAIL_PORT = int(options.get('frontend', 'email_port'))
113 if options.has_option('frontend', 'notification_sender'):
114 NOTIFICATION_SENDER = options.get('frontend', 'notification_sender')
116 NOTIFICATION_SENDER = "noreply@example.com"
117 NOTIFICATION_BCC = []
118 options_to_list(options, NOTIFICATION_BCC, 'frontend', 'notification_bcc')
120 if not options.has_option('frontend', 'database'):
121 raise ConfigParser.NoSectionError(
122 "Please define [frontend] database=<Section>")
124 database_section = options.get('frontend', 'database')
126 if not options.has_section(database_section):
127 raise ConfigParser.NoSectionError(
128 "No database=<database_section_name> defined")
130 # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
131 DATABASE_ENGINE = options.get(database_section, 'engine')
132 DATABASE_NAME = options.get(database_section, 'name')
133 if options.has_option(database_section, 'user'):
134 DATABASE_USER = options.get(database_section, 'user')
135 if options.has_option(database_section, 'host'):
136 DATABASE_HOST = options.get(database_section, 'host')
137 if options.has_option(database_section, 'port'):
138 DATABASE_PORT = options.get(database_section, 'port')
140 if options.has_option(database_section, 'password_file'):
141 password_file = options.get(database_section, 'password_file')
142 DATABASE_PASSWORD = open(password_file,'r').readline()
143 elif options.has_option(database_section, 'password'):
144 DATABASE_PASSWORD = options.get(database_section, 'password')
148 'ENGINE': 'django.db.backends.sqlite3',
149 'NAME': DATABASE_NAME,
153 # Local time zone for this installation. Choices can be found here:
154 # http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
155 # although not all variations may be possible on all operating systems.
156 # If running in a Windows environment this must be set to the same as your
158 if options.has_option('frontend', 'time_zone'):
159 TIME_ZONE = options.get('frontend', 'time_zone')
161 TIME_ZONE = 'America/Los_Angeles'
163 # Language code for this installation. All choices can be found here:
164 # http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
165 # http://blogs.law.harvard.edu/tech/stories/storyReader$15
166 LANGUAGE_CODE = 'en-us'
170 # If you set this to False, Django will make some optimizations so as not
171 # to load the internationalization machinery.
174 # Absolute path to the directory that holds media.
175 # Example: "/home/media/media.lawrence.com/"
176 MEDIA_ROOT = os.path.join(HTSWORKFLOW_ROOT, 'frontend', 'static', '')
178 # URL that handles the media served from MEDIA_ROOT.
179 # Example: "http://media.lawrence.com"
180 MEDIA_URL = '/static/'
182 # URL prefix for static media -- CSS, JavaScript and images. Make sure to use a
184 STATIC_URL = '/media/'
186 # Make this unique, and don't share it with anybody.
187 if not options.has_option('frontend', 'secret'):
188 options.set('frontend', 'secret_key', make_django_secret_key(458))
189 save_options(INI_FILE[0], options)
190 SECRET_KEY = options.get('frontend', 'secret_key')
192 # some of our urls need an api key
193 DEFAULT_API_KEY = 'n7HsXGHIi0vp9j5u4TIRJyqAlXYc4wrH'
195 # List of callables that know how to import templates from various sources.
197 'django.template.loaders.filesystem.Loader',
198 'django.template.loaders.app_directories.Loader',
201 MIDDLEWARE_CLASSES = (
202 'django.middleware.csrf.CsrfViewMiddleware',
203 'django.middleware.common.CommonMiddleware',
204 'django.contrib.sessions.middleware.SessionMiddleware',
205 'django.contrib.auth.middleware.AuthenticationMiddleware',
206 'django.contrib.messages.middleware.MessageMiddleware',
207 'django.middleware.doc.XViewMiddleware',
210 TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
211 'htsworkflow.frontend.thispage.thispage',
213 ROOT_URLCONF = 'htsworkflow.frontend.urls'
216 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
217 # Always use forward slashes, even on Windows.
218 # Don't forget to use absolute paths, not relative paths.
219 '/usr/share/python-support/python-django/django/contrib/admin/templates',
220 #'/usr/lib/pymodules/python2.6/django/contrib/admin/templates/',
221 os.path.join(HTSWORKFLOW_ROOT, 'frontend', 'templates'),
222 os.path.join(HTSWORKFLOW_ROOT, 'templates'),
226 'django.contrib.admin',
227 'django.contrib.auth',
228 'django.contrib.contenttypes',
229 'django.contrib.staticfiles',
230 'django.contrib.humanize',
231 'django.contrib.sessions',
232 'django.contrib.sites',
233 'htsworkflow.frontend.eland_config',
234 'htsworkflow.frontend.samples',
235 # modules from htsworkflow branch
236 'htsworkflow.frontend.experiments',
237 'htsworkflow.frontend.analysis',
238 'htsworkflow.frontend.reports',
239 'htsworkflow.frontend.inventory',
240 'htsworkflow.frontend.bcmagic',
241 'htsworkflow.frontend.labels',
242 'django.contrib.databrowse',
245 # Project specific settings
247 ALLOWED_IPS={'127.0.0.1': '127.0.0.1'}
248 options_to_dict(ALLOWED_IPS, 'allowed_hosts')
250 ALLOWED_ANALYS_IPS = {'127.0.0.1': '127.0.0.1'}
251 options_to_dict(ALLOWED_ANALYS_IPS, 'allowed_analysis_hosts')
252 #UPLOADTO_HOME = os.path.abspath('../../uploads')
253 #UPLOADTO_CONFIG_FILE = os.path.join(UPLOADTO_HOME, 'eland_config')
254 #UPLOADTO_ELAND_RESULT_PACKS = os.path.join(UPLOADTO_HOME, 'eland_results')
255 #UPLOADTO_BED_PACKS = os.path.join(UPLOADTO_HOME, 'bed_packs')
256 # Where "results_dir" means directory with all the flowcells
257 if options.has_option('frontend', 'results_dir'):
258 RESULT_HOME_DIR=os.path.expanduser(options.get('frontend', 'results_dir'))
260 RESULT_HOME_DIR='/tmp'
262 if options.has_option('frontend', 'link_flowcell_storage_device_url'):
263 LINK_FLOWCELL_STORAGE_DEVICE_URL = options.get('frontend',
264 'link_flowcell_storage_device_url')
266 LINK_FLOWCELL_STORAGE_DEVICE_URL = None
267 # PORT 9100 is default for Zebra tabletop/desktop printers
268 # PORT 6101 is default for Zebra mobile printers
269 BCPRINTER_PRINTER1_HOST = None
270 if options.has_option('bcprinter', 'printer1_host'):
271 BCPRINTER_PRINTER1_HOST = options.get('bcprinter', 'printer1_host')
272 BCPRINTER_PRINTER1_PORT=9100
273 if options.has_option('bcprinter', 'printer1_port'):
274 BCPRINTER_PRINTER1_PORT = int(options.get('bcprinter', 'printer1_port'))
275 BCPRINTER_PRINTER2_HOST = None
276 if options.has_option('bcprinter', 'printer2_host'):
277 BCPRINTER_PRINTER1_HOST = options.get('bcprinter', 'printer2_host')
278 BCPRINTER_PRINTER2_PORT=9100
279 if options.has_option('bcprinter', 'printer2_port'):
280 BCPRINTER_PRINTER2_PORT = int(options.get('bcprinter', 'printer2_port'))