Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 43 lines (28 sloc) 1.516 kb
eceb89f @niwibe Improved readme.
authored
1 =============
2 django-dbconf
3 =============
4
f650e67 @niwibe Initial commit.
authored
5 Simple helper to save settings in a database and efficient access to this data through cache.
6
eceb89f @niwibe Improved readme.
authored
7 This application is not intended to replace the django settings. Allows for complex applications
8 that claim to have certain settings in the database and to change the flight, and especially to
9 have them with persistence.
10
11 Its use is very simple, containing a model with 2 fields (key, val) and a singleton class
12 (with cache) to serve as interface to the configuration.
13
14 The key is in a namespace, so code can be searched by, or at least I call it so.
15
16 Example:
17 --------
18
19 * 'google.analytics.code'
20 * 'google.analytics.domain'
21
22 Example of usage config object:
23 -------------------------------
24
16c5990 @niwibe Some modifications.
authored
25 >>> from django_dbconf.conf import config
26 >>> val = config.get('google.analytics.code')
eceb89f @niwibe Improved readme.
authored
27
28 Example of obtain all config by prefix:
29 ---------------------------------------
30
19ba0ba @niwibe Fix mistake on readme.
authored
31 >>> print list(config.get_range('google.'))
eceb89f @niwibe Improved readme.
authored
32 [('google.analytics.code', 'XXXXX'), ('google.analytics.domain', '.niwi.be')]
33
34
35 **config** is a instance of a `LazyDatabaseConf` and the public method are:
36
37 * get(key, default=None) -> str: get key if not exists in cache obtain key and value pair from database.
38 * set(key, value) -> None: only modifies in memory and cache, not database modification
39 * get_range(prefix) -> generator: get all key value pairs searching by prefix.
40
41 **NOTE**: If value is modified in database, the cache is invalidated and config object always
42 returns the updated value.
Something went wrong with that request. Please try again.