4
timeline_django inserts actions in to a `Timeline` (http://pypi.python.org/pypi/timeline/)
5
for Django db queries, and other events in Django. There is some setup required to have
6
the events inserted in the right timeline for the context.
11
When running under wsgi you need to do the following things. Firstly add::
13
timeline_django.middleware.TimelineMiddleware
15
to your middleware in settings.py. This will save the timeline for the request
16
such that it is accessible to the db layer.
18
Then you need to change the way you set up your WSGI application in your WSGI
21
from timeline import wsgi as timeline_wsgi
22
from timeline_django.setup import setup as timeline_django_setup
24
timeline_django_setup()
25
application = timeline_wsgi.make_app(application)
27
This will cause `timeline.wsgi` to put a `Timeline` in the wsgi environ, and
28
`timeline_django` to use that to log the requests.
33
If you are running in other environments you need to do some of these steps
34
yourself. First you need to pick a point to create a new `Timeline` object.
35
This needs to correspond to the start of an timeline that you want to
36
capture. That may be at the start of a script, or it may be in response to
39
Once you have created the `Timeline` you need to store it somewhere it can
40
be accessed when needed. That may be in a variable, or it may be in
41
thread-local storage if you will have multiple threads handling separate
42
timelines. Once you have the `Timline` stored you need a function that
43
will return it. That function will be your `timeline_factory`. It should take
44
no arguments and return a `Timeline` object, or `None` if there is no
45
applicable `Timeline` when it is called.
47
Once you have that method then you can call `timeline_django`'s setup method::
49
from timeline_django.setup import setup
51
setup(timeline_factory=timeline_factory)
53
where `timeline_factory` is the function you created above. That will set up the
54
hooks necessary to have an action recorded in your timeline when there is
55
a DB query, or one of the other Django events that `timeline_django` supports.
3
59
Copyright (c) 2012, Canonical Ltd