3 Cube creation and schema definition |
3 Cube creation and schema definition |
4 ----------------------------------- |
4 ----------------------------------- |
5 |
5 |
6 .. _adv_tuto_create_new_cube: |
6 .. _adv_tuto_create_new_cube: |
7 |
7 |
8 Step 1: creating a new cube for my web site |
8 Step 1: creating a virtual environment |
|
9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
10 |
|
11 Fisrt I need a python virtual environment with cubicweb:: |
|
12 |
|
13 virtualenv python-2.7.5_cubicweb |
|
14 . /python-2.7.5_cubicweb/bin/activate |
|
15 pip install cubicweb |
|
16 |
|
17 |
|
18 Step 2: creating a new cube for my web site |
9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
19 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
10 |
20 |
11 One note about my development environment: I wanted to use the packaged |
21 One note about my development environment: I wanted to use the packaged |
12 version of CubicWeb and cubes while keeping my cube in my user |
22 version of CubicWeb and cubes while keeping my cube in the current |
13 directory, let's say `~src/cubes`. I achieve this by setting the |
23 directory, let's say `~src/cubes`:: |
14 following environment variables:: |
|
15 |
24 |
16 CW_CUBES_PATH=~/src/cubes |
25 cd ~src/cubes |
17 CW_MODE=user |
26 CW_MODE=user |
18 |
27 |
19 I can now create the cube which will hold custom code for this web |
28 I can now create the cube which will hold custom code for this web |
20 site using:: |
29 site using:: |
21 |
30 |
22 cubicweb-ctl newcube --directory=~/src/cubes sytweb |
31 cubicweb-ctl newcube sytweb |
23 |
32 |
24 |
33 |
25 .. _adv_tuto_assemble_cubes: |
34 .. _adv_tuto_assemble_cubes: |
26 |
35 |
27 Step 2: pick building blocks into existing cubes |
36 Step 3: pick building blocks into existing cubes |
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
37 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
29 |
38 |
30 Almost everything I want to handle in my web-site is somehow already modelized in |
39 Almost everything I want to handle in my web-site is somehow already modelized in |
31 existing cubes that I'll extend for my need. So I'll pick the following cubes: |
40 existing cubes that I'll extend for my need. So I'll pick the following cubes: |
32 |
41 |
48 |
57 |
49 * `tag`, providing a full tagging system as an easy and powerful way to classify |
58 * `tag`, providing a full tagging system as an easy and powerful way to classify |
50 entities supporting the `tags` relation by linking the to `Tag` entities. This |
59 entities supporting the `tags` relation by linking the to `Tag` entities. This |
51 will allows navigation into a large number of picture. |
60 will allows navigation into a large number of picture. |
52 |
61 |
53 Ok, now I'll tell my cube requires all this by editing :file:`cubes/sytweb/__pkginfo__.py`: |
62 Ok, now I'll tell my cube requires all this by editing :file:`cubicweb-sytweb/cubicweb_sytweb/__pkginfo__.py`: |
54 |
63 |
55 .. sourcecode:: python |
64 .. sourcecode:: python |
56 |
65 |
57 __depends__ = {'cubicweb': '>= 3.10.0', |
66 __depends__ = {'cubicweb': '>= 3.10.0', |
58 'cubicweb-file': '>= 1.9.0', |
67 'cubicweb-file': '>= 1.9.0', |
62 'cubicweb-tag': '>= 1.2.0', |
71 'cubicweb-tag': '>= 1.2.0', |
63 'cubicweb-zone': None} |
72 'cubicweb-zone': None} |
64 |
73 |
65 Notice that you can express minimal version of the cube that should be used, |
74 Notice that you can express minimal version of the cube that should be used, |
66 `None` meaning whatever version available. All packages starting with 'cubicweb-' |
75 `None` meaning whatever version available. All packages starting with 'cubicweb-' |
67 will be recognized as being cube, not bare python packages. You can still specify |
76 will be recognized as being cube, not bare python packages. |
68 this explicitly using instead the `__depends_cubes__` dictionary which should |
|
69 contains cube's name without the prefix. So the example below would be written |
|
70 as: |
|
71 |
|
72 .. sourcecode:: python |
|
73 |
|
74 __depends__ = {'cubicweb': '>= 3.10.0'} |
|
75 __depends_cubes__ = {'file': '>= 1.9.0', |
|
76 'folder': '>= 1.1.0', |
|
77 'person': '>= 1.2.0', |
|
78 'comment': '>= 1.2.0', |
|
79 'tag': '>= 1.2.0', |
|
80 'zone': None} |
|
81 |
77 |
82 If your cube is packaged for debian, it's a good idea to update the |
78 If your cube is packaged for debian, it's a good idea to update the |
83 `debian/control` file at the same time, so you won't forget it. |
79 `debian/control` file at the same time, so you won't forget it. |
84 |
80 |
|
81 Now, I need to install all the dependencies:: |
85 |
82 |
86 Step 3: glue everything together in my cube's schema |
83 cd cubicweb-sytweb |
|
84 pip install -e . |
|
85 pip install cubicweb[etwist] |
|
86 pip install psycopg2 # for postgresql |
|
87 |
|
88 |
|
89 Step 4: glue everything together in my cube's schema |
87 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
88 |
91 |
89 .. sourcecode:: python |
92 .. sourcecode:: python |
90 |
93 |
91 from yams.buildobjs import RelationDefinition |
94 from yams.buildobjs import RelationDefinition |
129 This schema will probably have to evolve as time goes (for security handling at |
132 This schema will probably have to evolve as time goes (for security handling at |
130 least), but since the possibility to let a schema evolve is one of CubicWeb's |
133 least), but since the possibility to let a schema evolve is one of CubicWeb's |
131 features (and goals), we won't worry about it for now and see that later when needed. |
134 features (and goals), we won't worry about it for now and see that later when needed. |
132 |
135 |
133 |
136 |
134 Step 4: creating the instance |
137 Step 5: creating the instance |
135 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
138 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
136 |
139 |
137 Now that I have a schema, I want to create an instance. To |
140 Now that I have a schema, I want to create an instance. To |
138 do so using this new 'sytweb' cube, I run:: |
141 do so using this new 'sytweb' cube, I run:: |
139 |
142 |
140 cubicweb-ctl create sytweb sytweb_instance |
143 cubicweb-ctl create sytweb sytweb_instance |
|
144 |
|
145 Don't forget to say "yes" to the question: `Allow anonymous access ? [y/N]:` |
141 |
146 |
142 Hint: if you get an error while the database is initialized, you can |
147 Hint: if you get an error while the database is initialized, you can |
143 avoid having to answer the questions again by running:: |
148 avoid having to answer the questions again by running:: |
144 |
149 |
145 cubicweb-ctl db-create sytweb_instance |
150 cubicweb-ctl db-create sytweb_instance |