|
1 .. -*- coding: utf-8 -*- |
|
2 |
|
3 Frequently Asked Questions |
|
4 ========================== |
|
5 |
|
6 [XXX 'copy answer from forum' means reusing text from |
|
7 http://groups.google.com/group/google-appengine/browse_frm/thread/c9476925f5f66ec6 |
|
8 and |
|
9 http://groups.google.com/group/google-appengine/browse_frm/thread/d791ce17e2716147/eb078f8cfe8426e0 |
|
10 and |
|
11 http://groups.google.com/group/google-appengine/browse_frm/thread/f48cf6099973aef5/c28cd6934dd72457 |
|
12 ] |
|
13 |
|
14 Why does not CubicWeb have a template language ? |
|
15 ------------------------------------------------ |
|
16 |
|
17 There are enough template languages out there. You can use your |
|
18 preferred template language if you want. [explain how to use a |
|
19 template language] |
|
20 |
|
21 `CubicWeb` does not define its own templating language as this was |
|
22 not our goal. Based on our experience, we realized that |
|
23 we could gain productivity by letting designers use design tools |
|
24 and developpers develop without the use of the templating language |
|
25 as an intermediary that could not be anyway efficient for both parties. |
|
26 Python is the templating language that we use in `CubicWeb`, but again, |
|
27 it does not prevent you from using a templating language. |
|
28 |
|
29 The reason template languages are not used in this book is that |
|
30 experience has proved us that using pure python was less cumbersome. |
|
31 |
|
32 Why do you think using pure python is better than using a template language ? |
|
33 ----------------------------------------------------------------------------- |
|
34 |
|
35 Python is an Object Oriented Programming language and as such it |
|
36 already provides a consistent and strong architecture and syntax |
|
37 a templating language would not reach. |
|
38 |
|
39 When doing development, you need a real language and template |
|
40 languages are not real languages. |
|
41 |
|
42 Using Python enables developing applications for which code is |
|
43 easier to maintain with real functions/classes/contexts |
|
44 without the need of learning a new dialect. By using Python, |
|
45 we use standard OOP techniques and this is a key factor in a |
|
46 robust application. |
|
47 |
|
48 Why do you use the GPL license to prevent me from doing X ? |
|
49 ----------------------------------------------------------- |
|
50 |
|
51 GPL means that *if* you redistribute your application, you need to |
|
52 redistribute it *and* the changes you made *and* the code _linked_ |
|
53 to it under the GPL licence. |
|
54 |
|
55 Publishing a web site has nothing to do with redistributing |
|
56 source code. A fair amount of companies use modified GPL code |
|
57 for internal use. And someone could publish a `CubicWeb` component |
|
58 under a BSD licence for others to plug into a GPL framework without |
|
59 any problem. The only thing we are trying to prevent here is someone |
|
60 taking the framework and packaging it as closed source to his own |
|
61 clients. |
|
62 |
|
63 |
|
64 CubicWeb looks pretty recent. Is it stable ? |
|
65 -------------------------------------------- |
|
66 |
|
67 It is constantly evolving, piece by piece. The framework has |
|
68 evolved over the past seven years and data has been migrated from |
|
69 one schema to the other ever since. There is a well-defined way to |
|
70 handle data and schema migration. |
|
71 |
|
72 <<<<<<< /home/syt/src/fcubicweb/cubicweb_3.2/doc/book/en/annexes/faq.rst |
|
73 Why is the RQL query language looking similar to X ? |
|
74 ---------------------------------------------------- |
|
75 ======= |
|
76 Why is the RQL query language looking similar to X ? |
|
77 ----------------------------------------------------- |
|
78 >>>>>>> /tmp/faq.rst~other.MxOUAP |
|
79 |
|
80 It may remind you of SQL but it is higher level than SQL, more like |
|
81 SPARQL. Except that SPARQL did not exist when we started the project. |
|
82 Having SPARQL has a query language has been in our backlog for years. |
|
83 |
|
84 That RQL language is what is going to make a difference with django- |
|
85 like frameworks for several reasons. |
|
86 |
|
87 1. accessing data is *much* easier with it. One can write complex |
|
88 queries with RQL that would be tedious to define and hard to maintain |
|
89 using an object/filter suite of method calls. |
|
90 |
|
91 2. it offers an abstraction layer allowing your applications to run |
|
92 on multiple back-ends. That means not only various SQL backends |
|
93 (postgresql, sqlite, mysql), but also multiple databases at the |
|
94 same time, and also non-SQL data stores like LDAP directories and |
|
95 subversion/mercurial repositories (see the `vcsfile` |
|
96 component). Google App Engine is yet another supported target for |
|
97 RQL. |
|
98 |
|
99 [copy answer from forum, explain why similar to sparql and why better |
|
100 than django and SQL] |
|
101 |
|
102 which ajax library |
|
103 ------------------ |
|
104 [we use jquery and things on top of that] |
|
105 |
|
106 |
|
107 How to implement security? |
|
108 -------------------------- |
|
109 |
|
110 This is an example of how it works in our framework:: |
|
111 |
|
112 class Version(EntityType): |
|
113 """a version is defining the content of a particular project's |
|
114 release""" |
|
115 # definition of attributes is voluntarily missing |
|
116 permissions = {'read': ('managers', 'users', 'guests',), |
|
117 'update': ('managers', 'logilab', 'owners',), |
|
118 'delete': ('managers', ), |
|
119 'add': ('managers', 'logilab', |
|
120 ERQLExpression('X version_of PROJ, U in_group G, PROJ |
|
121 require_permission P, P name "add_version", P require_group G'),)} |
|
122 |
|
123 The above means that permission to read a Version is granted to any |
|
124 user that is part of one of the groups 'managers', 'users', 'guests'. |
|
125 The 'add' permission is granted to users in group 'managers' or |
|
126 'logilab' and to users in group G, if G is linked by a permission |
|
127 entity named "add_version" to the version's project. |
|
128 :: |
|
129 |
|
130 class version_of(RelationType): |
|
131 """link a version to its project. A version is necessarily linked |
|
132 to one and only one project. """ |
|
133 # some lines voluntarily missing |
|
134 permissions = {'read': ('managers', 'users', 'guests',), |
|
135 'delete': ('managers', ), |
|
136 'add': ('managers', 'logilab', |
|
137 RRQLExpression('O require_permission P, P name "add_version", |
|
138 'U in_group G, P require_group G'),) } |
|
139 |
|
140 You can find additional information in the section :ref:`security`. |
|
141 |
|
142 [XXX what does the second example means in addition to the first one?] |
|
143 |
|
144 |
|
145 `Error while publishing rest text ...` |
|
146 -------------------------------------- |
|
147 While modifying the description of an entity, you get an error message in |
|
148 the application `Error while publishing ...` for Rest text and plain text. |
|
149 The server returns a traceback like as follows :: |
|
150 |
|
151 2008-10-06 15:05:08 - (cubicweb.rest) ERROR: error while publishing ReST text |
|
152 Traceback (most recent call last): |
|
153 File "/home/user/src/blogdemo/cubicweb/common/rest.py", line 217, in rest_publish |
|
154 File "/usr/lib/python2.5/codecs.py", line 817, in open |
|
155 file = __builtin__.open(filename, mode, buffering) |
|
156 TypeError: __init__() takes at most 3 arguments (4 given) |
|
157 |
|
158 |
|
159 This can be fixed by applying the patch described in : |
|
160 http://code.google.com/p/googleappengine/issues/detail?id=48 |
|
161 |
|
162 What are hooks used for? |
|
163 ------------------------ |
|
164 |
|
165 Hooks are executed around (actually before or after) events. The |
|
166 most common events are data creation, update and deletion. They |
|
167 permit additional constraint checking (those not expressible at the |
|
168 schema level), pre and post computations depending on data |
|
169 movements. |
|
170 |
|
171 As such, they are a vital part of the framework. |
|
172 |
|
173 Other kinds of hooks, called Operations, are available |
|
174 for execution just before commit. |
|
175 |
|
176 When should you define an HTML template rather than define a graphical component? |
|
177 --------------------------------------------------------------------------------- |
|
178 |
|
179 An HTML template cannot contain code, hence it is only about static |
|
180 content. A component is made of code and operations that apply on a |
|
181 well defined context (request, result set). It enables much more |
|
182 dynamic views. |
|
183 |
|
184 What is the difference between `AppRsetObject` and `AppObject` ? |
|
185 ---------------------------------------------------------------- |
|
186 |
|
187 `AppRsetObject` instances are selected on a request and a result |
|
188 set. `AppObject` instances are directly selected by id. |
|
189 |
|
190 How to update a database after a schema modification? |
|
191 ----------------------------------------------------- |
|
192 |
|
193 It depends on what has been modified in the schema. |
|
194 |
|
195 * Update of an attribute permissions and properties: |
|
196 ``synchronize_eschema('MyEntity')``. |
|
197 |
|
198 * Update of a relation permissions and properties: |
|
199 ``synchronize_rschema('MyRelation')``. |
|
200 |
|
201 * Add an attribute: ``add_attribute('MyEntityType', 'myattr')``. |
|
202 |
|
203 * Add a relation: ``add_relation_definition('SubjRelation', 'MyRelation', 'ObjRelation')``. |
|
204 |
|
205 |
|
206 How to create an anonymous user? |
|
207 -------------------------------- |
|
208 |
|
209 This allows to bypass authentication for your site. In the |
|
210 ``all-in-one.conf`` file of your instance, define the anonymous user |
|
211 as follows :: |
|
212 |
|
213 # login of the CubicWeb user account to use for anonymous user (if you want to |
|
214 # allow anonymous) |
|
215 anonymous-user=anon |
|
216 |
|
217 # password of the CubicWeb user account matching login |
|
218 anonymous-password=anon |
|
219 |
|
220 You also must ensure that this `anon` user is a registered user of |
|
221 the DB backend. If not, you can create through the administation |
|
222 interface of your instance by adding a user with the role `guests`. |
|
223 This could be the admin account (for development |
|
224 purposes, of course). |
|
225 |
|
226 .. note:: |
|
227 While creating a new instance, you can decide to allow access |
|
228 to anonymous user, which will automatically execute what is |
|
229 decribed above. |
|
230 |
|
231 |
|
232 How to change the application logo? |
|
233 ----------------------------------- |
|
234 |
|
235 There are two ways of changing the logo. |
|
236 |
|
237 1. The easiest way to use a different logo is to replace the existing |
|
238 ``logo.png`` in ``myapp/data`` by your prefered icon and refresh. |
|
239 By default all application will look for a ``logo.png`` to be |
|
240 rendered in the logo section. |
|
241 |
|
242 .. image:: ../images/lax-book.06-main-template-logo.en.png |
|
243 |
|
244 2. In your cube directory, you can specify which file to use for the logo. |
|
245 This is configurable in ``mycube/data/external_resources``: :: |
|
246 |
|
247 LOGO = DATADIR/path/to/mylogo.gif |
|
248 |
|
249 where DATADIR is ``mycubes/data``. |
|
250 |
|
251 |
|
252 How to configure LDAP source? |
|
253 ------------------------------- |
|
254 |
|
255 Your instance's sources are defined in ``/etc/cubicweb.d/myapp/sources``. |
|
256 Configuring an LDAP source is about declaring that source in your |
|
257 instance configuration file such as: :: |
|
258 |
|
259 [ldapuser] |
|
260 adapter=ldapuser |
|
261 # ldap host |
|
262 host=myhost |
|
263 # base DN to lookup for usres |
|
264 user-base-dn=ou=People,dc=mydomain,dc=fr |
|
265 # user search scope |
|
266 user-scope=ONELEVEL |
|
267 # classes of user |
|
268 user-classes=top,posixAccount |
|
269 # attribute used as login on authentication |
|
270 user-login-attr=uid |
|
271 # name of a group in which ldap users will be by default |
|
272 user-default-group=users |
|
273 # map from ldap user attributes to cubicweb attributes |
|
274 user-attrs-map=gecos:email,uid:login |
|
275 |
|
276 Any change applied to configuration file requires to restart your |
|
277 application. |
|
278 |
|
279 I get NoSelectableObject exceptions: how do I debug selectors ? |
|
280 --------------------------------------------------------------- |
|
281 |
|
282 You just need to put the appropriate context manager around view/component |
|
283 selection: :: |
|
284 |
|
285 from cubicweb.common.selectors import traced_selection |
|
286 with traced_selection(): |
|
287 comp = self.vreg.select_object('contentnavigation', 'wfhistory', |
|
288 self.req, rset, context='navcontentbottom') |
|
289 |
|
290 This will yield additional WARNINGs, like this: :: |
|
291 |
|
292 2009-01-09 16:43:52 - (cubicweb.selectors) WARNING: selector one_line_rset returned 0 for <class 'cubicweb.web.views.basecomponents.WFHistoryVComponent'> |
|
293 |
|
294 How to format an entity date attribute? |
|
295 --------------------------------------- |
|
296 |
|
297 If your schema has an attribute of type Date or Datetime, you might |
|
298 want to format it. First, you should define your preferred format using |
|
299 the site configuration panel ``http://appurl/view?vid=systemepropertiesform`` |
|
300 and then set ``ui.date`` and/or ``ui.datetime``. |
|
301 Then in the view code, use:: |
|
302 |
|
303 self.format_date(entity.date_attribute) |
|
304 |
|
305 Can PostgreSQL and CubicWeb authentication work with kerberos ? |
|
306 ---------------------------------------------------------------- |
|
307 |
|
308 If you have postgresql set up to accept kerberos authentication, you can set |
|
309 the db-host, db-name and db-user parameters in the `sources` configuration |
|
310 file while leaving the password blank. It should be enough for your instance |
|
311 to connect to postgresql with a kerberos ticket. |
|
312 |
|
313 |
|
314 How to load data from a script? |
|
315 ------------------------------- |
|
316 |
|
317 The following script aims at loading data within a script assuming pyro-nsd is |
|
318 running and your application is configured with ``pyro-server=yes``, otherwise |
|
319 you would not be able to use dbapi. :: |
|
320 |
|
321 from cubicweb import dbapi |
|
322 |
|
323 cnx = dbapi.connection(database='instance-id', user='admin', password='admin') |
|
324 cur = cnx.cursor() |
|
325 for name in ('Personal', 'Professional', 'Computers'): |
|
326 cur.execute('INSERT Blog B: B name %s', name) |
|
327 cnx.commit() |
|
328 |
|
329 What is the CubicWeb datatype corresponding to GAE datastore's UserProperty? |
|
330 ---------------------------------------------------------------------------- |
|
331 |
|
332 If you take a look at your application schema and |
|
333 click on "display detailed view of metadata" you will see that there |
|
334 is a Euser entity in there. That's the one that is modeling users. The |
|
335 thing that corresponds to a UserProperty is a relationship between |
|
336 your entity and the Euser entity. As in :: |
|
337 |
|
338 class TodoItem(EntityType): |
|
339 text = String() |
|
340 todo_by = SubjectRelation('Euser') |
|
341 |
|
342 [XXX check that cw handle users better by |
|
343 mapping Google Accounts to local Euser entities automatically] |
|
344 |