doc/book/en/A02b-components.en.txt
changeset 280 ce829abf7c29
parent 268 0575e7973c5e
child 1463 136756fff6fb
equal deleted inserted replaced
277:a11a3c231050 280:ce829abf7c29
     3 .. _cubes:
     3 .. _cubes:
     4 
     4 
     5 Cubes
     5 Cubes
     6 -----
     6 -----
     7 
     7 
     8 What is a cube ?
       
     9 ~~~~~~~~~~~~~~~~
       
    10 
       
    11 A cube is a model grouping one or more entity types and/or views associated
       
    12 in order to provide a specific feature or even a complete application using
       
    13 others cubes.
       
    14 
       
    15 You can decide to write your own set of cubes if you wish to re-use the 
       
    16 entity types you develop. Lots of cubes are available from the `CubicWeb
       
    17 Forge`_ under a free software license.
       
    18 
       
    19 .. _`CubicWeb Forge`: http://www.cubicweb.org/project/
       
    20 
       
    21 Standard library
     8 Standard library
    22 ~~~~~~~~~~~~~~~~
     9 ~~~~~~~~~~~~~~~~
    23 
    10 
    24 A library of standard cubes is part of the `CubicWeb` release (look at the
    11 A library of standard cubes are available from `CubicWeb Forge`_
    25 output of ``cubicweb-ctl list``). Cubes provide entities and views.
    12 Cubes provide entities and views.
    26 
    13 
    27 The available application entities are:
    14 The available application entities are:
    28 
    15 
    29 * addressbook: PhoneNumber and PostalAddress
    16 * addressbook: PhoneNumber and PostalAddress
    30 
    17 
    57 
    44 
    58 Adding comments to BlogDemo
    45 Adding comments to BlogDemo
    59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    60 
    47 
    61 To import a cube in your application just change the line in the
    48 To import a cube in your application just change the line in the
    62 ``app.conf`` file. For example::
    49 ``__pkginfo__.py`` file and verify that the cube you are planning
       
    50 to use is listed by the command ``cubicweb-ctl list``.
       
    51 For example::
    63 
    52 
    64     included-yams-cubes=comment
    53     __use__ = ('comment',)
    65 
    54 
    66 will make the ``Comment`` entity available in your ``BlogDemo``
    55 will make the ``Comment`` entity available in your ``BlogDemo``
    67 application.
    56 application.
    68 
    57 
    69 Change the schema to add a relationship between ``BlogEntry`` and
    58 Change the schema to add a relationship between ``BlogEntry`` and
    72 
    61 
    73     comments = ObjectRelation('Comment', cardinality='1*', composite='object')
    62     comments = ObjectRelation('Comment', cardinality='1*', composite='object')
    74 
    63 
    75 to the definition of a ``BlogEntry`` will be enough.
    64 to the definition of a ``BlogEntry`` will be enough.
    76 
    65 
    77 Clear the datastore and restart.
    66 Synchronize the data model
       
    67 ~~~~~~~~~~~~~~~~~~~~~~~~~~
    78 
    68 
    79 Cube structure
    69 Once you modified your data model, you need to synchronize the
    80 ~~~~~~~~~~~~~~
    70 database with your model. For this purpose, `CubicWeb` provides
    81 
    71 a very usefull command ``cubicweb-ctl shell blogdemo`` which
    82 A complex  cube is structured as follows:
    72 launches an interactive migration Python shell. (see 
       
    73 :ref:`cubicweb-ctl-shell` for more details))
       
    74 As you modified a relation from the `BlogEntry` schema,
       
    75 run the following command:
    83 ::
    76 ::
    84 
    77 
    85   mycube/
    78   synchronize_rschema('BlogEntry')
    86   |
    79   
    87   |-- schema.py
    80 You can now start your application and add comments to each 
    88   |
    81 `BlogEntry`.
    89   |-- entities/
       
    90   |
       
    91   |-- sobjects/
       
    92   |
       
    93   |-- views/
       
    94   |
       
    95   |-- test/
       
    96   |
       
    97   |-- i18n/
       
    98   |
       
    99   |-- data/
       
   100   |
       
   101   |-- migration/
       
   102   | |- postcreate.py
       
   103   | \- depends.map
       
   104   |
       
   105   |-- debian/
       
   106   |
       
   107   \-- __pkginfo__.py
       
   108 
       
   109 We can also define simple Python module instead of directories (packages), for example:
       
   110 ::
       
   111 
       
   112   mycube/
       
   113   |
       
   114   |-- entities.py
       
   115   |-- hooks.py
       
   116   \-- views.py
       
   117 
       
   118 
       
   119 where:
       
   120 
       
   121 * ``schema`` contains the definition of the schema (server side only)
       
   122 * ``entities`` contains entities definition (server side and web interface)
       
   123 * ``sobjects`` contains hooks and/or notification views (server side only)
       
   124 * ``views`` contains the web interface components (web interface only)
       
   125 * ``test`` contains tests related to the application (not installed)
       
   126 * ``i18n`` contains messages catalogs for supported languages (server side and
       
   127   web interface)
       
   128 * ``data`` contains data files for static content (images, css, javascripts)
       
   129   ...(web interface only)
       
   130 * ``migration`` contains initialization file for new instances (``postcreate.py``)
       
   131   and a file containing dependencies of the component depending on the version
       
   132   (``depends.map``)
       
   133 * ``debian`` contains all the files managing debian packaging (you will find
       
   134   the usual files ``control``, ``rules``, ``changelog``... not installed)
       
   135 * file ``__pkginfo__.py`` provides component meta-data, especially the distribution
       
   136   and the current version(server side and web interface) or sub-components used by
       
   137   the component.
       
   138  
       
   139 At least you should have:
       
   140 
       
   141 * the file ``__pkginfo__.py``
       
   142 * schema definition
       
   143 
       
   144 [WRITE ME]
       
   145 
       
   146 * explain the cube architecture
       
   147 
       
   148 * add comments to the blog by importing the comments cube