doc/book/en/intro/concepts.rst
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 14 Apr 2010 16:56:33 +0200
branchstable
changeset 5257 a31fbcfa8c3b
parent 5189 84d4587a92bc
child 5306 763319a51e72
permissions -rw-r--r--
[doc/book] misc fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
     3
.. _Concepts:
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
     4
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
     5
The Core Concepts of |cubicweb|
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
     6
===============================
301
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 300
diff changeset
     7
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
     8
This section defines some terms and core concepts of the |cubicweb| framework. To
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
     9
avoid confusion while reading this book, take time to go through the following
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    10
definitions and use this section as a reference during your reading.
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    11
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    12
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    13
.. _Cube:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    14
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    15
Cubes
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    16
-----
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    17
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    18
A cube is a software component made of three parts: its data model
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    19
(:file:`schema`), its logic (:file:`entities`) and its user interface
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    20
(:file:`views`).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    21
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    22
A cube can use other cubes as building blocks and assemble them to provide a
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    23
whole with richer functionnalities than its parts. The cubes `cubicweb-blog`_ and
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    24
`cubicweb-comment`_ could be used to make a cube named *myblog* with commentable
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    25
blog entries.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    26
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    27
The `CubicWeb.org Forge`_ offers a large number of cubes developed by the community
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    28
and available under a free software license.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    29
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    30
The command :command:`cubicweb-ctl list` displays the list of cubes installed on
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    31
your system.
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    32
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    33
On a Unix system, the available cubes are usually stored in the directory
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
    34
:file:`/usr/share/cubicweb/cubes`. If you're using the cubicweb forest
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
    35
(:ref:SourceInstallation), the cubes are searched in the directory
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
    36
:file:`/path/to/cubicweb_forest/cubes`. The environment variable
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
    37
:envvar:`CW_CUBES_PATH` gives additionnal locations where to search for cubes.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    38
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    39
.. _`CubicWeb.org Forge`: http://www.cubicweb.org/project/
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    40
.. _`cubicweb-blog`: http://www.cubicweb.org/project/cubicweb-blog
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    41
.. _`cubicweb-comment`: http://www.cubicweb.org/project/cubicweb-comment
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    42
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    43
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    44
.. _Instance:
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    45
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    46
Instances
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    47
---------
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    48
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    49
An instance is a runnable application installed on a computer and based on a
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    50
cube.
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    51
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    52
The instance directory contains the configuration files. Several instances can be
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    53
created and based on the same cube. For exemple, several software forges can be
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    54
set up on one computer system based on the `cubicweb-forge`_ cube.
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    55
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    56
.. _`cubicweb-forge`: http://www.cubicweb.org/project/cubicweb-forge
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    57
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    58
Instances can be of three different types: all-in-one, web engine or data
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    59
repository. For applications that support high traffic, several web (front-end)
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    60
and data (back-end) instances can be set-up to share the load.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    61
5257
a31fbcfa8c3b [doc/book] misc fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5189
diff changeset
    62
.. image:: ../images/archi_globale.en.png
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    63
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
    64
The command :command:`cubicweb-ctl list` also displays the list of instances
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
    65
installed on your system.
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    66
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    67
On a Unix system, the instances are usually stored in the directory
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    68
:file:`/etc/cubicweb.d/`. During development, the :file:`~/etc/cubicweb.d/`
2445
6f065b366d14 rename environment variables
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2279
diff changeset
    69
directory is looked up, as well as the paths in :envvar:`CW_INSTANCES_DIR`
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    70
environment variable.
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    71
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    72
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    73
.. Note::
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    74
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    75
  The term application is used to refer to "something that should do something as
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    76
  a whole", eg more like a project and so can refer to an instance or to a cube,
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    77
  depending on the context. This book will try to use *application*, *cube* and
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    78
  *instance* as appropriate.
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    79
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    80
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    81
.. _RepositoryIntro:
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    82
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    83
Data Repository
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    84
---------------
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    85
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
    86
The data repository [1]_ provides access to one or more data sources (including
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    87
SQL databases, LDAP repositories, other |cubicweb| instance repositories, GAE's
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    88
DataStore, etc).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    89
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    90
All interactions with the repository are done using the Relation Query Language
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    91
(:ref:`RQL`). The repository federates the data sources and hides them from the
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    92
querier, which does not realize when a query spans accross several data sources
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4442
diff changeset
    93
and requires running sub-queries and merges to complete.
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    94
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    95
It is common to run the web engine and the repository in the same process (see
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4442
diff changeset
    96
instances of type all-in-one above), but this is not a requirement. A repository
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    97
can be set up to be accessed remotely using Pyro (`Python Remote Objects`_) and
5146
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
    98
act as a server. However, it's important to know if code you're writing is
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
    99
executed on the repository side, on our client side (the web engine being a
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   100
client for instance): you don't have the same abilities on both side. On the
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   101
repository side, you can for instance by-pass security checks, which isn't
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   102
possible from client code.
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   103
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   104
Some logic can be attached to events that happen in the repository, like
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   105
creation of entities, deletion of relations, etc. This is used for example to
5146
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   106
send email notifications when the state of an object changes. See :ref:`HookIntro` below.
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   107
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
   108
.. [1] not to be confused with a Mercurial repository or a Debian repository.
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   109
.. _`Python Remote Objects`: http://pyro.sourceforge.net/
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   110
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   111
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   112
.. _WebEngineIntro:
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   113
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   114
Web Engine
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   115
----------
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   116
4442
7bc0e4ed4109 fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   117
The web engine replies to http requests and runs the user interface
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   118
and most of the application logic.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   119
5144
5a09bea07302 [doc/book] a new chapter on how to use the ORM
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5143
diff changeset
   120
By default the web engine provides a `CRUD`_ user interface based on
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   121
the data model of the instance. Entities can be created, displayed,
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   122
updated and deleted. As the default user interface is not very fancy,
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   123
it is usually necessary to develop your own.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   124
5144
5a09bea07302 [doc/book] a new chapter on how to use the ORM
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5143
diff changeset
   125
.. _`CRUD`: http://en.wikipedia.org/wiki/Create,_read,_update_and_delete
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   126
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   127
.. _SchemaIntro:
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   128
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   129
Schema (Data Model)
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   130
-------------------
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   131
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   132
The data model of a cube is described as an entity-relationship schema using a
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   133
comprehensive language made of Python classes imported from the yams_ library.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   134
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   135
.. _yams: http://www.logilab.org/project/yams/
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   136
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   137
An `entity type` defines a set of attributes and is used in some relations.
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   138
Attributes may be of the following types: `String`, `Int`, `Float`, `Boolean`,
5143
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   139
`Date`, `Time`, `Datetime`, `Interval`, `Password`, `Bytes`, `RichString`.
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   140
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   141
A `relation type` is used to define an oriented binary relation between two
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   142
entity types.  The left-hand part of a relation is named the `subject` and the
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   143
right-hand part is named the `object`.
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   144
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   145
A `relation definition` is a triple (*subject entity type*, *relation type*, *object
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   146
entity type*) associated with a set of properties such as cardinality,
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   147
constraints, etc.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   148
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   149
Permissions can be set on entity types and relation definition to control who
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   150
will be able to create, read, update or delete entities and relations. Permissions
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   151
are granted to groups (to which users may belong) or using rql expression (if the
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   152
rql expression returns some results, the permission is granted).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   153
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   154
Some meta-data necessary to the system is added to the data model. That includes
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   155
entities like users and groups, the entities used to store the data model
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   156
itself and attributes like unique identifier, creation date, creator, etc.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   157
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
   158
When you create a new |cubicweb| instance, the schema is stored in the database.
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   159
When the cubes the instance is based on evolve, they may change their data model
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   160
and provide migration scripts that will be executed when the administrator will
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   161
run the upgrade process for the instance.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   162
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   163
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   164
.. _VRegistryIntro:
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   165
5143
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   166
Registries and application objects
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   167
----------------------------------
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   168
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   169
Application objects
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   170
~~~~~~~~~~~~~~~~~~~
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   171
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   172
Beside a few core functionalities, almost every feature of the framework is
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   173
achieved by dynamic objects (`application objects` or `appobjects`) stored in a
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   174
two-levels registry (the `vregistry`). Each object is affected to a registry with
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   175
an identifier in this registry. You may have more than one object sharing an
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   176
identifier in the same registry, At runtime, appobjects are selected in a
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   177
registry according to the context. Selection is done by comparing *score*
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   178
returned by each appobject's *selector*.
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   179
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   180
Application objects are stored in the vregistry using a two-level hierarchy :
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   181
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   182
  object's `__registry__` : object's `__regid__` : [list of app objects]
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   183
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   184
E.g. The `vregistry` contains several registries which hold a list of
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   185
appobjects associated to an identifier.
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   186
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   187
The base class of appobjects is :class:`cubicweb.appobject.AppObject`.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   188
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   189
Selectors
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   190
~~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   191
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   192
Each appobject has a selector, that is used to compute how well the object fits a
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   193
given context. The better the object fits the context, the higher the score. They
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   194
are the glue that tie appobjects to the data model. Using them appropriately is
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   195
an essential part of the construction of well behaved cubes.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   196
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   197
|cubicweb| provides a set of basic selectors that may be parametrized.  Also,
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   198
selectors can be combined with the `~` unary operator (negation) and the binary
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   199
operators `&` and `|` (respectivly 'and' and 'or') to build more complex
5143
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   200
selector. Of course complex selector may be combined too. Last but not least, you
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   201
can write your own selectors.
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   202
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   203
The `vregistry`
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   204
~~~~~~~~~~~~~~~
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   205
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   206
At startup, the `vregistry` inspects a number of directories looking for
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   207
compatible classes definition. After a recording process, the objects are
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   208
assigned to registries so that they can be selected dynamically while the
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   209
instance is running.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   210
5143
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   211
In a cube, application object classes are looked in the following modules or
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   212
packages:
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   213
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   214
- `entities`
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   215
- `views`
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   216
- `sobjects`
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   217
- `hooks`
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   218
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   219
5143
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   220
Once initialized, there are three common ways to retrieve some application object
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   221
from a registry:
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   222
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   223
* get the most appropriate object by specifying an identifier. In that case, the
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   224
  object with the greatest score is selected. There should always be a single
5143
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   225
  appobject with a greater score than others for a particular context.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   226
5143
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   227
* get all objects applying to a context by specifying a registry. In that case, a
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   228
  list of objects will be returned containing the object with the highest score
43afbdd5c8b4 improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5134
diff changeset
   229
  (> 0) for each identifier in that registry.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   230
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   231
* get the object within a particular registry/identifier. In that case no
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   232
  selection process is involved, the vregistry will expect to find a single
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   233
  object in that cell.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   234
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   235
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   236
.. _RQLIntro:
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   237
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   238
The RQL query language
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   239
----------------------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   240
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   241
**No need for a complicated ORM when you have a powerful query language**
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   242
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   243
All the persistent data in a |cubicweb| instance is retrieved and modified by
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   244
using the Relation Query Language.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   245
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   246
This query language is inspired by SQL but is on a higher level in order to
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   247
emphasize browsing relations.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   248
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   249
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   250
db-api
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   251
~~~~~~
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   252
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   253
The repository exposes a `db-api`_ like api but using the RQL instead of SQL.
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   254
5146
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   255
You basically get a connection using :func:`cubicweb.dbapi.connect` , then
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   256
get a cursor to call its `execute` method which will return result set for the
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   257
given rql query.
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   258
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   259
You can also get additional information through the connection, such as the
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   260
repository'schema, version configuration, etc.
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   261
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   262
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   263
Result set
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   264
~~~~~~~~~~
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   265
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   266
Every request made (using RQL) to the data repository returns an object we call a
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   267
Result Set. It enables easy use of the retrieved data, providing a translation
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   268
layer between the backend's native datatypes and |cubicweb| schema's EntityTypes.
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   269
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   270
Result sets provide access to the raw data, yielding either basic Python data
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   271
types, or schema-defined high-level entities, in a straightforward way.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   272
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   273
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   274
.. _ViewIntro:
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   275
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   276
Views
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   277
-----
2279
b4e970513117 [doc] improve description of core concepts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   278
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   279
**CubicWeb is data driven**
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   280
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   281
The view system is loosely coupled to data through the selection system explained
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   282
above. Views are application objects with a dedicated interface to 'render'
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   283
something, eg producing some html, text, xml, pdf, or whatsover that can be
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   284
displayed to a user.
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   285
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   286
The two main entry points of a view are:
119
7a56ca431d65 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   287
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   288
* `call()`, used to render a view on a context with no result set, or on a whole
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   289
  result set
3283
4f53eb3f1331 more doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3258
diff changeset
   290
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   291
* `cell_call(row, col)`, used to render a view on a the cell with index `row` and
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   292
  `col` of the context's result set (remember result set may be seen as a two
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   293
  dimensions array).
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   294
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   295
Then view may gets refined into different kind of objects such as `template`,
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   296
`boxes`, `components`, which are more high-level abstraction useful to build
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   297
the user interface in an object oriented way.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   298
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   299
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   300
.. _HookIntro:
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   301
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   302
Hooks and operations
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   303
--------------------
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
   304
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
   305
**CubicWeb provides an extensible data repository**
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   306
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   307
The data model defined using Yams types allows to express the data
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   308
model in a comfortable way. However several aspects of the data model
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   309
can not be expressed there. For instance:
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   310
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   311
* managing computed attributes
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   312
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   313
* enforcing complicated structural invariants
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   314
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   315
* real-world side-effects linked to data events (email notification
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   316
  being a prime example)
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   317
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   318
The hook system is much like the triggers of an SQL database engine,
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   319
except that:
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   320
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   321
* it is not limited to one specific SQL backend (every one of them
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   322
  having an idiomatic way to encode triggers), nor to SQL backends at
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   323
  all (think about LDAP or a Subversion repository)
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   324
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   325
* it is well-coupled to the rest of the framework
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   326
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   327
Hooks are also application objects registered on events such as after/before
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   328
add/update/delete on entities/relations, server startup or shutdown, etc. As all
5146
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   329
application objects, they have a selector defining when they should be called or
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   330
not.
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   331
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   332
`Operations` may be instantiated by hooks to do further processing at different
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   333
steps of the transaction's commit / rollback, which usually can not be done
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   334
safely at the hook execution time.
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   335
5134
910e021131d1 [doc] enhanced concepts section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   336
Hooks and operation are an essential building block of any moderately complicated
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2535
diff changeset
   337
cubicweb application.
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3283
diff changeset
   338
5146
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   339
.. Note:
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   340
   RQL queries executed in hooks and operations are *unsafe* by default, e.g. the
fe56baf63ecb add note about running repository / client code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5144
diff changeset
   341
   read and write security is deactivated unless explicitly asked.
5189
84d4587a92bc [doc/book] rql/dbapi cleanup, rip cachekey (prematurely ?)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5150
diff changeset
   342
5144
5a09bea07302 [doc/book] a new chapter on how to use the ORM
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5143
diff changeset
   343
.. |cubicweb| replace:: *CubicWeb*