Giter VIP home page Giter VIP logo

django-easysettings's Introduction

django-easysettings

Build status

Coverage status

Easy app-specific settings for Django apps.

Provides a method for using a declarative class for an app's default settings. The instance of this class can be used to access all project settings in place of django.conf.settings.

Installation

To install, run: pip install django-easysettings

Usage

Create a conf.py file within your app's directory, adding attributes for the default values of your app-specific settings. They will be overridden by any project setting that is provided.

For example:

from easysettings.app import AppSettings


class Settings(AppSettings):
    MYAPP_FRUIT = 'Apple'


settings = Settings()

Then in your app, rather than from django.conf import settings, use from myapp.conf import settings. For example:

from myapp.conf import settings


def dashboard(request):
    context = {}
    context['fruit'] = settings.MYAPP_FRUIT
    if settings.DEBUG:
        context['debug_mode'] = True
    # ...

Dictionaries

A common pattern is to use a dictionary as a namespace for all an app's settings, such as settings.MYAPP['settings'].

Easy-settings handles this fine, overriding any keys provided in the project while still having access to the default app settings keys.

You can also use a subclass of an AppSettings class to set up a dictionary.

from easysettings.apps import AppSettings


class MyAppSettings(AppSettings):
    """
    MyApp settings
    """
    #: Preferred fruit
    FRUIT = 'Apple'
    #: Preferred drink
    DRINK = 'Water'


class Settings(AppSettings):
    MYAPP = MyAppSettings


settings = Settings()

Legacy Usage

If previously your app used a common prefix (like MYAPP_) you can still support projects that still use these stand-alone legacy settings while moving to a MYAPP dictionary for your settings.

from easysettings.legacy import LegacyAppSettings


class Settings(LegacyAppSettings):
    MYAPP = {'FRUIT': 'Apple'}


settings = Settings()

If a project uses settings like MYAPP_FRUIT = 'Banana' they will continue to work. As soon as a project switches to MYAPP, any MYAPP_* settings will be ignored.

While the legacy app settings class is used, the dictionary settings can still be accessed via the prefixed setting (for example, settings.MYAPP_FRUIT).

django-easysettings's People

Contributors

smileychris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

priestd09 gointer

django-easysettings's Issues

Documentation issue

I understand the idea of making configuration settings more regular (models are in the models.py, views in views.py, configuration is in conf.py....) But I don't understand how easysettings helps with anything other than that....

Part of the problem with django settings is that everything is essentially dumped into a single namespace and if I have say 4 separate settings, I end up with

MODULE_NAME_SETTING_NAME_1 = Value1
MODULE_NAME_SETTING_NAME_2 = Value2
MODULE_NAME_SETTING_NAME_3 = Value3
MODULE_NAME_SETTING_NAME_4 = Value4

easysettings seems to move the defaults to conf.py, but does nothing about grouping all the settings for MODULE_NAME into one spot. It seems like easysettings could be used to push development more in the direction of django_debug_toolbar where there is one exposed global, with settings inside that dict. More along the lines of

MODULE_NAME = {
"SETTINGS_NAME_1": Value1,
"SETTINGS_NAME_2": Value2,
"SETTINGS_NAME_3": Value3,
"SETTINGS_NAME_4": Value4,
}

Maybe it's just a documentation thing, but I'm not understanding why I would want to use this in its current state.

Not trying to be condescending here, I really don't understand the rationale.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.