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


Download files

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

Source Distribution

django-classsettings-1.0.1.tar.gz (3.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page