doc/book/en/devweb/controllers.rst
author Julien Jehannet <julien.jehannet@logilab.fr>
Thu, 16 Jun 2011 12:31:27 +0200
branchstable
changeset 7529 2fdc310be7cd
parent 6347 ef47a2100c66
child 7876 df15d194a134
permissions -rw-r--r--
[book] add autoload section from code and fix sphinx warnings * drop misleading faq entry since clear explanation can be found in internationalization chapter * use autodata sphinx directive instead of raw text * fill empty chapter with autodoc: - devweb/httpcaching.rst - devweb/resource.rst - devweb/views/idownloadable.rst - devweb/views/wdoc.rst * use shebang in excerpt to denote shell code * fix some bad indented docstrings in javascript files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5263
196eb979318f [doc/book] merge controller/editcontroller
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4743
diff changeset
     1
.. _controllers:
196eb979318f [doc/book] merge controller/editcontroller
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4743
diff changeset
     2
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
Controllers
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
-----------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
     6
Overview
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
     7
++++++++
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
     8
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
     9
Controllers are responsible for taking action upon user requests
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    10
(loosely following the terminology of the MVC meta pattern).
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    11
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    12
The following controllers are provided out-of-the box in CubicWeb. We
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    13
list them by category. They are all defined in
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    14
(:mod:`cubicweb.web.views.basecontrollers`).
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    15
5263
196eb979318f [doc/book] merge controller/editcontroller
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4743
diff changeset
    16
`Browsing`:
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    17
6347
ef47a2100c66 exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5459
diff changeset
    18
* the View controller is associated with most browsing actions within a
7529
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6347
diff changeset
    19
  CubicWeb application: it always instantiates a
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6347
diff changeset
    20
  :ref:`the_main_template_layout` and lets the ResultSet/Views dispatch system
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6347
diff changeset
    21
  build up the whole content; it handles :exc:`ObjectNotFound` and
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6347
diff changeset
    22
  :exc:`NoSelectableObject` errors that may bubble up to its entry point, in an
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6347
diff changeset
    23
  end-user-friendly way (but other programming errors will slip through)
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    24
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    25
* the JSon controller (same module) provides services for Ajax calls,
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    26
  typically using JSON as a serialization format for input, and
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    27
  sometimes using either JSON or XML for output;
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    28
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    29
* the Login/Logout controllers make effective user login or logout
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    30
  requests
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    31
5263
196eb979318f [doc/book] merge controller/editcontroller
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4743
diff changeset
    32
`Edition`:
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    33
5263
196eb979318f [doc/book] merge controller/editcontroller
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4743
diff changeset
    34
* the Edit controller (see :ref:`edit_controller`) handles CRUD
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    35
  operations in response to a form being submitted; it works in close
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    36
  association with the Forms, to which it delegates some of the work
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    37
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    38
* the ``Form validator controller`` provides form validation from Ajax
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    39
  context, using the Edit controller, to implement the classic form
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    40
  handling loop (user edits, hits `submit/apply`, validation occurs
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    41
  server-side by way of the Form validator controller, and the UI is
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    42
  decorated with failure information, either global or per-field ,
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    43
  until it is valid)
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    44
5263
196eb979318f [doc/book] merge controller/editcontroller
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4743
diff changeset
    45
`Other`:
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    46
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    47
* the ``SendMail controller`` (web/views/basecontrollers.py) is reponsible
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    48
  for outgoing email notifications
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    49
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    50
* the MailBugReport controller (web/views/basecontrollers.py) allows
6347
ef47a2100c66 exception: specify expected parameter in NoSelectableException
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5459
diff changeset
    51
  to quickly have a `reportbug` feature in one's application
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    52
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    53
Registration
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    54
++++++++++++
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    55
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    56
All controllers (should) live in the 'controllers' namespace within
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    57
the global registry.
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    58
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    59
Concrete controllers
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    60
++++++++++++++++++++
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    61
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    62
Most API details should be resolved by source code inspection, as the
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    63
various controllers have differing goals. See for instance the
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    64
:ref:`edit_controller` chapter.
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    65
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    66
:mod:`cubicweb.web.controller` contains the top-level abstract
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    67
Controller class and its unimplemented entry point
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5400
diff changeset
    68
`publish(rset=None)` method.
4741
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    69
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    70
A handful of helpers are also provided there:
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    71
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    72
* process_rql builds a result set from an rql query typically issued
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    73
  from the browser (and available through _cw.form['rql'])
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    74
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    75
* validate_cache will force cache validation handling with respect to
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    76
  the HTTP Cache directives (that were typically originally issued
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    77
  from a previous server -> client response); concrete Controller
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    78
  implementations dealing with HTTP (thus, for instance, not the
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    79
  SendMail controller) may very well call this in their publication
f9a176ebe090 [book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    80
  process.