Skip to content

muccg/ccg-django-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CCG Django Utils

Build Status PyPI

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.

Environment Settings for Django

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", ""),
    }
}

Log Handler

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'
}

Misc

A HttpResponse subclass with status of 401.

from ccg_django_utils.http import HttpResponseUnauthorized

Webhelpers

Functions for generating URLs with a base path prepended. This should be deprecated soon.

from ccg_django_utils.webhelpers import url

About

Miscellaneous utility code used by the Centre for Comparative Genomics in our Django applications.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages