Code Monkey home page Code Monkey logo

django-easysettings's Introduction

django-easysettings

Easy app-specific settings for Django.

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 import AppSettings


class Settings(AppSettings):
    MYAPP_WIDGETS = ('foo', 'bar')


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):
    data = {}
    for widget in settings.MYAPP_WIDGETS:
        data[widget] = render_widget(widget)
    if settings.DEBUG:
        data['debug_mode'] = True
    # ...

Isolating Settings when Testing

You can force your app's tests to use the default project settings rather than any value in the project's settings configuration module.

Just set settings.isolated = True.

For example, you could use a base test class to do this:

class BaseTest(TestCase):

    def setUp(self):
        """
        Isolate all application specific settings.
        """
        output = super(BaseTest, self).setUp()
        settings.isolated = True
        return output

    def tearDown(self):
        """
        Restore settings to their original state.
        """
        settings.isolated = False
        settings.revert()
        return super(BaseTest, self).tearDown()

As also shown in the example above, you can revert any changes made by calling settings.revert().

django-easysettings's People

Contributors

smileychris avatar

Watchers

 avatar  avatar

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.