~phanatic/django-configglue/more-supported-releases

« back to all changes in this revision

Viewing changes to doc/walkthrough.rst

  • Committer: Ricardo Kirkner
  • Date: 2011-08-05 01:36:57 UTC
  • Revision ID: ricardo.kirkner@canonical.com-20110805013657-uunflpxljy4l1mi3
updated documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
Replace *settings.py* with ::
26
26
 
27
27
    import django
28
 
    from configglue.parser import SchemaConfigParser
29
 
    from django_configglue.utils import update_settings
30
28
    from django_configglue.schema import schemas
31
 
 
 
29
    from django_configglue.utils import configglue
32
30
 
33
31
    DjangoSchema = schemas.get(django.get_version())
34
 
    # parse config file
35
 
    parser = SchemaConfigParser(DjangoSchema())
36
 
    parser.read(['main.cfg', 'local.cfg'])
37
 
    update_settings(parser, locals())
38
32
 
39
 
    # keep parser reference
40
 
    __CONFIGGLUE_PARSER__ = parser
 
33
    # make django aware of configglue-based configuration
 
34
    configglue(DjangoSchema, ['main.cfg', 'local.cfg'], __name__)
41
35
 
42
36
 
43
37
This code snippet defines a schema (a static description of which
161
155
and create a *custom.cfg* file with the following content::
162
156
 
163
157
    [django]
164
 
    installed_apps = django.contrib.auth
165
 
                     django.contrib.contenttypes
166
 
                     django.contrib.sessions
167
 
                     django.contrib.sites
168
 
                     django_configglue
 
158
    installed_apps =
 
159
        django.contrib.auth
 
160
        django.contrib.contenttypes
 
161
        django.contrib.sessions
 
162
        django.contrib.sites
 
163
        django_configglue
169
164
 
170
165
The *INSTALLED_APPS* setting will be read from the *custom.cfg* configuration
171
166
file, as can be verified by running ::
240
235
Take care that the specified value has to be valid according the the option's
241
236
type, as defined by it's schema, as it will be casted to match it.
242
237
 
243
 
In this example, the type for *INTERNAL_IPS* is a `TupleConfigOption`, so the
 
238
In this example, the type for *INTERNAL_IPS* is a `TupleOption`, so the
244
239
value will be interpreted as a tuple of strings, separated by commas.
245
240
 
246
241
 
268
263
    $ python manage.py settings --django_site_id=foo
269
264
    Traceback (most recent call last):
270
265
    ...
271
 
    ValueError: Invalid value 'foo' for IntConfigOption 'site_id' in section 'django'. Original exception was: invalid literal for int() with base 10: 'foo'.
 
266
    ValueError: Invalid value 'foo' for IntOption 'site_id' in section 'django'. Original exception was: invalid literal for int() with base 10: 'foo'.
272
267
 
273
268
If, on the other hand, an invalid section name is used that will be reported
274
269
too. Edit the *custom.cfg* file so that the section name reads ::
284
279
    $ python manage.py settings --validate
285
280
    Error: Settings did not validate againt schema.
286
281
 
287
 
    Sections in configuration do not match schema: dajngo, __main__
 
282
    Sections in configuration are missing from schema: dajngo
288
283
 
289
284
it will be noted that the *dajngo* section is not valid according to the
290
285
schema used.
291
286
 
292
 
.. note:: __main__ should not be listed as an invalid section.
293
 
    This is a bug and has already been reported as such.
294
 
 
295