|
1 .. -*- coding: utf-8 -*- |
|
2 |
|
3 ============= |
|
4 LAX Tutorial |
|
5 ============= |
|
6 |
|
7 Introduction |
|
8 ============ |
|
9 |
|
10 LAX stands for Logilab App engine eXtension. It is a web framework |
|
11 running on top of the Google AppEngine datastore. |
|
12 |
|
13 Distinctive features include a data-model driven engine, a query |
|
14 language, a selection/view mechanism for HTML/XML/text generation, |
|
15 reuseable components, etc. It all sums up to very fast and efficient |
|
16 development. |
|
17 |
|
18 This tutorial will guide you to build a blog application step by step |
|
19 to discover the unique features of LAX. It assumes that you followed |
|
20 the installation guidelines and that both the AppEngine SDK and the |
|
21 LAX framework are setup on your computer. |
|
22 |
|
23 Creating a very simple application |
|
24 ================================== |
|
25 |
|
26 Creating a new application |
|
27 -------------------------- |
|
28 |
|
29 When you installed lax, you saw a directory named skel. Make a copy of |
|
30 this directory and call it BlogDemo. |
|
31 |
|
32 Defining a schema |
|
33 ----------------- |
|
34 |
|
35 With LAX, the schema/datamodel is the core of the application. |
|
36 |
|
37 Let us start with something simple and improve on it later. First, we |
|
38 make sure that in appconfig.py we have a line :: |
|
39 |
|
40 schema_type = 'yams' |
|
41 |
|
42 Then, in schema.py, we define two entities : ``Blog`` and ``BlogEntry``. |
|
43 |
|
44 :: |
|
45 |
|
46 class Blog(EntityType): |
|
47 title = String(maxsize=50, required=True) |
|
48 description = String() |
|
49 |
|
50 class BlogEntry(EntityType): |
|
51 title = String(maxsize=100, required=True) |
|
52 publish_date = Date(default='TODAY') |
|
53 text = String(fulltextindexed=True) |
|
54 category = String(vocabulary=('important','business')) |
|
55 entry_of = SubjectRelation('Blog', cardinality='?*') |
|
56 |
|
57 A Blog has a title and a description. The title is a string that is |
|
58 required and must be less than 50 characters. The description is a |
|
59 string that is not constrained. |
|
60 |
|
61 A BlogEntry has a title, a publish_date and a text. The title is a |
|
62 string that is required and must be less than 100 characters. The |
|
63 publish_date is a Date with a default value of TODAY, meaning that |
|
64 when a BlogEntry is created, its publish_date will be the current day |
|
65 unless it is modified. The text is a string that will be indexed in |
|
66 the full-text index and has no constraint. |
|
67 |
|
68 A BlogEntry also has a relationship ``entry_of`` that link it to a |
|
69 Blog. The cardinality ``?*`` means that a BlogEntry can be part of |
|
70 zero or one Blog (``?`` means `zero or one`) and that a Blog can |
|
71 have any number of BlogEntry (``*`` means `any number including |
|
72 zero`). For completeness, remember that ``+`` means `one or more`. |
|
73 |
|
74 :note: in lax-0.3.0, cardinality checking is not fully ported to |
|
75 AppEngine, so cardinality limits are not enforced. This should be |
|
76 fixed in lax-0.4.0 available at the beginning of June. |
|
77 |
|
78 Using the application |
|
79 --------------------- |
|
80 |
|
81 Defining this simple schema is enough to get us started. Launch the |
|
82 application with the command:: |
|
83 |
|
84 python dev_appserver.py BlogDemo |
|
85 |
|
86 and point your browser at localhost:8080 |
|
87 |
|
88 You will see the home page of your application. It lists the entity |
|
89 types: Blog and BlogEntry. |
|
90 |
|
91 Let us create a few of these. Click on the [+] at the right of the |
|
92 link Blog. Call this new Blog ``Tech-blog`` and type in |
|
93 ``everything about technology`` as the description, then validate the |
|
94 form by clicking on ``button_ok``. |
|
95 |
|
96 Click on the logo at top left to get back to the home page, then |
|
97 follow the Blog link. If this link reads ``blog_plural`` it is because |
|
98 i18n is not working for you yet. Let us ignore this for a while. After |
|
99 following the link, you should be seeing a list with a single item |
|
100 ``Tech-blog``. Clicking on this item will get you to its detailed |
|
101 description except that in this case, there is not much to display |
|
102 besides the name and the phrase ``everything about technology``. |
|
103 |
|
104 Now get back to the home page by clicking on the top-left logo, then |
|
105 create a new Blog called ``MyLife`` and get back to the home page |
|
106 again to follow the Blog link for the second time. The list now |
|
107 has two items. |
|
108 |
|
109 Get back to the home page and click on [+] at the right of the link |
|
110 BlogEntry. Call this new entry ``Hello World`` and type in some text |
|
111 before clicking on ``button_ok``. You added a new blog entry without |
|
112 saying to what blog it belongs. There is a box on the left entitled |
|
113 ``actions``, click on the menu item ``modify``. You are back to the form |
|
114 to edit the blog entry you just created, except that the form now has |
|
115 another section with a combobox titled ``add relation``. Chose |
|
116 ``entry_of`` in this menu and a second combobox appears where you pick |
|
117 ``MyLife``. Validate the changes by clicking |
|
118 ``button_ok``. The entity BlogEntry that is displayed now includes a link |
|
119 to the entity Blog named ``MyLife``. |
|
120 |
|
121 Conclusion |
|
122 ---------- |
|
123 |
|
124 Exercise |
|
125 ~~~~~~~~ |
|
126 |
|
127 Create new blog entries in ``Tech-blog``. |
|
128 |
|
129 What we learned |
|
130 ~~~~~~~~~~~~~~~ |
|
131 |
|
132 Creating a simple schema was enough to set up a new application that |
|
133 can store blogs and blog entries. |
|
134 |
|
135 What is next ? |
|
136 -------------- |
|
137 |
|
138 Althought the application is fully functionnal, its look is very |
|
139 basic. We will now improve how information is displayed by writing |
|
140 views. |
|
141 |
|
142 |
|
143 Developing the user interface with Views |
|
144 ======================================== |
|
145 |
|
146 [WRITE ME] |
|
147 |
|
148 * Defining views with selection/views |
|
149 |
|
150 * implementing interfaces, calendar for blog entries. |
|
151 |
|
152 * show that a calendar view can export data to ical. |
|
153 |
|
154 * create view "blogentry table" with title, publish_date, category. |
|
155 |
|
156 * in view blog, select blogentries and apply view "blogentry table" |
|
157 |
|
158 * demo ajax by filtering blogentry table on category |
|
159 |
|
160 Components |
|
161 =========== |
|
162 |
|
163 [WRITE ME] |
|
164 |
|
165 * explain the component architecture |
|
166 |
|
167 * add comments to the blog by importing the comments component |
|
168 |
|
169 Boxes |
|
170 ====== |
|
171 |
|
172 [WRITE ME] |
|
173 |
|
174 * explain how to build a box |
|
175 |
|
176 * add an blogentry archives box |
|
177 |
|
178 Preferences |
|
179 ============ |
|
180 |
|
181 [WRITE ME] |
|
182 |
|
183 * talk about the user preferences |
|
184 |
|
185 * add an example on how to hide / display / move a component or a box |
|
186 |
|
187 MainTemplate |
|
188 ============ |
|
189 |
|
190 [WRITE ME] |
|
191 |
|
192 * customize MainTemplate and show that everything in the user |
|
193 interface can be changed |
|
194 |
|
195 |
|
196 RSS Channel |
|
197 =========== |
|
198 |
|
199 [WRITE ME] |
|
200 |
|
201 * show that the RSS view can be used to display an ordered selection |
|
202 of blog entries, thus providing a RSS channel |
|
203 |
|
204 * show that a different selection (by category) means a different channel |
|
205 |
|
206 RQL |
|
207 ==== |
|
208 |
|
209 [WRITE ME] |
|
210 |
|
211 * talk about the Relation Query Language |
|
212 |
|
213 URL Rewriting |
|
214 ============= |
|
215 |
|
216 [WRITE ME] |
|
217 |
|
218 * show how urls are mapped to selections and views and explain URLRewriting |
|
219 |
|
220 Security |
|
221 ========= |
|
222 |
|
223 [WRITE ME] |
|
224 |
|
225 * talk about security access rights and show that security is defined |
|
226 using RQL |
|
227 |