Skip to content

Commit

Permalink
Add Meta attr for specifying required settings
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwithanm committed Jun 1, 2012
1 parent bf14a76 commit 72c9bfa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions appconf/base.py
@@ -1,3 +1,4 @@
from django.core.exceptions import ImproperlyConfigured
import sys
from .utils import import_attribute

Expand All @@ -9,6 +10,7 @@ def __init__(self, meta, prefix=None):
self.holder_path = getattr(meta, 'holder', 'django.conf.settings')
self.holder = import_attribute(self.holder_path)
self.proxy = getattr(meta, 'proxy', False)
self.required = getattr(meta, 'required', [])
self.configured_data = {}

def prefixed_name(self, name):
Expand Down Expand Up @@ -71,6 +73,14 @@ def __new__(cls, name, bases, attrs):
prefixed_name = new_class._meta.prefixed_name(name)
setattr(new_class._meta.holder, prefixed_name, value)
new_class.add_to_class(name, value)

# Confirm presence of required settings.
for name in new_class._meta.required:
prefixed_name = new_class._meta.prefixed_name(name)
if not hasattr(new_class._meta.holder, prefixed_name):
raise ImproperlyConfigured('The required setting %s is'
' missing.' % prefixed_name)

return new_class

def add_to_class(cls, name, value):
Expand Down

0 comments on commit 72c9bfa

Please sign in to comment.