/
schemas.txt
72 lines (49 loc) · 2.51 KB
/
schemas.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
###########################
Write configuration schemas
###########################
**As a Django application developer**, you want to expose configuration
directives. You want to make sure your application is well configured. As an
example, you appreciate to mark some directives as required, and to provide
default values for optional ones. But you do not want to re-invent the wheel
about validation.
**As a Django user**, you do not want to bother about application configuration
schemas. You just want it loaded when you register the application in
``INSTALLED_APPS``.
This sections explains how to create with `django-confit`.
*******************************************
Create settings_schemas.ConfigurationSchema
*******************************************
See:
* `colander's documentation`_
* `django-confit's builtin schemas`_
Simple example from `custom schemas in django-confit demo project`_:
.. literalinclude:: /../demo/django_confit_demo/settings_schemas.py
:language: python
.. warning::
In `django-confit` code, you will see some hacks around versions of
applications. Yes, they are **hacks**. They are necessary because from the
`django-confit` point of view, we do not know which version of the
application is actually installed. So we have to write conditionals in order
to support them as well as possible... But it is a true pain.
**Just imagine the schema lives within the third-party application
itself...** As a consequence:
* one schema is enough. No need to manage concurrent schemas. The one for
the current version is enough.
* the schema is updated along the application. It is part of the
application's release process.
* as an user, you do not have to find or write a schema for the application.
There is an official one! You install the app, you get the schema!
********************
Register your schema
********************
In a project or a third-party application, register schemas in
``settings.CONFIT_SCHEMAS``. See :doc:`configure`.
In `django-confit` itself, make sure the schema can be loaded with
``django_confit.schemas.<APP>.ConfigurationSchema``.
.. rubric:: Notes & references
.. target-notes::
.. _`colander's documentation`: http://docs.pylonsproject.org/projects/colander
.. _`django-confit's builtin schemas`:
https://github.com/benoitbryon/django-confit/tree/master/django_confit/schemas
.. _`custom schemas in django-confit demo project`:
https://github.com/benoitbryon/django-confit/blob/master/demo/django_confit_demo/settings_schemas.py