Initial commit
[fnpdjango.git] / fnpdjango / utils / app.py
1 """
2 Basic utilities for applications.
3 """
4
5
6 from django.conf import settings
7
8
9 class AppSettings(object):
10     """Allows specyfying custom settings for an app, with default values.
11
12     Just subclass, set some properties and instantiate with a prefix.
13     Getting a SETTING from an instance will check for prefix_SETTING
14     in project settings if set, else take the default. The value will be
15     then filtered through _more_SETTING method, if there is one.
16
17     """
18     def __init__(self, prefix):
19         self._prefix = prefix
20
21     def __getattribute__(self, name):
22         if name.startswith('_'):
23             return object.__getattribute__(self, name)
24         value = getattr(settings,
25                          "%s_%s" % (self._prefix, name),
26                          object.__getattribute__(self, name))
27         more = "_more_%s" % name
28         if hasattr(self, more):
29             value = getattr(self, more)(value)
30         return value