Miscellaneous utility code used by the [Centre for Comparative Genomics] 1 in our Django applications.
It's all contained in the ccg_django_utils
module.
Use simple environment variables to control django settings. For example:
# settings.py
from ccg_django_utils.conf import EnvConfig
env = EnvConfig()
DATABASES = {
'default': {
'ENGINE': env.get_db_engine("dbtype", "pgsql"),
'NAME': env.get("dbname", "myapp"),
'USER': env.get("dbuser", "myapp"),
'PASSWORD': env.get("dbpass", "myapp"),
'HOST': env.get("dbserver", ""),
'PORT': env.get("dbport", ""),
}
}
A file logging handler which automatically creates the necessary parent directories. For example:
LOGGING['handlers']['file'] = {
'level': 'INFO',
'class': 'ccg_django_utils.loghandlers.ParentPathFileHandler',
'filename': os.path.join(CCG_LOG_DIRECTORY, 'myapp.log'),
'when': 'midnight',
'formatter': 'verbose'
}
A HttpResponse
subclass with status of 401.
from ccg_django_utils.http import HttpResponseUnauthorized
Functions for generating URLs with a base path prepended. This should be deprecated soon.
from ccg_django_utils.webhelpers import url