doc/tutorials/advanced/part01_create-cube.rst
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 21 Mar 2019 14:33:54 +0100
changeset 12530 9d88e1177c35
parent 12403 d901fc62eb01
child 12533 3657b5d82590
permissions -rw-r--r--
Remove Twisted web server Twisted web server is not used anymore and has been superseded by pyramid many years ago. Furthermore, our usage is not compatible with Python 3. So we drop the "etwist" sub-package. As a consequence, "all-in-one" configuration type gets dropped as it was Twisted-specific. We resurrect it in cubicweb/pyramid/config.py by only keeping options used by the "pyramid". Similarly, we introduce a AllInOneCreateHandler in cubicweb/pyramid/pyramidctl.py that is basically the one that lived in cubicweb/etwist/twctl.py and is used to create the "all-in-one" instance. Added a TODO here about "pyramid.ini" that could be generated at the end of bootstrap() method. In cubicweb/devtools/httptest.py, CubicWebServerTC is now equivalent to CubicWebWsgiTC and the latter is dropped.
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
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    13
  virtualenv python-2.7.5_cubicweb
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    14
  . /python-2.7.5_cubicweb/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
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
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
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
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
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
.. _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
    38
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    39
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
    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
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
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
    43
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
    44
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    45
* `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
    46
  `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
    47
  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
    48
  `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
    49
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    50
* `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
    51
  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
    52
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    53
* `zone <https://www.cubicweb.org/project/cubicweb-zone>`_, containing the
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    54
  `Zone` entity type for hierarchical geographical zones. Entities (including
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    55
  sub-zones) are added to a given zone using the `situated_in` 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
    56
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    57
* `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
    58
  `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
    59
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    60
* `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
    61
  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
    62
  `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
    63
12390
d9196c0420fe [doc] add a link to every cube documentation page
Laurent Peuch <cortex@worlddomination.be>
parents: 12389
diff changeset
    64
* `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
    65
  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
    66
  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
    67
  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
    68
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    69
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
    70
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
    71
  .. 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
    72
12388
83269385a51d [doc] move to latest CW version for cube creation
Laurent Peuch <cortex@worlddomination.be>
parents: 12209
diff changeset
    73
    __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
    74
                   'cubicweb-file': '>= 1.9.0',
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    75
                   'cubicweb-folder': '>= 1.1.0',
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    76
                   'cubicweb-person': '>= 1.2.0',
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    77
                   'cubicweb-comment': '>= 1.2.0',
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    78
                   'cubicweb-tag': '>= 1.2.0',
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
    79
                   'cubicweb-zone': None}
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
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
    81
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
    82
`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
    83
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
    84
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
    85
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
    86
`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
    87
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    88
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
    89
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    90
  cd cubicweb-sytweb
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    91
  pip install -e .
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    92
  pip install cubicweb[etwist]
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    93
  pip install psycopg2 # for postgresql
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    94
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    95
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
    96
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
    97
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
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
    99
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
   100
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
   101
.. 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
   102
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
   103
    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
   104
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   105
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
   106
    class comments(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   107
        subject = 'Comment'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   108
        object = 'File'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   109
        # 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
   110
        # 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
   111
        cardinality = '1*'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   112
        composite = 'object'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   113
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
   114
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
    class tags(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   116
        subject = 'Tag'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   117
        object = 'File'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   118
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
   119
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
    class filed_under(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   121
        subject = 'File'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   122
        object = 'Folder'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   123
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
    class situated_in(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   126
        subject = 'File'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   127
        object = 'Zone'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   128
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
   129
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
   130
    class displayed_on(RelationDefinition):
12403
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   131
        subject = 'Person'
d901fc62eb01 [doc] pep8 and retab in tutorial code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12402
diff changeset
   132
        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
   133
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
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
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
   136
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
   137
* 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
   138
  `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
   139
  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
   140
  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
   141
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
* 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
   143
  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
   144
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
* 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
   146
  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
   147
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
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
   149
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
   150
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
   151
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
   152
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
   153
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
   154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
   155
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
   156
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
   157
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
   158
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
  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
   160
12391
e4e5814fd70c [doc] recommend sqlite during tutorial because it's simplier to use
Laurent Peuch <cortex@worlddomination.be>
parents: 12390
diff changeset
   161
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
   162
configuration.
e4e5814fd70c [doc] recommend sqlite during tutorial because it's simplier to use
Laurent Peuch <cortex@worlddomination.be>
parents: 12390
diff changeset
   163
12209
3a3551fff787 [doc] Update the advanced tutorial
Olivier Giorgis <olivier.giorgis@logilab.fr>
parents: 10491
diff changeset
   164
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
   165
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
   166
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
   167
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
   168
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
   169
   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
   170
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
   171
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
   172
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
   173
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
   174
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
   175
12392
ab8613334697 [doc] start the server in debug mode, it's easier during learning
Laurent Peuch <cortex@worlddomination.be>
parents: 12391
diff changeset
   176
  cubicweb-ctl start -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
   177
12393
ea198374785b [doc] explicitely give the local server url to make this step more obvious
Laurent Peuch <cortex@worlddomination.be>
parents: 12392
diff changeset
   178
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
   179
http://localhost:8080 (or with another port if you've modified it)