~fgallina/python-timeline-django/no-query-fix

« back to all changes in this revision

Viewing changes to README

  • Committer: Tarmac
  • Author(s): James Westby
  • Date: 2012-02-22 23:02:35 UTC
  • mfrom: (1.5.2 readme)
  • Revision ID: tarmac@server-5390-20120222230235-rjb4ldda34q2uufq
[r=james-w] Put something in the README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
timeline_django
 
2
===============
 
3
 
 
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.
 
7
 
 
8
wsgi
 
9
----
 
10
 
 
11
When running under wsgi you need to do the following things. Firstly add::
 
12
 
 
13
    timeline_django.middleware.TimelineMiddleware
 
14
 
 
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.
 
17
 
 
18
Then you need to change the way you set up your WSGI application in your WSGI
 
19
script::
 
20
 
 
21
    from timeline import wsgi as timeline_wsgi
 
22
    from timeline_django.setup import setup as timeline_django_setup
 
23
    
 
24
    timeline_django_setup()
 
25
    application = timeline_wsgi.make_app(application)
 
26
 
 
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.
 
29
 
 
30
Other
 
31
-----
 
32
 
 
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
 
37
some other event.
 
38
 
 
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.
 
46
 
 
47
Once you have that method then you can call `timeline_django`'s setup method::
 
48
 
 
49
    from timeline_django.setup import setup
 
50
 
 
51
    setup(timeline_factory=timeline_factory)
 
52
 
 
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.
 
56
 
1
57
..
2
58
 
3
59
        Copyright (c) 2012, Canonical Ltd