doc/tutorials/advanced/part01_create-cube.rst
author Laurent Wouters <lwouters@cenotelie.fr>
Fri, 20 Mar 2020 14:34:07 +0100
changeset 12931 6eae252361e5
parent 12927 89acc8d3d462
permissions -rw-r--r--
[rql] Store selected variables for RQL select queries in ResultSet (#17218476) By storing the name of the selected variables for RQL select queries in the ResultSet (within the "variables" attribute), the information can be passed down to specific protocols, e.g. rqlio that may wish to pass is down further to clients. In turn, clients can then choose to present the results of RQL select queries as symbolic bindings using the names used in the query's projection, instead of ordinal arrays.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
.. _TutosPhotoWebSiteCubeCreation:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
Cube creation and schema definition
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
-----------------------------------
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
.. _adv_tuto_create_new_cube:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
     8
Step 1: creating a virtual environment
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
     9
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    10
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    11
Fisrt I need a python virtual environment with cubicweb::
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    12
12533
3657b5d82590 [doc] make the tutorial use a python3 virtualenv
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12530
diff changeset
    13
  python3 -m venv venv
3657b5d82590 [doc] make the tutorial use a python3 virtualenv
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12530
diff changeset
    14
  . venv/bin/activate
12530
9d88e1177c35 Remove Twisted web server
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12403
diff changeset
    15
  pip install cubicweb[pyramid]
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    16
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    17
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    18
Step 2: creating a new cube for my web site
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
One note about my development environment: I wanted to use the packaged
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    22
version of CubicWeb and cubes while keeping my cube in the current
12535
7dbb523d5421 [doc] fix reference to ~src/cubes in tutorial
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12534
diff changeset
    23
directory, let's say `~/src/cubes`::
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
12535
7dbb523d5421 [doc] fix reference to ~src/cubes in tutorial
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12534
diff changeset
    25
  cd ~/src/cubes
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
  CW_MODE=user
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
I can now create the cube which will hold custom code for this web
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
site using::
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    31
  cubicweb-ctl newcube sytweb
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
12389
385a1d11dfeb [doc] make this step more obvious
Laurent Peuch <cortex@worlddomination.be>
parents: 12388
diff changeset
    33
Enter a short description and this will create your new cube in the
385a1d11dfeb [doc] make this step more obvious
Laurent Peuch <cortex@worlddomination.be>
parents: 12388
diff changeset
    34
`cubicweb-sytweb` folder.
385a1d11dfeb [doc] make this step more obvious
Laurent Peuch <cortex@worlddomination.be>
parents: 12388
diff changeset
    35
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
.. _adv_tuto_assemble_cubes:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    38
Step 3: pick building blocks into existing cubes
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
Almost everything I want to handle in my web-site is somehow already modelized in
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
existing cubes that I'll extend for my need. So I'll pick the following cubes:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    44
* `folder <https://www.cubicweb.org/project/cubicweb-folder>`_, containing the
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    45
  `Folder` entity type, which will be used as both 'album' and a way to map
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    46
  file system folders. Entities are added to a given folder using the
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    47
  `filed_under` relation.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    49
* `file <https://www.cubicweb.org/project/cubicweb-file>`_, containing `File`
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    50
  entity type, gallery view, and a file system import utility.
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    51
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    53
* `person <https://www.cubicweb.org/project/cubicweb-person>`_, containing the
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    54
  `Person` entity type plus some basic views.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    56
* `comment <https://www.cubicweb.org/project/cubicweb-comment>`_, providing a
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    57
  full commenting system allowing one to comment entity types supporting the
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    58
  `comments` relation by adding a `Comment` entity.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    60
* `tag <https://www.cubicweb.org/project/cubicweb-tag>`_, providing a full
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    61
  tagging system as an easy and powerful way to classify entities supporting
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    62
  the `tags` relation by linking the to `Tag` entities. This will allows
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    63
  navigation into a large number of picture.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    65
Ok, now I'll tell my cube requires all this by editing :file:`cubicweb-sytweb/cubicweb_sytweb/__pkginfo__.py`:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
  .. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
12388
83269385a51d [doc] move to latest CW version for cube creation
Laurent Peuch <cortex@worlddomination.be>
parents: 12209
diff changeset
    69
    __depends__ = {'cubicweb': '>= 3.26.7',
6923
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
    70
                   'cubicweb-file': '>= 1.9.0',
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    71
                   'cubicweb-folder': '>= 1.1.0',
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    72
                   'cubicweb-person': '>= 1.2.0',
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    73
                   'cubicweb-comment': '>= 1.2.0',
12927
89acc8d3d462 [doc] Remove zone cube which causes to crash on install
Elodie Thieblin <ethieblin@logilab.fr>
parents: 12535
diff changeset
    74
                   'cubicweb-tag': '>= 1.2.0'
89acc8d3d462 [doc] Remove zone cube which causes to crash on install
Elodie Thieblin <ethieblin@logilab.fr>
parents: 12535
diff changeset
    75
                   }
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
Notice that you can express minimal version of the cube that should be used,
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
`None` meaning whatever version available. All packages starting with 'cubicweb-'
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    79
will be recognized as being cube, not bare python packages.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
6923
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
    81
If your cube is packaged for debian, it's a good idea to update the
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
    82
`debian/control` file at the same time, so you won't forget it.
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
    83
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    84
Now, I need to install all the dependencies::
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    85
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    86
  cd cubicweb-sytweb
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    87
  pip install -e .
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    88
  pip install cubicweb[etwist]
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    89
  pip install psycopg2 # for postgresql
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    90
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    91
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    92
Step 4: glue everything together in my cube's schema
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    94
12394
e847b5d1ffff [doc] always put file name for code example and uses :file:`path` syntax everywhere
Laurent Peuch <cortex@worlddomination.be>
parents: 12393
diff changeset
    95
Put this code in :file:`cubicweb-sytweb/cubicweb_sytweb/schema.py`:
e847b5d1ffff [doc] always put file name for code example and uses :file:`path` syntax everywhere
Laurent Peuch <cortex@worlddomination.be>
parents: 12393
diff changeset
    96
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    97
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    98
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    99
    from yams.buildobjs import RelationDefinition
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   101
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
    class comments(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   103
        subject = 'Comment'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   104
        object = 'File'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   105
        # a Comment can be on only one File
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   106
        # but a File can have several comments
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   107
        cardinality = '1*'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   108
        composite = 'object'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   109
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   110
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
    class tags(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   112
        subject = 'Tag'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   113
        object = 'File'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   114
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   115
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   116
    class filed_under(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   117
        subject = 'File'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   118
        object = 'Folder'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   119
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   120
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   121
    class displayed_on(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   122
        subject = 'Person'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   123
        object = 'File'
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   124
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   126
This schema:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   127
6923
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
   128
* allows to comment and tag on `File` entity type by adding the `comments` and
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
   129
  `tags` relations. This should be all we've to do for this feature since the
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
   130
  related cubes provide 'pluggable section' which are automatically displayed on
327443ec7120 [doc] update photo web site tutorial: we're starting from cw 3.10/file 1.9+
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6876
diff changeset
   131
  the primary view of entity types supporting the relation.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   133
* adds a `situated_in` relation definition so that image entities can be
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
  geolocalized.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
* add a new relation `displayed_on` relation telling who can be seen on a
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
  picture.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
This schema will probably have to evolve as time goes (for security handling at
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   140
least), but since the possibility to let a schema evolve is one of CubicWeb's
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
features (and goals), we won't worry about it for now and see that later when needed.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   143
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
   144
Step 5: creating the instance
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   146
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
Now that I have a schema, I want to create an instance. To
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
do so using this new 'sytweb' cube, I run::
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
  cubicweb-ctl create sytweb sytweb_instance
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   151
12391
e4e5814fd70c [doc] recommend sqlite during tutorial because it's simplier to use
Laurent Peuch <cortex@worlddomination.be>
parents: 12390
diff changeset
   152
For simplicity you should use the sqlite database, it won't require
e4e5814fd70c [doc] recommend sqlite during tutorial because it's simplier to use
Laurent Peuch <cortex@worlddomination.be>
parents: 12390
diff changeset
   153
configuration.
e4e5814fd70c [doc] recommend sqlite during tutorial because it's simplier to use
Laurent Peuch <cortex@worlddomination.be>
parents: 12390
diff changeset
   154
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
   155
Don't forget to say "yes" to the question: `Allow anonymous access ? [y/N]:`
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
   156
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   157
Hint: if you get an error while the database is initialized, you can
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   158
avoid having to answer the questions again by running::
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   159
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   160
   cubicweb-ctl db-create sytweb_instance
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   161
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   162
This will use your already configured instance and start directly from the create
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   163
database step, thus skipping questions asked by the 'create' command.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   164
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   165
Once the instance and database are fully initialized, run ::
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   166
12534
e0e7d8ca051f [doc] replace cubicweb-ctl start by cubicweb-ctl pyramid
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12533
diff changeset
   167
  cubicweb-ctl pyramid -D sytweb_instance
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   168
12393
ea198374785b [doc] explicitely give the local server url to make this step more obvious
Laurent Peuch <cortex@worlddomination.be>
parents: 12392
diff changeset
   169
to start the instance, check you can connect on it, etc... then go on
ea198374785b [doc] explicitely give the local server url to make this step more obvious
Laurent Peuch <cortex@worlddomination.be>
parents: 12392
diff changeset
   170
http://localhost:8080 (or with another port if you've modified it)