doc/book/en/tutorials/base/create-cube.rst
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 17 Jun 2010 17:49:58 +0200
branchstable
changeset 5781 a3e60e0fb0f3
parent 5432 ee246e1813c6
child 6152 6824f8b61098
permissions -rw-r--r--
[doc/book/faq] question on security
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
     3
.. _Steps:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
     4
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
     5
Steps for creating your cube
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
     6
----------------------------
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
     7
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
     8
The following steps will help you to create and customize a new cube.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
     9
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    10
1. :ref:`CreateYourCube`
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    11
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
    12
Create the directory to hold the code of your cube. The most important
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
    13
files that will be useful to customize your newly created cube are:
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
    14
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    15
  * schema.py: contains the data model
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    16
  * views.py: contains your custom views
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
    17
  * entities.py: contains XXX
4450
8000abf9c9d3 fix bad rest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
    18
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    19
The detailed structure of the code directory is described in :ref:`cubelayout`.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    20
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    21
2. :ref:`DefineDataModel`
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    22
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    23
Define the data model of your application.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    24
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    25
3. :ref:`ExploreYourInstance`
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    26
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    27
Create, run, and explore an instance of your cube.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    28
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    29
4. :ref:`DefineViews`
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    30
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
    31
Customize the views of your data: how and which part of your data are showed.
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    32
5432
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
    33
.. note:: views do not define the look'n'feel and the design of your application. For that, you will use CSS and the files located 'blog/data/'.
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    34
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    35
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    36
5. :ref:`DefineEntities`
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    37
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    38
Define your own entities to add useful functions when you manipulate your data, especially when you write view.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    39
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    40
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    41
.. _CreateYourCube:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    42
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    43
Create your cube
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    44
----------------
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    45
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    46
The packages ``cubicweb`` and ``cubicweb-dev`` install a command line
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    47
tool for *CubicWeb* called ``cubicweb-ctl``. This tool provides a wide
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    48
range of commands described in details in :ref:`cubicweb-ctl`.
1674
e4383a510089 [doc] Add brief reference to the chapter cubicweb-ctl tool.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1440
diff changeset
    49
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    50
Once your *CubicWeb* development environment is set up, you can create
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    51
a new cube::
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    52
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    53
  cubicweb-ctl newcube blog
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    54
272
06077d56f2c4 [doc] Does not keep mercurial forest as the only reference for path description.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 268
diff changeset
    55
This will create in the cubes directory (``/path/to/forest/cubes`` for Mercurial
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
    56
installation, ``/usr/share/cubicweb/cubes`` for debian packages installation)
2544
282261b26774 [doc] fixed some dangling internal links
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2535
diff changeset
    57
a directory named ``blog`` reflecting the structure described in :ref:`Concepts`.
280
ce829abf7c29 [doc] Improved tutoriel. Moved appropriate content to cubicweb foundations chapter. Adds section to fill about cubicweb-ctl shell.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 272
diff changeset
    58
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    59
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    60
For packages installation, you can still create new cubes in your home directory using the following configuration. Let's say you want to develop your new cubes in `~src/cubes`, then set the following environment variables:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    61
::
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    62
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    63
  CW_CUBES_PATH=~/src/cubes
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    64
  CW_MODE=user
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    65
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    66
and then create your new cube using:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    67
::
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    68
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    69
  cubicweb-ctl newcube --directory=~/src/cubes blog
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    70
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    71
255
5d2804b9a28c [doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 229
diff changeset
    72
.. _DefineDataModel:
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    73
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
    74
Define your data model
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
    75
----------------------
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    76
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
    77
The data model or schema is the core of your *CubicWeb* application.
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
    78
It defines the type of content your application will handle.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    79
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
    80
The data model of your cube ``blog`` is defined in the file ``schema.py``:
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    81
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
    82
.. sourcecode:: python
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    83
4143
e6d936eef7aa [mq]: doc
Charles Hébert
parents: 3293
diff changeset
    84
  from yams.buildobjs import EntityType, String, SubjectRelation, Date
e6d936eef7aa [mq]: doc
Charles Hébert
parents: 3293
diff changeset
    85
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    86
  class Blog(EntityType):
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
    87
    title = String(maxsize=50, required=True)
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    88
    description = String()
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    89
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    90
  class BlogEntry(EntityType):
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
    91
    title = String(required=True, fulltextindexed=True, maxsize=256)
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    92
    publish_date = Date(default='TODAY')
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
    93
    content = String(required=True, fulltextindexed=True)
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
    94
    entry_of = SubjectRelation('Blog', cardinality='?*')
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    95
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
    96
The first step is the import of the EntityType (generic class for entity and
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
    97
attributes that will be used in both Blog and BlogEntry entities.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    98
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    99
A Blog has a title and a description. The title is a string that is
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   100
required and must be less than 50 characters.  The
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   101
description is a string that is not constrained.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   102
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   103
A BlogEntry has a title, a publish_date and a content. The title is a
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   104
string that is required and must be less than 100 characters. The
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   105
publish_date is a Date with a default value of TODAY, meaning that
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   106
when a BlogEntry is created, its publish_date will be the current day
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   107
unless it is modified. The content is a string that will be indexed in
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   108
the database full-text index and has no constraint.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   109
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   110
A BlogEntry also has a relationship ``entry_of`` that links it to a
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   111
Blog. The cardinality ``?*`` means that a BlogEntry can be part of
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   112
zero or one Blog (``?`` means `zero or one`) and that a Blog can
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   113
have any number of BlogEntry (``*`` means `any number including
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   114
zero`). For completeness, remember that ``+`` means `one or more`.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   115
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   116
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   117
.. _ExploreYourInstance:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   118
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   119
Create and explore your instance
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   120
--------------------------------
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   121
.. _CreateYourInstance:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   122
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   123
Create your instance
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   124
~~~~~~~~~~~~~~~~~~~~
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   125
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2175
diff changeset
   126
To use this cube as an instance and create a new instance named ``blogdemo``, do::
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
   127
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   128
  cubicweb-ctl create blog blogdemo
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   129
4143
e6d936eef7aa [mq]: doc
Charles Hébert
parents: 3293
diff changeset
   130
This command will create the corresponding database and initialize it.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   131
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   132
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   133
.. _WelcomeToYourWebInstance:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   134
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2175
diff changeset
   135
Welcome to your web instance
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   136
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   137
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2175
diff changeset
   138
Start your instance in debug mode with the following command: ::
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   139
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   140
  cubicweb-ctl start -D blogdemo
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   141
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   142
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2175
diff changeset
   143
You can now access your web instance to create blogs and post messages
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   144
by visiting the URL http://localhost:8080/.
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   145
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2175
diff changeset
   146
A login form will appear. By default, the instance will not allow anonymous
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2175
diff changeset
   147
users to enter the instance. To login, you need then use the admin account
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   148
you created at the time you initialized the database with ``cubicweb-ctl
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   149
create``.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   150
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1440
diff changeset
   151
.. image:: ../../images/login-form.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   152
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   153
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2175
diff changeset
   154
Once authenticated, you can start playing with your instance
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   155
and create entities.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   156
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents: 1440
diff changeset
   157
.. image:: ../../images/blog-demo-first-page.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   158
2535
c7b736929a58 [doc] a bit of rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2476
diff changeset
   159
Please notice that so far, the *CubicWeb* framework managed all aspects of
c7b736929a58 [doc] a bit of rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2476
diff changeset
   160
the web application based on the schema provided at the beginning.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   162
.. _AddEntities:
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   163
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   164
Add entities
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   165
~~~~~~~~~~~~
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   166
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   167
We will now add entities in our web application.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   168
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   169
Add a Blog
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   170
**********
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   171
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   172
Let us create a few of these entities. Click on the `[+]` at the left of the
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   173
link Blog on the home page. Call this new Blog ``Tech-blog`` and type in
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   174
``everything about technology`` as the description, then validate the form by
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   175
clicking on ``Validate``.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   176
5388
9167751463d4 [doc/book] rename images with non suffix dots to please latex
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5311
diff changeset
   177
.. image:: ../../images/cbw-create-blog_en.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   178
   :alt: from to create blog
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   179
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   180
Click on the logo at top left to get back to the home page, then
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   181
follow the Blog link that will list for you all the existing Blog.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   182
You should be seeing a list with a single item ``Tech-blog`` you
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   183
just created.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   184
5388
9167751463d4 [doc/book] rename images with non suffix dots to please latex
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5311
diff changeset
   185
.. image:: ../../images/cbw-list-one-blog_en.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   186
   :alt: displaying a list of a single blog
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   187
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   188
Clicking on this item will get you to its detailed description except
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   189
that in this case, there is not much to display besides the name and
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   190
the phrase ``everything about technology``.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   191
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   192
Now get back to the home page by clicking on the top-left logo, then
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   193
create a new Blog called ``MyLife`` and get back to the home page
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   194
again to follow the Blog link for the second time. The list now
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   195
has two items.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   196
5388
9167751463d4 [doc/book] rename images with non suffix dots to please latex
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5311
diff changeset
   197
.. image:: ../../images/cbw-list-two-blog_en.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   198
   :alt: displaying a list of two blogs
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   199
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   200
Add a BlogEntry
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   201
***************
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   202
268
0575e7973c5e [doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 255
diff changeset
   203
Get back to the home page and click on [+] at the left of the link
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   204
BlogEntry. Call this new entry ``Hello World`` and type in some text
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   205
before clicking on ``Validate``. You added a new blog entry without
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   206
saying to what blog it belongs. There is a box on the left entitled
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   207
``actions``, click on the menu item ``modify``. You are back to the form
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   208
to edit the blog entry you just created, except that the form now has
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   209
another section with a combobox titled ``add relation``. Chose
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   210
``entry_of`` in this menu and a second combobox appears where you pick
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
   211
``MyLife``.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   212
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   213
You could also have, at the time you started to fill the form for a
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
   214
new entity BlogEntry, hit ``Apply`` instead of ``Validate`` and the
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   215
combobox titled ``add relation`` would have showed up.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   216
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   217
5388
9167751463d4 [doc/book] rename images with non suffix dots to please latex
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5311
diff changeset
   218
.. image:: ../../images/cbw-add-relation-entryof_en.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   219
   :alt: editing a blog entry to add a relation to a blog
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   220
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   221
Validate the changes by clicking ``Validate``. The entity BlogEntry
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   222
that is displayed now includes a link to the entity Blog named
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   223
``MyLife``.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   224
5388
9167751463d4 [doc/book] rename images with non suffix dots to please latex
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5311
diff changeset
   225
.. image:: ../../images/cbw-detail-one-blogentry_en.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   226
   :alt: displaying the detailed view of a blogentry
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   227
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   228
Note that all of this was handled by the framework and that the only input
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   229
that was provided so far is the schema. To get a graphical view of the schema,
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   230
point your browser to the URL http://localhost:8080/schema
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   231
5388
9167751463d4 [doc/book] rename images with non suffix dots to please latex
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5311
diff changeset
   232
.. image:: ../../images/cbw-schema_en.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   233
   :alt: graphical view of the schema (aka data-model)
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   234
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   235
255
5d2804b9a28c [doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 229
diff changeset
   236
.. _DefineViews:
5d2804b9a28c [doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 229
diff changeset
   237
1249
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   238
Define your entity views
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   239
------------------------
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   240
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   241
Each entity defined in a model is associated with default views
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
   242
allowing different renderings of the data. You can redefine each of
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   243
them according to your needs and preferences. So let's see how the
1249
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   244
views are defined.
280
ce829abf7c29 [doc] Improved tutoriel. Moved appropriate content to cubicweb foundations chapter. Adds section to fill about cubicweb-ctl shell.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 272
diff changeset
   245
ce829abf7c29 [doc] Improved tutoriel. Moved appropriate content to cubicweb foundations chapter. Adds section to fill about cubicweb-ctl shell.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 272
diff changeset
   246
1249
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   247
The view selection principle
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   248
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   249
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
   250
A view is defined by a Python class which includes:
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
   251
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   252
  - an identifier (all objects in *CubicWeb* are recorded in a
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   253
    registry and this identifier will be used as a key)
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
   254
1249
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   255
  - a filter to select the result sets it can be applied to
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   256
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   257
A view has a set of methods complying with the `View` class interface
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   258
(`cubicweb.common.view`).
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   259
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
   260
*CubicWeb* provides a lot of standard views for the type `EntityView`;
1249
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   261
for a complete list, read the code in directory ``cubicweb/web/views/``.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   262
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   263
A view is applied on a `result set` which contains a set of entities
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   264
we are trying to display. *CubicWeb* uses a selector mechanism which
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   265
computes for each available view a score: the view with the highest
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   266
score is then used to display the given `result set`.  The standard
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   267
library of selectors is in ``cubicweb.selector``.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   268
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   269
It is possible to define multiple views for the same identifier
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   270
and to associate selectors and filters to allow the application
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   271
to find the most appropriate way to render the data.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   272
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   273
For example, the view named ``primary`` is the one used to display a
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   274
single entity. We will now show you how to create a primary view for
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   275
BlogEntry.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   276
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   277
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   278
Primary view customization
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   279
~~~~~~~~~~~~~~~~~~~~~~~~~~
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   280
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   281
If you wish to modify the way a `BlogEntry` is rendered, you will have
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   282
to subclass the `primary` view, for instance in the module ``views``
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   283
of the cube ``cubes/blog/views.py``.
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   284
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   285
The standard primary view is the most sophisticated view of all. It
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   286
has more than a call() method. It is a template. Actually the entry
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   287
point calls the following sequence of (redefinable) methods:
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   288
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   289
 * render_entity_title
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   290
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   291
 * render_entity_metadata
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   292
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   293
 * render_entity_attributes
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   294
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   295
 * render_entity_relations
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   296
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   297
 * render_side_boxes
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   298
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   299
Excepted side boxes, we can see all of them already in action in the
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   300
blog entry view. This is all described in more details in
5306
763319a51e72 [doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5253
diff changeset
   301
:ref:`primary_view`.
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   302
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   303
We can for example add in front of the publication date a prefix
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   304
specifying that the date we see is the publication date.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   305
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   306
To do so, please apply the following changes:
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   307
2545
f8246ed962f6 [doc] replace code-block with sourcecode
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2544
diff changeset
   308
.. sourcecode:: python
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   309
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   310
  from cubicweb.selectors import implements
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   311
  from cubicweb.web.views import primary
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   312
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   313
  class BlogEntryPrimaryView(primary.PrimaryView):
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   314
      __select__ = implements('BlogEntry')
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   315
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   316
      def render_entity_attributes(self, entity):
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   317
          self.w(u'<p>published on %s</p>' %
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   318
                 entity.publish_date.strftime('%Y-%m-%d'))
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   319
          super(BlogEntryPrimaryView, self).render_entity_attributes(entity)
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   320
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   321
.. note::
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   322
  When a view is modified, it is not required to restart the instance
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   323
  server. Save the Python file and reload the page in your web browser
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   324
  to view the changes.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   325
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   326
You can now see that the publication date has a prefix.
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   327
5388
9167751463d4 [doc/book] rename images with non suffix dots to please latex
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5311
diff changeset
   328
.. image:: ../../images/cbw-update-primary-view_en.png
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   329
   :alt: modified primary view
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   330
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   331
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1808
diff changeset
   332
The above source code defines a new primary view for ``BlogEntry``.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   333
1249
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   334
Since views are applied to result sets and result sets can be tables of
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   335
data, we have to recover the entity from its (row,col)-coordinates.
1253
9716a9f77980 [doc] some improvements on Views
Emile Anclin <emile.anclin@logilab.fr>
parents: 1249
diff changeset
   336
The view has a ``self.w()`` method that is used to output data, in our
9716a9f77980 [doc] some improvements on Views
Emile Anclin <emile.anclin@logilab.fr>
parents: 1249
diff changeset
   337
example HTML output.
117
22c0fad39c13 [doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   338
2544
282261b26774 [doc] fixed some dangling internal links
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2535
diff changeset
   339
.. note::
4936
a4b772a0d801 Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4450
diff changeset
   340
   You can find more details about views and selectors in :ref:`Views`.
1249
905d76e38433 [doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents: 296
diff changeset
   341
1253
9716a9f77980 [doc] some improvements on Views
Emile Anclin <emile.anclin@logilab.fr>
parents: 1249
diff changeset
   342
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   343
.. _DefineEntities:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   344
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   345
Write entities to add logic in your data
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   346
----------------------------------------
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   347
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
   348
By default, CubicWeb provides a default entity for each data type defined in the schema.
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
   349
A default entity mainly contains the attributes defined in the data model.
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   350
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
   351
You can redefine each entity to provide additional functions to help you write your views.
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   352
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   353
.. sourcecode:: python
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   354
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   355
    from cubicweb.entities import AnyEntity
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   356
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   357
    class BlogEntry(AnyEntity):
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   358
        """customized class for BlogEntry entities"""
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   359
    	__regid__ = 'BlogEntry'
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
   360
    	__implements__ = AnyEntity.__implements__
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   361
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   362
        def display_cw_logo(self):
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   363
            if 'CW' in self.title:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   364
                return True
5253
7ee07d18dc95 [doc/book] include sylvain great advanced tutorial, move tutorials in one proper section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4936
diff changeset
   365
            else:
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   366
                return False
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   367
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   368
Customizing an entity requires that your entity:
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   369
 - inherits from ``cubicweb.entities`` or any subclass
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   370
 - defines a ``__regid__`` linked to the corresponding data type of your schema
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   371
 - implements the base class by explicitly using ``__implements__``.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   372
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   373
We implemented here a function ``display_cw_logo`` which tests if the blog entry title contains 'CW'.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   374
This function can then be used when you customize your views. For instance, you can modify your previous ``views.py`` as follows:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   375
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   376
.. sourcecode:: python
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   377
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   378
 class BlogEntryPrimaryView(primary.PrimaryView):
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   379
     __select__ = implements('BlogEntry')
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   380
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   381
     ...
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   382
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   383
     def render_entity_title(self, entity):
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   384
	 if entity.display_cw_logo():
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   385
	     self.w(u'<image src="http://www.cubicweb.org/doc/en/_static/cubicweb.png"/>')
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   386
	 super(BlogEntryPrimaryView, self).render_entity_title(entity)
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   387
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   388
Then each blog entry whose title contains 'CW' is shown with the CubicWeb logo in front of it.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   389
4450
8000abf9c9d3 fix bad rest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   390
.. _UpdatingSchemaAndSynchronisingInstance:
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   391
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   392
Updating the schema and synchronising the instance
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   393
--------------------------------------------------
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   394
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   395
While developping your cube, you may want to update your data model. Let's say you
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   396
want to add a ``category`` attribute in the ``Blog`` data type. This is called a migration.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   397
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   398
The required steps are:
5432
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   399
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   400
1. modify the file ``schema.py``. The ``Blog`` class looks now like this:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   401
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   402
.. sourcecode:: python
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   403
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   404
 class Blog(EntityType):
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   405
   title = String(maxsize=50, required=True)
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   406
   description = String()
4446
a413fac5ff5e damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   407
   category = String(required=True, vocabulary=(_('Professional'), _('Personal')), default='Personal')
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   408
5432
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   409
2. stop your ``blogdemo`` instance:
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   410
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   411
.. sourcecode:: bash
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   412
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   413
  cubicweb-ctl stop blogdemo
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   414
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   415
3. start the cubicweb shell for your instance by running the following command:
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   416
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   417
.. sourcecode:: bash
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   418
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   419
  cubicweb-ctl shell blogdemo
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   420
5432
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   421
4. at the cubicweb shell prompt, execute:
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   422
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   423
.. sourcecode:: python
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   424
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   425
 add_attribute('Blog', 'category')
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   426
5432
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   427
5. restart your instance:
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   428
   
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   429
.. sourcecode:: bash
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   430
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   431
  cubicweb-ctl start blogdemo
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   432
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   433
6. modify a blog entity and check that the new attribute
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   434
``category`` has been added.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   435
5432
ee246e1813c6 [doc] various small improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5388
diff changeset
   436
Of course, you may also want to add relations, entity types, etc. See :ref:`migration`
4431
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   437
for a list of all available migration commands.
e597e0ca67cd Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4143
diff changeset
   438