Skip to main content

Adds ability to define Django settings with classes/functions and navigate each of them easily

Project description

https://travis-ci.org/dferens/django-classsettings.png?branch=master https://coveralls.io/repos/dferens/django-classsettings/badge.png?branch=master

Adds ability to define Django settings with classes.

As many text editors and IDEs indexes code symbols, with such approach you can easily navigate to any group and any line of your settings file.

Settings class

Exports defined variables into module’s scope:

from classsettings import Settings

class Administration(Settings):
    def ADMINS(self): return (
        ('Your Name', 'your_email@example.com'),
    )
    def DEBUG(self): return False
    def TEMPLATE_DEBUG(self): return self.DEBUG()

Will result in

ADMINS = (
    ('Your Name', 'your_email@example.com'),
)
DEBUG = False
TEMPLATE_DEBUG = False

Config class

Injects dictionary if variables into module’s scope:

from classsettings import Config

class REST_FRAMEWORK(Config):
    def DEFAULT_FILTER_BACKENDS(self): return (
        'rest_framework.filters.DjangoFilterBackend',
    )

Will result in

REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS': (
        'rest_framework.filter.DjangoFilterBackend',
    )
}

Decorators

Some decorators may be found usefull:

from classsettings import Settings, from_env

class MySettingsGroup(Settings):
    # Will look for `EMAIL_HOST` key in `os.environ`
    # and use `smtp.gmail.com` if such key was not found
    @from_env
    def EMAIL_HOST(self): return 'smtp.gmail.com'

    # Will raise Django's `ImproperlyConfigured` exception
    # if such key was not found
    @from_env
    def SECRET_KEY(self): pass

    # Will look for specified key
    @from_env(key='CUSTOM_ENV_VAR_NAME')
    def variable(self): pass

    # Will apply `through` callable to result
    @from_env(through=dj_database_url.parse)
    def DATABASE_URL(self): return 'sqlite://'

Project details


Release history Release notifications

History Node

1.0.2

This version
History Node

1.0.1

History Node

1.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-classsettings-1.0.1.tar.gz (3.8 kB) Copy SHA256 hash SHA256 Source None Mar 9, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page