doc/book/en/A03a-concepts.en.txt
changeset 1221 d474534fd04d
parent 466 bef394c66f10
child 1398 5fe84a5f7035
equal deleted inserted replaced
1220:9f80ecdb057a 1221:d474534fd04d
    10 ~~~~~~~~~~~~~~~~~~~
    10 ~~~~~~~~~~~~~~~~~~~
    11 .. image:: images/archi_globale.en.png
    11 .. image:: images/archi_globale.en.png
    12 
    12 
    13 
    13 
    14 `CubicWeb` framework is a server/client application framework. Those two
    14 `CubicWeb` framework is a server/client application framework. Those two
    15 parties communicates through RQL (`CubicWeb` query language implementation)
    15 parts communicate through RQL (`CubicWeb` query language implementation)
    16 and ResultSet (which will be explained in :ref:`TermsVocabulary`).
    16 and ResultSet (which will be explained in :ref:`TermsVocabulary`).
    17 
    17 
    18 The server manages all interactions with sources.
    18 The server manages all interactions with sources.
    19 
    19 
    20 
    20 
    21 .. note::
    21 .. note::
    22   For real, the client and server sides are integrated in the same
    22   Usually, the client and server sides are integrated in the same
    23   process and interact directly, without the needs for distants
    23   process and interact directly, without the need for distant
    24   calls using Pyro. It is important to note down that those two
    24   calls using Pyro. But, it is important to note that those two
    25   sides, client/server, are disjointed and it is possible to execute
    25   sides, client/server, are disjointed and it is possible to execute
    26   a couple of calls in distincts processes to balance the load of
    26   a couple of calls in distinct processes to balance the load of
    27   your web site on one or more machines.
    27   your web site on one or more machines.
    28 
    28 
    29 .. _TermsVocabulary:
    29 .. _TermsVocabulary:
    30 
    30 
    31 Terms and vocabulary
    31 Terms and vocabulary
    40   The schema defines the data model of an application based on entities
    40   The schema defines the data model of an application based on entities
    41   and relations, modeled with a comprehensive language made of Python
    41   and relations, modeled with a comprehensive language made of Python
    42   classes based on `yams`_ library. This is the core piece
    42   classes based on `yams`_ library. This is the core piece
    43   of an application. It is initially defined in the file system and is
    43   of an application. It is initially defined in the file system and is
    44   stored in the database at the time an instance is created. `CubicWeb`
    44   stored in the database at the time an instance is created. `CubicWeb`
    45   provides a certain number of system entities included automatically as
    45   provides a certain number of system entities included automatically    
    46   it is necessary for the core of `CubicWeb` and a library of
    46   (necessary for the core of `CubicWeb`) and a library of
    47   cubes (which defined application entities) that can be explicitely
    47   cubes (which defined application entities) that can be explicitely
    48   included if necessary.
    48   included if necessary.
    49 
    49 
    50 *entity type*
    50 *entity type*
    51   An entity type is a set of attributes; the essential attribute of
    51   An entity type is a set of attributes; the essential attribute of
    55   Entities are linked to each others by relations. In `CubicWeb`
    55   Entities are linked to each others by relations. In `CubicWeb`
    56   relations are binary: by convention we name the first item of
    56   relations are binary: by convention we name the first item of
    57   a relation the `subject` and the second the `object`.
    57   a relation the `subject` and the second the `object`.
    58 
    58 
    59 *final entity type*
    59 *final entity type*
    60   Final types corresponds to the basic types such as string of characters,
    60   Final types correspond to the basic types such as string of characters,
    61   integers... Those types have a main property which is that they can
    61   integers... Those types have a main property which is that they can
    62   only be used as `object` of a relation. The attributes of an entity
    62   only be used as `object` of a relation. The attributes of an entity
    63   (non final) are entities (finals).
    63   (non final) are entities (finals).
    64 
    64 
    65 *final relation type*
    65 *final relation type*
    76 
    76 
    77 *source*
    77 *source*
    78   A data source is a container of data (SGBD, LDAP directory, `Google
    78   A data source is a container of data (SGBD, LDAP directory, `Google
    79   App Engine`'s datastore ...) integrated in the
    79   App Engine`'s datastore ...) integrated in the
    80   `CubicWeb` repository. This repository has at least one source, `system` which
    80   `CubicWeb` repository. This repository has at least one source, `system` which
    81   contains the schema of the application, plain-text index and others
    81   contains the schema of the application, plain-text index and other
    82   vital informations for the system.
    82   vital informations for the system.
    83 
    83 
    84 *configuration*
    84 *configuration*
    85   It is possible to create differents configurations for an instance:
    85   It is possible to create different configurations for an instance:
    86 
    86 
    87   - ``repository`` : repository only, accessible for clients using Pyro
    87   - ``repository`` : repository only, accessible for clients using Pyro
    88   - ``twisted`` : web interface only, access the repository using Pyro
    88   - ``twisted`` : web interface only, access the repository using Pyro
    89   - ``all-in-one`` : web interface and repository in a single process.
    89   - ``all-in-one`` : web interface and repository in a single process.
    90      The repository could be or not accessible using Pyro.
    90      The repository could be or not accessible using Pyro.
    91 
    91 
    92 *cube*
    92 *cube*
    93   A cube is a model grouping one or multiple data types and/or views
    93   A cube is a model grouping one or multiple data types and/or views
    94   to provide a specific functionnality or a complete `CubicWeb` application
    94   to provide a specific functionality or a complete `CubicWeb` application
    95   potentially using other cubes. The available cubes are located in the file
    95   potentially using other cubes. The available cubes are located in the file
    96   system at `/path/to/forest/cubicweb/cubes` for a Mercurial forest installation,
    96   system at `/path/to/forest/cubicweb/cubes` for a Mercurial forest installation.
    97   for a debian packages installation they will be located in
    97   For a debian packages installation they will be located in
    98   `/usr/share/cubicweb/cubes`.
    98   `/usr/share/cubicweb/cubes`.
    99   Larger applications can be built faster by importing cubes,
    99   Larger applications can be built quite fast by importing cubes,
   100   adding entities and relationships and overriding the
   100   adding entities and relationships, overriding the
   101   views that need to display or edit informations not provided by
   101   *views* that display the cubes or by editing informations not provided by
   102   cubes.
   102   the cubes.
   103 
   103 
   104 *instance*
   104 *instance*
   105   An instance is a specific installation of one or multiple cubes. All the required
   105   An instance is a specific installation of one or multiple cubes. All the required
   106   configuration files necessary for the well being of your web application
   106   configuration files necessary for the well being of your web application
   107   are grouped in an instance. This will refer to the cube(s) your application
   107   are grouped in an instance. This will refer to the cube(s) your application
   108   is based on.
   108   is based on.
   109   For example logilab.org and our intranet are two instances of a single
   109   For example logilab.org and our intranet are two instances of a single
   110   cube jpl, developped internally.
   110   cube "jpl", developped internally.
   111   The instances are defined in the directory `/etc/cubicweb.d`.
   111   The instances are defined in the directory `/etc/cubicweb.d`.
   112 
   112 
   113 *application*
   113 *application*
   114   The term application is sometime used to talk about an instance
   114   The term application is sometimes used to talk about an instance
   115   and sometimes to talk of a cube depending on the context.
   115   and sometimes to talk of a cube depending on the context.
   116   So we would like to avoid using this term and try to use *cube* and
   116   So we would like to avoid using this term and try to use *cube* and
   117   *instance* instead.
   117   *instance* instead.
   118 
   118 
   119 *result set*
   119 *result set*
   141   views are not very fancy, it is usually necessary to develop your
   141   views are not very fancy, it is usually necessary to develop your
   142   own. Any generated view can be overridden by defining a new one with
   142   own. Any generated view can be overridden by defining a new one with
   143   the same identifier.
   143   the same identifier.
   144 
   144 
   145 *rql*
   145 *rql*
   146  Relation Query Language in order to empasize the way of browsing relations.
   146  Relation Query Language in order to emphasize the way of browsing relations.
   147  This query language is inspired by SQL but is highest level, its implementation
   147  This query language is inspired by SQL but is on a higher level;
   148  generates SQL.
   148  its implementation generates SQL.
   149 
   149 
   150 
   150 
   151 .. _`Python Remote Object`: http://pyro.sourceforge.net/
   151 .. _`Python Remote Object`: http://pyro.sourceforge.net/
   152 .. _`yams`: http://www.logilab.org/project/yams/
   152 .. _`yams`: http://www.logilab.org/project/yams/
   153 
   153 
   154 
   154 
   155 `CubicWeb` engine
   155 `CubicWeb` engine
   156 ~~~~~~~~~~~~~~~~~
   156 ~~~~~~~~~~~~~~~~~
   157 
   157 
   158 The engine in `CubicWeb` is a set of classes managing a set of objects loaded
   158 The engine in `CubicWeb` is a set of classes managing a set of objects loaded
   159 dynamically at the startup of `CubicWeb` (*appobjects*). Those dynamics objects,
   159 dynamically at the startup of `CubicWeb` (*appobjects*). Those dynamic objects,
   160 based on the schema or the library, are building the final application.
   160 based on the schema or the library, are building the final application.
   161 The differents dymanic components are for example:
   161 The different dynamic components are for example:
   162 
   162 
   163 * client and server side
   163 * client and server side
   164 
   164 
   165   - entities definition, containing the logic which enables application data manipulation
   165   - entities definition, containing the logic which enables application data manipulation
   166 
   166 
   198 The most important method is the `execute` method of a cursor :
   198 The most important method is the `execute` method of a cursor :
   199 
   199 
   200 `execute(rqlstring, args=None, eid_key=None, build_descr=True)`
   200 `execute(rqlstring, args=None, eid_key=None, build_descr=True)`
   201 
   201 
   202 :rqlstring: the RQL query to execute (unicode)
   202 :rqlstring: the RQL query to execute (unicode)
   203 :args: if the query contains substitutions, a dictionnary containing the values to use
   203 :args: if the query contains substitutions, a dictionary containing the values to use
   204 :eid_key:
   204 :eid_key:
   205    an implementation detail of the RQL queries cache implies that if a substitution
   205    an implementation detail of the RQL cache implies that if a substitution
   206    is used to introduce an eid *susceptible to raise the ambiguities in the query
   206    is used to introduce an eid *susceptible to raise the ambiguities in the query
   207    type resolution*, then we have to specify the correponding key in the dictionnary
   207    type resolution*, then we have to specify the corresponding key in the dictionary
   208    through this argument
   208    through this argument
   209 
   209 
   210 
   210 
   211 The `Connection` object owns the methods `commit` and `rollback`. You *should
   211 The `Connection` object owns the methods `commit` and `rollback`. You *should
   212 never need to use them* during the development of the web interface based on
   212 never need to use them* during the development of the web interface based on
   213 the `CubicWeb` framework as it determines the end of the transaction depending
   213 the `CubicWeb` framework as it determines the end of the transaction depending
   214 on the query execution success.
   214 on the query execution success.
   215 
   215 
   216 .. note::
   216 .. note::
   217   While executing updates queries (SET, INSERT, DELETE), if a query generates
   217   While executing update queries (SET, INSERT, DELETE), if a query generates
   218   an error related to security, a rollback is automatically done on the current
   218   an error related to security, a rollback is automatically done on the current
   219   transaction.
   219   transaction.
   220 
   220 
   221 
   221 
   222 The `Request` class (`cubicweb.web`)
   222 The `Request` class (`cubicweb.web`)
   223 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   223 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   224 
   224 
   225 A request instance is created when an HTTP request is sent to the web server.
   225 A request instance is created when an HTTP request is sent to the web server.
   226 It contains informations such as forms parameters, user authenticated, etc.
   226 It contains informations such as form parameters, user authenticated, etc.
   227 
   227 
   228 **Globally, a request represents a user query, either through HTTP or not
   228 **Globally, a request represents a user query, either through HTTP or not
   229 (we also talk about RQL queries on the server side for example).**
   229 (we also talk about RQL queries on the server side for example).**
   230 
   230 
   231 An instance of `Request` has the following attributes:
   231 An instance of `Request` has the following attributes:
   232 
   232 
   233 * `user`, instance of `cubicweb.common.utils.User` corresponding to the authenticated
   233 * `user`, instance of `cubicweb.common.utils.User` corresponding to the authenticated
   234   user
   234   user
   235 * `form`, dictionnary containing the values of a web form
   235 * `form`, dictionary containing the values of a web form
   236 * `encoding`, characters encoding to use in the response
   236 * `encoding`, character encoding to use in the response
   237 
   237 
   238 But also:
   238 But also:
   239 
   239 
   240 :Session data handling:
   240 :Session data handling:
   241   * `session_data()`, returns a dictionnary containing all the session data
   241   * `session_data()`, returns a dictionary containing all the session data
   242   * `get_session_data(key, default=None)`, returns a value associated to the given
   242   * `get_session_data(key, default=None)`, returns a value associated to the given
   243     key or the value `default` if the key is not defined
   243     key or the value `default` if the key is not defined
   244   * `set_session_data(key, value)`, assign a value to a key
   244   * `set_session_data(key, value)`, assign a value to a key
   245   * `del_session_data(key)`,  suppress the value associated to a key
   245   * `del_session_data(key)`,  suppress the value associated to a key
   246 
   246 
   247 
   247 
   248 :Cookies handling:
   248 :Cookies handling:
   249   * `get_cookie()`, returns a dictionnary containing the value of the header
   249   * `get_cookie()`, returns a dictionary containing the value of the header
   250     HTTP 'Cookie'
   250     HTTP 'Cookie'
   251   * `set_cookie(cookie, key, maxage=300)`, adds a header HTTP `Set-Cookie`,
   251   * `set_cookie(cookie, key, maxage=300)`, adds a header HTTP `Set-Cookie`,
   252     with a minimal 5 minutes length of duration by default (`maxage` = None
   252     with a minimal 5 minutes length of duration by default (`maxage` = None
   253     returns a *session* cookie which will expire when the user closes the browser
   253     returns a *session* cookie which will expire when the user closes the browser
   254     window)
   254     window)
   266     of the HTTP request
   266     of the HTTP request
   267   * `set_header(header, value)`, adds an arbitrary header in the response
   267   * `set_header(header, value)`, adds an arbitrary header in the response
   268   * `cursor()` returns a RQL cursor on the session
   268   * `cursor()` returns a RQL cursor on the session
   269   * `execute(*args, **kwargs)`, shortcut to ``.cursor().execute()``
   269   * `execute(*args, **kwargs)`, shortcut to ``.cursor().execute()``
   270   * `property_value(key)`, properties management (`EProperty`)
   270   * `property_value(key)`, properties management (`EProperty`)
   271   * dictionnary `data` to store data to share informations between components
   271   * dictionary `data` to store data to share informations between components
   272     *while a request is executed*
   272     *while a request is executed*
   273 
   273 
   274 Please note that this class is abstract and that a concrete implementation
   274 Please note that this class is abstract and that a concrete implementation
   275 will be provided by the *frontend* web used (in particular *twisted* as of
   275 will be provided by the *frontend* web used (in particular *twisted* as of
   276 today). For the views or others that are executed on the server side,
   276 today). For the views or others that are executed on the server side,
   370 What is a cube ?
   370 What is a cube ?
   371 ````````````````
   371 ````````````````
   372 
   372 
   373 A cube is a model grouping one or more entity types and/or views associated
   373 A cube is a model grouping one or more entity types and/or views associated
   374 in order to provide a specific feature or even a complete application using
   374 in order to provide a specific feature or even a complete application using
   375 others cubes.
   375 other cubes.
   376 
   376 
   377 You can decide to write your own set of cubes if you wish to re-use the
   377 You can decide to write your own set of cubes if you wish to re-use the
   378 entity types you develop. Lots of cubes are available from the `CubicWeb
   378 entity types you develop. Lots of cubes are available from the `CubicWeb
   379 Forge`_ under a free software license.
   379 Forge`_ under a free software license.
   380 
   380 
   458 * ``schema`` contains the schema definition (server side only)
   458 * ``schema`` contains the schema definition (server side only)
   459 * ``entities`` contains the entities definition (server side and web interface)
   459 * ``entities`` contains the entities definition (server side and web interface)
   460 * ``sobjects`` contains hooks and/or views notifications (server side only)
   460 * ``sobjects`` contains hooks and/or views notifications (server side only)
   461 * ``views`` contains the web interface components (web interface only)
   461 * ``views`` contains the web interface components (web interface only)
   462 * ``test`` contains tests related to the application (not installed)
   462 * ``test`` contains tests related to the application (not installed)
   463 * ``i18n`` contains messages catalogs for supported languages (server side and
   463 * ``i18n`` contains message catalogs for supported languages (server side and
   464   web interface)
   464   web interface)
   465 * ``data`` contains data files for static content (images, css, javascripts)
   465 * ``data`` contains data files for static content (images, css, javascripts)
   466   ...(web interface only)
   466   ...(web interface only)
   467 * ``migration`` contains initialization file for new instances (``postcreate.py``)
   467 * ``migration`` contains initialization file for new instances (``postcreate.py``)
   468   and a file containing dependencies of the component depending on the version
   468   and a file containing dependencies of the component depending on the version
   477 At least you should have:
   477 At least you should have:
   478 
   478 
   479 * the file ``__pkginfo__.py``
   479 * the file ``__pkginfo__.py``
   480 * the schema definition
   480 * the schema definition
   481   XXX false, we may want to have cubes which are only adding a service,
   481   XXX false, we may want to have cubes which are only adding a service,
   482   no persistent data (eg embeding for instance)
   482   no persistent data (eg embedding for instance)
   483 
   483 
   484 
   484 
   485 Standard library
   485 Standard library
   486 ````````````````
   486 ````````````````
   487 
   487