Skip to content

Instantly share code, notes, and snippets.

@matagus
Created October 16, 2010 22:12
Show Gist options
  • Save matagus/630328 to your computer and use it in GitHub Desktop.
Save matagus/630328 to your computer and use it in GitHub Desktop.
django sttings proxy
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
from django.conf import settings as django_settings
class SettingsProxy(object):
def __init__(self, settings, defaults):
self.settings = settings
self.defaults = defaults
def __getattr__(self, attr):
try:
return getattr(self.settings, attr)
except AttributeError:
try:
return getattr(self.defaults, attr)
except AttributeError:
raise AttributeError, u'settings object has no attribute "%s"' % attr
class defaults(object):
FLAVOURS = (u'full', u'mobile',)
DEFAULT_MOBILE_FLAVOUR = u'mobile'
FLAVOURS_TEMPLATE_DIRS_PREFIX = u''
FLAVOURS_GET_PARAMETER = u'flavour'
FLAVOURS_SESSION_KEY = u'flavour'
settings = SettingsProxy(django_settings, defaults)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment