doc/book/en/development/devweb/request.rst
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 13 Apr 2010 19:22:46 +0200
branchstable
changeset 5231 40f53867e332
parent 4442 7bc0e4ed4109
child 5290 15846058378b
permissions -rw-r--r--
[doc/book] misc fixes/enhancements & notes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
The `Request` class (`cubicweb.web`)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
4442
7bc0e4ed4109 fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
     4
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
     5
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
     6
4442
7bc0e4ed4109 fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
     7
**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
     8
(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
     9
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
An instance of `Request` has the following attributes:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
* `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
    13
  user
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
* `form`, dictionary containing the values of a web form
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
* `encoding`, character encoding to use in the response
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
But also:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
:Session data handling:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
  * `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
    21
  * `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
    22
    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
    23
  * `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
    24
  * `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
    25
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
:Cookies handling:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
  * `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
    29
    HTTP 'Cookie'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
  * `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
    31
    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
    32
    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
    33
    window)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
  * `remove_cookie(cookie, key)`, forces a value to expire
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
:URL handling:
4442
7bc0e4ed4109 fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
    37
  * `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
    38
  * `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
    39
  * `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
    40
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
:And more...:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
  * `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
    43
    'Content-Type'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
  * `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
    45
    of the HTTP request
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
  * `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
    47
  * `cursor()` returns a RQL cursor on the session
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
  * `execute(*args, **kwargs)`, shortcut to ``.cursor().execute()``
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
  * `property_value(key)`, properties management (`CWProperty`)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    50
  * 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
    51
    *while a request is executed*
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    53
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
    54
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
    55
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
    56
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
    57
to the client.
5231
40f53867e332 [doc/book] misc fixes/enhancements & notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4442
diff changeset
    58
40f53867e332 [doc/book] misc fixes/enhancements & notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4442
diff changeset
    59
40f53867e332 [doc/book] misc fixes/enhancements & notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4442
diff changeset
    60
XXX autoclass !
40f53867e332 [doc/book] misc fixes/enhancements & notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4442
diff changeset
    61
XXX create_entity