1 .. -*- coding: utf-8 -*- |
1 .. -*- coding: utf-8 -*- |
2 |
2 |
3 Create your cube |
3 Create your cube |
4 ---------------- |
4 ---------------- |
5 |
5 |
6 After you installed your `CubicWeb` development environment, you can start |
6 Once your `CubicWeb` development environment is set up, you can create a new |
7 to build your first cube: :: |
7 cube:: |
8 |
8 |
9 cubicweb-ctl newcube blog |
9 cubicweb-ctl newcube blog |
10 |
10 |
11 This will create in ``/path/to/forest/cubes`` a directory containing: :: |
11 This will create in ``/path/to/forest/cubes`` a directory named ``blog`` containing:: |
12 |
12 |
13 blog/ |
13 blog/ |
14 | |
14 | |
15 |-- data/ |
15 |-- data/ |
16 | |-- cubes.blog.css |
16 | |-- cubes.blog.css |
17 | |-- cubes.blog.js |
17 | |-- cubes.blog.js |
18 | |-- external_resources |
18 | `-- external_resources |
19 | |
19 | |
20 |-- debian/ |
20 |-- debian/ |
21 | |-- changelog |
21 | |-- changelog |
22 | |-- compat |
22 | |-- compat |
23 | |-- control |
23 | |-- control |
24 | |-- copyright |
24 | |-- copyright |
25 | |-- cubicweb-blog.prerm |
25 | |-- cubicweb-blog.prerm |
26 | |-- rules |
26 | `-- rules |
27 | |
27 | |
28 |-- entities.py |
28 |-- entities.py |
29 | |
29 | |
30 |-- i18n/ |
30 |-- i18n/ |
31 | |-- en.po |
31 | |-- en.po |
32 | |-- fr.po |
32 | `-- fr.po |
33 | |
33 | |
34 |-- __init__.py |
34 |-- __init__.py |
35 | |
35 | |
36 |-- MANIFEST.in |
36 |-- MANIFEST.in |
37 | |
37 | |
38 |-- migration/ |
38 |-- migration/ |
39 | |-- postcreate.py |
39 | |-- postcreate.py |
40 | |-- precreate.py |
40 | `-- precreate.py |
41 | |
41 | |
42 |-- __pkginfo__.py |
42 |-- __pkginfo__.py |
43 | |
43 | |
44 |-- schema.py |
44 |-- schema.py |
45 | |
45 | |
49 | |
49 | |
50 |-- sobjects.py |
50 |-- sobjects.py |
51 | |
51 | |
52 |-- test/ |
52 |-- test/ |
53 | |-- data/ |
53 | |-- data/ |
54 | |-- bootstrap_cubes |
54 | | `-- bootstrap_cubes |
55 | |-- pytestconf.py |
55 | |-- pytestconf.py |
56 | |-- realdb_test_blog.py |
56 | |-- realdb_test_blog.py |
57 | |-- test_blog.py |
57 | `-- test_blog.py |
58 | |
58 | |
59 |-- views.py |
59 `-- views.py |
60 |
|
61 Any changes applied to your data model should be done in this |
|
62 directory. |
|
63 |
60 |
64 .. _DefineDataModel: |
61 .. _DefineDataModel: |
65 |
62 |
66 Define your data schema |
63 Define your data model |
67 ----------------------- |
64 ---------------------- |
68 |
65 |
69 The data model or schema is hte core of your `CubicWeb` application. |
66 The data model or schema is the core of your `CubicWeb` application. |
70 This is where is defined the type of content you application will handle. |
67 It defines the type of content your application will handle. |
71 |
68 |
72 The data model is defined in the file ``schema.py`` of your cube |
69 The data model of your cube ``blog`` is defined in the file ``schema.py``: |
73 ``blog`` such as follows. |
|
74 |
70 |
75 :: |
71 :: |
76 |
72 |
77 from cubicweb.schema import format_constraint |
73 from cubicweb.schema import format_constraint |
|
74 |
78 class Blog(EntityType): |
75 class Blog(EntityType): |
79 title = String(maxsize=50, required=True) |
76 title = String(maxsize=50, required=True) |
80 description = String() |
77 description = String() |
81 |
78 |
82 class BlogEntry(EntityType): |
79 class BlogEntry(EntityType): |
105 |
102 |
106 |
103 |
107 Create your instance |
104 Create your instance |
108 -------------------- |
105 -------------------- |
109 |
106 |
110 :: |
107 To use this cube as an application and create a new instance named ``blogdemo``, do:: |
111 |
108 |
112 cubicweb-ctl create blog blogdemo |
109 cubicweb-ctl create blog blogdemo |
113 |
110 |
114 |
111 |
115 This command will create a directory ``~/etc/cubicweb.d/blogdemo`` |
112 This command will create a directory ``~/etc/cubicweb.d/blogdemo`` |
116 which will contain all the configuration files required to start |
113 which will contain all the configuration files required to start |
117 you web application. |
114 you web application. |
118 |
115 |
119 The instance ``blogdemo`` is based on the cube ``blog``. |
116 Welcome to your web application |
120 |
|
121 |
|
122 Welcome in your web application |
|
123 ------------------------------- |
117 ------------------------------- |
124 |
118 |
125 Run your application with the following command: :: |
119 Start your application in debug mode with the following command: :: |
126 |
120 |
127 cubicweb-ctl start -D blogdemo |
121 cubicweb-ctl start -D blogdemo |
128 |
122 |
129 |
123 |
130 You can now access to your web application to create blogs and post messages |
124 You can now access your web application to create blogs and post messages |
131 by visitin the URL http://localhost:8080/. |
125 by visiting the URL http://localhost:8080/. |
132 A login form will first be prompted. By default, the application will not allow |
126 |
133 anonymous user to get in the application. You should then use the admin |
127 A login form will appear. By default, the application will not allow anonymous |
134 account you created at the time you initialized the database with |
128 users to enter the application. To login, you need then use the admin account |
135 ``cubicweb-ctl create``. |
129 you created at the time you initialized the database with ``cubicweb-ctl |
|
130 create``. |
136 |
131 |
137 .. image:: images/login-form.png |
132 .. image:: images/login-form.png |
138 |
133 |
139 |
134 |
140 Once authenticated, you can start playing with your application |
135 Once authenticated, you can start playing with your application |
141 and create entities. Bravo! |
136 and create entities. |
142 |
137 |
143 .. image:: images/blog-demo-first-page.png |
138 .. image:: images/blog-demo-first-page.png |
144 |
139 |
145 Please notice that so far, `CubicWeb` franework managed all aspects of |
140 Please notice that so far, the `CubicWeb` franework managed all aspects of |
146 the web application based in the schema provided at first. |
141 the web application based on the schema provided at first. |
147 |
142 |
148 |
143 |
149 Create entities |
144 Add entities |
150 --------------- |
145 ------------ |
151 |
146 |
152 We will now create a couple of entities in our web application. |
147 We will now add entities in our web application. |
153 |
148 |
154 Create a Blog |
149 Add a Blog |
155 ~~~~~~~~~~~~~ |
150 ~~~~~~~~~~ |
156 |
151 |
157 Let us create a few of these entities. Click on the `[+]` at the right |
152 Let us create a few of these entities. Click on the `[+]` at the left of the |
158 of the link Blog. Call this new Blog ``Tech-blog`` and type in |
153 link Blog on the home page. Call this new Blog ``Tech-blog`` and type in |
159 ``everything about technology`` as the description, then validate the |
154 ``everything about technology`` as the description, then validate the form by |
160 form by clicking on ``Validate``. |
155 clicking on ``Validate``. |
161 |
156 |
162 .. image:: images/cbw-create-blog.en.png |
157 .. image:: images/cbw-create-blog.en.png |
163 :alt: from to create blog |
158 :alt: from to create blog |
164 |
159 |
165 Click on the logo at top left to get back to the home page, then |
160 Click on the logo at top left to get back to the home page, then |
180 has two items. |
175 has two items. |
181 |
176 |
182 .. image:: images/cbw-list-two-blog.en.png |
177 .. image:: images/cbw-list-two-blog.en.png |
183 :alt: displaying a list of two blogs |
178 :alt: displaying a list of two blogs |
184 |
179 |
185 Create a BlogEntry |
180 Add a BlogEntry |
186 ~~~~~~~~~~~~~~~~~~ |
181 ~~~~~~~~~~~~~~~ |
187 |
182 |
188 Get back to the home page and click on [+] at the right of the link |
183 Get back to the home page and click on [+] at the left of the link |
189 BlogEntry. Call this new entry ``Hello World`` and type in some text |
184 BlogEntry. Call this new entry ``Hello World`` and type in some text |
190 before clicking on ``Validate``. You added a new blog entry without |
185 before clicking on ``Validate``. You added a new blog entry without |
191 saying to what blog it belongs. There is a box on the left entitled |
186 saying to what blog it belongs. There is a box on the left entitled |
192 ``actions``, click on the menu item ``modify``. You are back to the form |
187 ``actions``, click on the menu item ``modify``. You are back to the form |
193 to edit the blog entry you just created, except that the form now has |
188 to edit the blog entry you just created, except that the form now has |
238 `EntityView`, for a complete list, you |
233 `EntityView`, for a complete list, you |
239 will have to read the code in directory ``cubicweb/web/views/`` |
234 will have to read the code in directory ``cubicweb/web/views/`` |
240 |
235 |
241 A view is applied on a `result set` which contains a set of |
236 A view is applied on a `result set` which contains a set of |
242 entities we are trying to display. `CubicWeb` uses a selector |
237 entities we are trying to display. `CubicWeb` uses a selector |
243 mecanism which computes a score used to identify which view |
238 mechanism which computes a score used to identify which view |
244 is the best to apply for the `result set` we are trying to |
239 is the best to apply for the `result set` we are trying to |
245 display. The standard library of selectors is in |
240 display. The standard library of selectors is in |
246 ``cubicweb.common.selector`` and a library of methods used to |
241 ``cubicweb.common.selector`` and a library of methods used to |
247 compute scores is available in ``cubicweb.vregistry.vreq``. |
242 compute scores is available in ``cubicweb.vregistry.vreq``. |
248 |
243 |