author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 02 Mar 2010 19:15:26 +0100 | |
branch | stable |
changeset 4751 | 1a9d2c3c7f0c |
parent 4450 | 8000abf9c9d3 |
child 4936 | a4b772a0d801 |
permissions | -rw-r--r-- |
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 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
4 |
.. _Steps: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
5 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
6 |
Steps for creating your cube |
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 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
9 |
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
|
10 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
11 |
1. :ref:`CreateYourCube` |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
12 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
13 |
Create the directory to hold the code of your cube. The most important files that will be useful to customize your newly created cube are: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
14 |
* schema.py: contains the data model |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
15 |
* views.py: contains your custom views |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
16 |
* entities.py: contains XXX |
4450
8000abf9c9d3
fix bad rest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4446
diff
changeset
|
17 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
18 |
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
|
19 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
20 |
2. :ref:`DefineDataModel` |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
21 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
22 |
Define the data model of your application. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
23 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
24 |
3. :ref:`ExploreYourInstance` |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
25 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
26 |
Create, run, and explore an instance of your cube. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
27 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
28 |
4. :ref:`DefineViews` |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
29 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
30 |
Customize the views of your data: how and which part of your data are showed. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
31 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
32 |
Note: views don't concern the look'n'feel or design of the site. For that, you should use CSS instead, and default CSS or your new cube are located in 'blog/data/'. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
33 |
|
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 |
5. :ref:`DefineEntities` |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
36 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
37 |
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
|
38 |
|
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 |
.. _CreateYourCube: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
41 |
|
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
42 |
Create your cube |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
43 |
---------------- |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
44 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
45 |
The packages ``cubicweb`` and ``cubicweb-dev`` install a command line |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
49 |
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
|
50 |
a new cube:: |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
51 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
52 |
cubicweb-ctl newcube blog |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
53 |
|
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
58 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
59 |
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
|
60 |
:: |
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 |
CW_CUBES_PATH=~/src/cubes |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
63 |
CW_MODE=user |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
64 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
65 |
and then create your new cube using: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
66 |
:: |
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 |
cubicweb-ctl newcube --directory=~/src/cubes blog |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
69 |
|
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 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
72 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
73 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
74 |
|
255
5d2804b9a28c
[doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
229
diff
changeset
|
75 |
.. _DefineDataModel: |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
76 |
|
268
0575e7973c5e
[doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
255
diff
changeset
|
77 |
Define your data model |
0575e7973c5e
[doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
255
diff
changeset
|
78 |
---------------------- |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
79 |
|
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
80 |
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
|
81 |
It defines the type of content your application will handle. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
82 |
|
268
0575e7973c5e
[doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
255
diff
changeset
|
83 |
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
|
84 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
85 |
.. sourcecode:: python |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
86 |
|
4143 | 87 |
from yams.buildobjs import EntityType, String, SubjectRelation, Date |
88 |
||
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
89 |
class Blog(EntityType): |
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
90 |
title = String(maxsize=50, required=True) |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
91 |
description = String() |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
92 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
93 |
class BlogEntry(EntityType): |
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
94 |
title = String(required=True, fulltextindexed=True, maxsize=256) |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
95 |
publish_date = Date(default='TODAY') |
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
96 |
content = String(required=True, fulltextindexed=True) |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1808
diff
changeset
|
97 |
entry_of = SubjectRelation('Blog', cardinality='?*') |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
98 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
99 |
The first step is the import of the EntityType (generic class for entity and |
4143 | 100 |
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
|
101 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
102 |
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
|
103 |
required and must be less than 50 characters. The |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
104 |
description is a string that is not constrained. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
105 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
the database full-text index and has no constraint. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
112 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
113 |
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
|
114 |
Blog. The cardinality ``?*`` means that a BlogEntry can be part of |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
115 |
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
|
116 |
have any number of BlogEntry (``*`` means `any number including |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
117 |
zero`). For completeness, remember that ``+`` means `one or more`. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
118 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
119 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
120 |
.. _ExploreYourInstance: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
121 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
122 |
Create and explore your instance |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
123 |
-------------------------------- |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
124 |
.. _CreateYourInstance: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
125 |
|
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
126 |
Create your instance |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
127 |
~~~~~~~~~~~~~~~~~~~~ |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
128 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2175
diff
changeset
|
129 |
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
|
130 |
|
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
131 |
cubicweb-ctl create blog blogdemo |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
132 |
|
4143 | 133 |
This command will create the corresponding database and initialize it. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
134 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
135 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
136 |
.. _WelcomeToYourWebInstance: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
137 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2175
diff
changeset
|
138 |
Welcome to your web instance |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
139 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
140 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2175
diff
changeset
|
141 |
Start your instance in debug mode with the following command: :: |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
142 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
143 |
cubicweb-ctl start -D blogdemo |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
144 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
145 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2175
diff
changeset
|
146 |
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
|
147 |
by visiting the URL http://localhost:8080/. |
0575e7973c5e
[doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
255
diff
changeset
|
148 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2175
diff
changeset
|
149 |
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
|
150 |
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
|
151 |
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
|
152 |
create``. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
153 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
154 |
.. image:: ../../images/login-form.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
155 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
156 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2175
diff
changeset
|
157 |
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
|
158 |
and create entities. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
159 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
160 |
.. image:: ../../images/blog-demo-first-page.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
161 |
|
2535
c7b736929a58
[doc] a bit of rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
162 |
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
|
163 |
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
|
164 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
165 |
.. _AddEntities: |
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 |
Add entities |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
168 |
~~~~~~~~~~~~ |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
169 |
|
268
0575e7973c5e
[doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
255
diff
changeset
|
170 |
We will now add entities in our web application. |
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 |
Add a Blog |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
173 |
********** |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
174 |
|
268
0575e7973c5e
[doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
255
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
``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
|
178 |
clicking on ``Validate``. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
179 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
180 |
.. image:: ../../images/cbw-create-blog.en.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
181 |
:alt: from to create blog |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
182 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
just created. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
187 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
188 |
.. image:: ../../images/cbw-list-one-blog.en.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
189 |
:alt: displaying a list of a single blog |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
190 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
the phrase ``everything about technology``. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
194 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
has two items. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
199 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
200 |
.. image:: ../../images/cbw-list-two-blog.en.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
201 |
:alt: displaying a list of two blogs |
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 |
Add a BlogEntry |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
204 |
*************** |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
205 |
|
268
0575e7973c5e
[doc] trying to improve the tutorial
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
255
diff
changeset
|
206 |
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
|
207 |
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
|
208 |
before clicking on ``Validate``. You added a new blog entry without |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
209 |
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
|
210 |
``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
|
211 |
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
|
212 |
another section with a combobox titled ``add relation``. Chose |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
213 |
``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
|
214 |
``MyLife``. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
215 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
216 |
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
|
217 |
new entity BlogEntry, hit ``Apply`` instead of ``Validate`` and the |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
218 |
combobox titled ``add relation`` would have showed up. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
219 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
220 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
221 |
.. image:: ../../images/cbw-add-relation-entryof.en.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
222 |
: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
|
223 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
224 |
Validate the changes by clicking ``Validate``. The entity BlogEntry |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
225 |
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
|
226 |
``MyLife``. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
227 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
228 |
.. image:: ../../images/cbw-detail-one-blogentry.en.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
229 |
:alt: displaying the detailed view of a blogentry |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
230 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
point your browser to the URL http://localhost:8080/schema |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
234 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
235 |
.. image:: ../../images/cbw-schema.en.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
236 |
:alt: graphical view of the schema (aka data-model) |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
237 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
238 |
|
255
5d2804b9a28c
[doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
229
diff
changeset
|
239 |
.. _DefineViews: |
5d2804b9a28c
[doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
229
diff
changeset
|
240 |
|
1249
905d76e38433
[doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents:
296
diff
changeset
|
241 |
Define your entity views |
905d76e38433
[doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents:
296
diff
changeset
|
242 |
------------------------ |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
243 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
244 |
Each entity defined in a model is associated with default views |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
245 |
allowing different rendering of the data. You can redefine each of |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
246 |
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
|
247 |
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
|
248 |
|
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
|
249 |
|
1249
905d76e38433
[doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents:
296
diff
changeset
|
250 |
The view selection principle |
905d76e38433
[doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents:
296
diff
changeset
|
251 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
252 |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1808
diff
changeset
|
253 |
A view is defined by a Python class which includes: |
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1808
diff
changeset
|
254 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
255 |
- an identifier (all objects in *CubicWeb* are recorded in a |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
256 |
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
|
257 |
|
1249
905d76e38433
[doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents:
296
diff
changeset
|
258 |
- 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
|
259 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
260 |
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
|
261 |
(`cubicweb.common.view`). |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
262 |
|
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
263 |
*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
|
264 |
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
|
265 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
library of selectors is in ``cubicweb.selector``. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
271 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
272 |
It is possible to define multiple views for the same identifier |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
273 |
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
|
274 |
to find the most appropriate way to render the data. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
275 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
BlogEntry. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
279 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
280 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
281 |
Primary view customization |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
282 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
283 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
of the cube ``cubes/blog/views.py``. |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
287 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
288 |
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
|
289 |
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
|
290 |
point calls the following sequence of (redefinable) methods: |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
291 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
292 |
* render_entity_title |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
293 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
294 |
* render_entity_metadata |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
295 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
296 |
* render_entity_attributes |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
297 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
298 |
* render_entity_relations |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
299 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
300 |
* render_side_boxes |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
301 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
302 |
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
|
303 |
blog entry view. This is all described in more details in |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
304 |
:ref:`primary`. |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
305 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
306 |
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
|
307 |
specifying that the date we see is the publication date. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
308 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
309 |
To do so, please apply the following changes: |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
310 |
|
2545
f8246ed962f6
[doc] replace code-block with sourcecode
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2544
diff
changeset
|
311 |
.. sourcecode:: python |
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 |
from cubicweb.selectors import implements |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
314 |
from cubicweb.web.views import primary |
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 |
class BlogEntryPrimaryView(primary.PrimaryView): |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
317 |
__select__ = implements('BlogEntry') |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
318 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
319 |
def render_entity_attributes(self, entity): |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
320 |
self.w(u'<p>published on %s</p>' % |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
321 |
entity.publish_date.strftime('%Y-%m-%d')) |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
322 |
super(BlogEntryPrimaryView, self).render_entity_attributes(entity) |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
323 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
324 |
.. note:: |
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
to view the changes. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
328 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
329 |
You can now see that the publication date has a prefix. |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
330 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
1440
diff
changeset
|
331 |
.. image:: ../../images/cbw-update-primary-view.en.png |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
332 |
:alt: modified primary view |
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
333 |
|
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
334 |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1808
diff
changeset
|
335 |
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
|
336 |
|
1249
905d76e38433
[doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents:
296
diff
changeset
|
337 |
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
|
338 |
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
|
339 |
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
|
340 |
example HTML output. |
117
22c0fad39c13
[doc] missing file
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
341 |
|
2544
282261b26774
[doc] fixed some dangling internal links
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2535
diff
changeset
|
342 |
.. note:: |
282261b26774
[doc] fixed some dangling internal links
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2535
diff
changeset
|
343 |
You can find more details about views and selectors in :ref:`ViewDefinition`. |
1249
905d76e38433
[doc] improve view explanation
Emile Anclin <emile.anclin@logilab.fr>
parents:
296
diff
changeset
|
344 |
|
1253
9716a9f77980
[doc] some improvements on Views
Emile Anclin <emile.anclin@logilab.fr>
parents:
1249
diff
changeset
|
345 |
|
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
346 |
.. _DefineEntities: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
347 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
348 |
Write entities to add logic in your data |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
349 |
---------------------------------------- |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
350 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
351 |
By default, CubicWeb provides a default entity for each data type defined in the schema. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
352 |
A default entity mainly contains the attributes defined in the data model. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
353 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
354 |
You can redefine each entity to provide additional functions to help you write your views. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
355 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
356 |
.. sourcecode:: python |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
357 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
358 |
from cubicweb.entities import AnyEntity |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
359 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
360 |
class BlogEntry(AnyEntity): |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
361 |
"""customized class for BlogEntry entities""" |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
362 |
__regid__ = 'BlogEntry' |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
363 |
__implements__ = AnyEntity.__implements__ |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
364 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
365 |
def display_cw_logo(self): |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
366 |
if 'CW' in self.title: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
367 |
return True |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
368 |
else: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
369 |
return False |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
370 |
|
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
371 |
Customizing an entity requires that your entity: |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
372 |
- inherits from ``cubicweb.entities`` or any subclass |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
373 |
- 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
|
374 |
- implements the base class by explicitly using ``__implements__``. |
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 |
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
|
377 |
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
|
378 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
379 |
.. sourcecode:: python |
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 |
class BlogEntryPrimaryView(primary.PrimaryView): |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
382 |
__select__ = implements('BlogEntry') |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
383 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
384 |
... |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
385 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
386 |
def render_entity_title(self, entity): |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
387 |
if entity.display_cw_logo(): |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
388 |
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
|
389 |
super(BlogEntryPrimaryView, self).render_entity_title(entity) |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
390 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
391 |
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
|
392 |
|
4450
8000abf9c9d3
fix bad rest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4446
diff
changeset
|
393 |
.. _UpdatingSchemaAndSynchronisingInstance: |
4431
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 |
Updating the schema and synchronising the instance |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
396 |
-------------------------------------------------- |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
397 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
398 |
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
|
399 |
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
|
400 |
|
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
401 |
The required steps are: |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
402 |
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
|
403 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
404 |
.. sourcecode:: python |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
405 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
406 |
class Blog(EntityType): |
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
407 |
title = String(maxsize=50, required=True) |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
408 |
description = String() |
4446
a413fac5ff5e
damn me, more stupid sed fix...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4437
diff
changeset
|
409 |
category = String(required=True, vocabulary=(_('Professional'), _('Personal')), default='Personal') |
4431
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
410 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
411 |
2. stop your ``blogdemo`` instance |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
412 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
413 |
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
|
414 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
415 |
.. sourcecode:: bash |
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 |
cubicweb-ctl shell blogdemo |
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 |
4. in the shell, execute: |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
420 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
421 |
.. sourcecode:: python |
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 |
add_attribute('Blog', 'category') |
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 |
5. you can restart your instance, modify a blog entity and check that the new attribute |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
426 |
``category`` has been added. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
427 |
|
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
428 |
Of course, you may also want to add relations, entity types, ... See :ref:`migration` |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
429 |
for a list of all available migration commands. |
e597e0ca67cd
Updated CW tutorial.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4143
diff
changeset
|
430 |