doc/book/en/intro/tutorial/components.rst
changeset 1808 aa09e20dd8c0
parent 1676 543de6c7f0da
parent 1714 a721966779be
child 2172 cf8f9180e63e
equal deleted inserted replaced
1693:49075f57cf2c 1808:aa09e20dd8c0
       
     1 .. -*- coding: utf-8 -*-
       
     2 
       
     3 .. _cubes:
       
     4 
       
     5 Cubes
       
     6 -----
       
     7 
       
     8 Standard library
       
     9 ~~~~~~~~~~~~~~~~
       
    10 
       
    11 A library of standard cubes are available from `CubicWeb Forge`_
       
    12 Cubes provide entities and views.
       
    13 
       
    14 The available application entities are:
       
    15 
       
    16 * addressbook: PhoneNumber and PostalAddress
       
    17 
       
    18 * basket: Basket (like a shopping cart)
       
    19 
       
    20 * blog: Blog (a *very* basic blog)
       
    21 
       
    22 * classfolder: Folder (to organize things but grouping them in folders)
       
    23 
       
    24 * classtags: Tag (to tag anything)
       
    25 
       
    26 * file: File (to allow users to upload and store binary or text files)
       
    27 
       
    28 * link: Link (to collect links to web resources)
       
    29 
       
    30 * mailinglist: MailingList (to reference a mailing-list and the URLs
       
    31   for its archives and its admin interface)
       
    32 
       
    33 * person: Person (easily mixed with addressbook)
       
    34 
       
    35 * task: Task (something to be done between start and stop date)
       
    36 
       
    37 * zone: Zone (to define places within larger places, for example a
       
    38   city in a state in a country)
       
    39 
       
    40 The available system entities are:
       
    41 
       
    42 * comment: Comment (to attach comment threads to entities)
       
    43 
       
    44 
       
    45 Adding comments to BlogDemo
       
    46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    47 
       
    48 To import a cube in your application just change the line in the
       
    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::
       
    52 
       
    53     __use__ = ('comment',)
       
    54 
       
    55 will make the ``Comment`` entity available in your ``BlogDemo``
       
    56 application.
       
    57 
       
    58 Change the schema to add a relationship between ``BlogEntry`` and
       
    59 ``Comment`` and you are done. Since the comment cube defines the
       
    60 ``comments`` relationship, adding the line::
       
    61 
       
    62     comments = ObjectRelation('Comment', cardinality='1*', composite='object')
       
    63 
       
    64 to the definition of a ``BlogEntry`` will be enough.
       
    65 
       
    66 Synchronize the data model
       
    67 ~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    68 
       
    69 Once you modified your data model, you need to synchronize the
       
    70 database with your model. For this purpose, `CubicWeb` provides
       
    71 a very useful command ``cubicweb-ctl shell blogdemo`` which
       
    72 launches an interactive migration Python shell. (see 
       
    73 :ref:`cubicweb-ctl` for more details))
       
    74 As you modified a relation from the `BlogEntry` schema,
       
    75 run the following command:
       
    76 ::
       
    77 
       
    78   synchronize_rschema('BlogEntry')
       
    79   
       
    80 You can now start your application and add comments to each 
       
    81 `BlogEntry`.