Skip to content

Instantly share code, notes, and snippets.

@ella
Created November 24, 2009 10:50
Show Gist options
  • Save ella/241788 to your computer and use it in GitHub Desktop.
Save ella/241788 to your computer and use it in GitHub Desktop.
from my_settings import Settings
MONGODB_HOST = 'localhost'
MONGODB_PORT = 27017
MONGODB_DB = 'events'
MONGODB_COLLECTION = 'events'
ROUTING_KEY = 'events'
EXCHANGE = 'events'
QUEUE = 'events'
TASK_PERIOD = 10
settings = Settings(__name__, 'EVENTS_')
from django.utils.importlib import import_module
from django.conf import settings
class Settings(object):
def __init__(self, module_name, prefix=''):
self.module = import_module(module_name)
self.prefix = prefix
def __getattr__(self, name):
p_name = ''.join((self.prefix, name))
if hasattr(settings, p_name):
return getattr(settings, p_name)
return getattr(self.module, name)
def __dir__(self):
return dir(self.module) + dir(self.settings)
# now you can override the settings using the prefix:
EVENTS_QUEUE = 'not-events'
from conf import settings
def whatever(request):
assert settings.QUEUE == 'not-events'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment