author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 15 Apr 2010 17:28:27 +0200 | |
branch | stable |
changeset 5290 | 15846058378b |
parent 5231 | 40f53867e332 |
child 5301 | f4219a6e62e3 |
permissions | -rw-r--r-- |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
The `Request` class (`cubicweb.web`) |
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
2 |
------------------------------------ |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
3 |
|
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
4 |
Overview |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
5 |
```````` |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
6 |
|
4442
7bc0e4ed4109
fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
7 |
A request instance is created when an HTTP request is sent to the web server. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
It contains informations such as form parameters, user authenticated, etc. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
9 |
|
4442
7bc0e4ed4109
fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
10 |
**Globally, a request represents a user query, either through HTTP or not |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
(we also talk about RQL queries on the server side for example).** |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
13 |
An instance of `Request` has the following attributes: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
14 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
* `user`, instance of `cubicweb.common.utils.User` corresponding to the authenticated |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
16 |
user |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
* `form`, dictionary containing the values of a web form |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
18 |
* `encoding`, character encoding to use in the response |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
19 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
But also: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
21 |
|
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
22 |
* `Session data handling` |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
23 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
* `session_data()`, returns a dictionary containing all the session data |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
* `get_session_data(key, default=None)`, returns a value associated to the given |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
key or the value `default` if the key is not defined |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
* `set_session_data(key, value)`, assign a value to a key |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
* `del_session_data(key)`, suppress the value associated to a key |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
|
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
30 |
* `Cookies handling` |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
31 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
* `get_cookie()`, returns a dictionary containing the value of the header |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
HTTP 'Cookie' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
* `set_cookie(cookie, key, maxage=300)`, adds a header HTTP `Set-Cookie`, |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
with a minimal 5 minutes length of duration by default (`maxage` = None |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
returns a *session* cookie which will expire when the user closes the browser |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
window) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
* `remove_cookie(cookie, key)`, forces a value to expire |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
|
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
40 |
* `URL handling` |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
41 |
|
4442
7bc0e4ed4109
fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
42 |
* `url()`, returns the full URL of the HTTP request |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
* `base_url()`, returns the root URL of the web application |
4442
7bc0e4ed4109
fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
44 |
* `relative_path()`, returns the relative path of the request |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
|
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
46 |
* `And more...` |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
47 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
* `set_content_type(content_type, filename=None)`, adds the header HTTP |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
'Content-Type' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
* `get_header(header)`, returns the value associated to an arbitrary header |
4442
7bc0e4ed4109
fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
51 |
of the HTTP request |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
* `set_header(header, value)`, adds an arbitrary header in the response |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
* `cursor()` returns a RQL cursor on the session |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
* `execute(*args, **kwargs)`, shortcut to ``.cursor().execute()`` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
* `property_value(key)`, properties management (`CWProperty`) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
* dictionary `data` to store data to share informations between components |
4442
7bc0e4ed4109
fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
57 |
*while a request is executed* |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
Please note that this class is abstract and that a concrete implementation |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
will be provided by the *frontend* web used (in particular *twisted* as of |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
today). For the views or others that are executed on the server side, |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
most of the interface of `Request` is defined in the session associated |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
to the client. |
5231
40f53867e332
[doc/book] misc fixes/enhancements & notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4442
diff
changeset
|
64 |
|
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
65 |
Automatic API |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
66 |
````````````` |
5231
40f53867e332
[doc/book] misc fixes/enhancements & notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4442
diff
changeset
|
67 |
|
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
68 |
The elements we gave in overview for above are built in three layers, |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
69 |
from ``cubicweb.req.RequestSessionBase``, ``cubicweb.dbapi.DBAPIRequest`` and |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
70 |
``cubicweb.web.CubicWebRequestBase``. |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
71 |
|
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
72 |
.. autoclass:: cubicweb.req.RequestSessionBase |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
73 |
:members: |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
74 |
|
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
75 |
.. autoclass:: cubicweb.dbapi.DBAPIRequest |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
76 |
:members: |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
77 |
|
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
78 |
.. autoclass:: cubicweb.web.request.CubicWebRequestBase |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5231
diff
changeset
|
79 |
:members: |