Created
November 24, 2009 10:50
-
-
Save ella/241788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now you can override the settings using the prefix: | |
EVENTS_QUEUE = 'not-events' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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