95 RQL. |
95 RQL. |
96 |
96 |
97 Which ajax library is CubicWeb using ? |
97 Which ajax library is CubicWeb using ? |
98 -------------------------------------- |
98 -------------------------------------- |
99 |
99 |
100 CubicWeb uses jQuery and provides a few helpers on top of |
100 CubicWeb uses jQuery_ and provides a few helpers on top of that. Additionally, |
101 that. Additionally, some jQuery plugins are provided (some are |
101 some jQuery plugins are provided (some are provided in specific cubes). |
102 provided in specific cubes). |
102 |
|
103 .. _jQuery: http://jquery.com |
|
104 |
103 |
105 |
104 Development |
106 Development |
105 ``````````` |
107 ``````````` |
106 |
108 |
107 How to load data from a script ? |
109 How to change the instance logo ? |
108 -------------------------------- |
110 --------------------------------- |
109 |
111 |
110 The following script aims at loading data within a script assuming pyro-nsd is |
112 There are two ways of changing the logo. |
111 running and your instance is configured with ``pyro-server=yes``, otherwise |
113 |
112 you would not be able to use dbapi. |
114 1. The easiest way to use a different logo is to replace the existing |
113 |
115 ``logo.png`` in ``myapp/data`` by your prefered icon and refresh. |
114 .. sourcecode:: python |
116 By default all instance will look for a ``logo.png`` to be |
115 |
117 rendered in the logo section. |
116 from cubicweb import dbapi |
118 |
117 |
119 .. image:: ../images/lax-book_06-main-template-logo_en.png |
118 cnx = dbapi.connect(database='instance-id', user='admin', password='admin') |
120 |
119 cur = cnx.cursor() |
121 2. In your cube directory, you can specify which file to use for the logo. |
120 for name in ('Personal', 'Professional', 'Computers'): |
122 This is configurable in ``mycube/uiprops.py``: :: |
121 cur.execute('INSERT Blog B: B name %s', name) |
123 |
122 cnx.commit() |
124 LOGO = data('mylogo.gif') |
123 |
125 |
124 |
126 ``mylogo.gif`` is in ``mycube/data`` directory. |
125 How to format an entity date attribute ? |
|
126 ---------------------------------------- |
|
127 |
|
128 If your schema has an attribute of type Date or Datetime, you might |
|
129 want to format it. First, you should define your preferred format using |
|
130 the site configuration panel ``http://appurl/view?vid=systempropertiesform`` |
|
131 and then set ``ui.date`` and/or ``ui.datetime``. |
|
132 Then in the view code, use: |
|
133 |
|
134 .. sourcecode:: python |
|
135 |
|
136 self.format_date(entity.date_attribute) |
|
137 |
|
138 What is the CubicWeb datatype corresponding to GAE datastore's UserProperty ? |
|
139 ----------------------------------------------------------------------------- |
|
140 |
|
141 If you take a look at your instance schema and |
|
142 click on "display detailed view of metadata" you will see that there |
|
143 is a Euser entity in there. That's the one that is modeling users. The |
|
144 thing that corresponds to a UserProperty is a relationship between |
|
145 your entity and the Euser entity. As in: |
|
146 |
|
147 .. sourcecode:: python |
|
148 |
|
149 class TodoItem(EntityType): |
|
150 text = String() |
|
151 todo_by = SubjectRelation('Euser') |
|
152 |
|
153 [XXX check that cw handle users better by mapping Google Accounts to local Euser |
|
154 entities automatically] |
|
155 |
|
156 |
|
157 How do I translate an msg id defined (and translated) in another cube ? |
|
158 ----------------------------------------------------------------------- |
|
159 |
|
160 You should put these translations in the `i18n/static-messages.pot` |
|
161 file of your own cube. |
|
162 |
|
163 |
|
164 What is `Error while publishing rest text ...` ? |
|
165 ------------------------------------------------ |
|
166 |
|
167 While modifying the description of an entity, you get an error message in |
|
168 the instance `Error while publishing ...` for Rest text and plain text. |
|
169 The server returns a traceback like as follows :: |
|
170 |
|
171 2008-10-06 15:05:08 - (cubicweb.rest) ERROR: error while publishing ReST text |
|
172 Traceback (most recent call last): |
|
173 File "/home/user/src/blogdemo/cubicweb/common/rest.py", line 217, in rest_publish |
|
174 File "/usr/lib/python2.5/codecs.py", line 817, in open |
|
175 file = __builtin__.open(filename, mode, buffering) |
|
176 TypeError: __init__() takes at most 3 arguments (4 given) |
|
177 |
|
178 This can be fixed by applying the patch described in : |
|
179 http://code.google.com/p/googleappengine/issues/detail?id=48 |
|
180 |
|
181 What are hooks used for ? |
|
182 ------------------------- |
|
183 |
|
184 Hooks are executed around (actually before or after) events. The |
|
185 most common events are data creation, update and deletion. They |
|
186 permit additional constraint checking (those not expressible at the |
|
187 schema level), pre and post computations depending on data |
|
188 movements. |
|
189 |
|
190 As such, they are a vital part of the framework. |
|
191 |
|
192 Other kinds of hooks, called Operations, are available |
|
193 for execution just before commit. |
|
194 |
|
195 When should you define an HTML template rather than define a graphical component ? |
|
196 ---------------------------------------------------------------------------------- |
|
197 |
|
198 An HTML template cannot contain code, hence it is only about static |
|
199 content. A component is made of code and operations that apply on a |
|
200 well defined context (request, result set). It enables much more |
|
201 dynamic views. |
|
202 |
|
203 How to update a database after a schema modification ? |
|
204 ------------------------------------------------------ |
|
205 |
|
206 It depends on what has been modified in the schema. |
|
207 |
|
208 * update the permissions and properties of an entity or a relation: |
|
209 ``sync_schema_props_perms('MyEntityOrRelation')``. |
|
210 |
|
211 * add an attribute: ``add_attribute('MyEntityType', 'myattr')``. |
|
212 |
|
213 * add a relation: ``add_relation_definition('SubjRelation', 'MyRelation', 'ObjRelation')``. |
|
214 |
|
215 |
127 |
216 How to create an anonymous user ? |
128 How to create an anonymous user ? |
217 --------------------------------- |
129 --------------------------------- |
218 |
130 |
219 This allows to bypass authentication for your site. In the |
131 This allows to browse the site without being authenticated. In the |
220 ``all-in-one.conf`` file of your instance, define the anonymous user |
132 ``all-in-one.conf`` file of your instance, define the anonymous user |
221 as follows :: |
133 as follows :: |
222 |
134 |
223 # login of the CubicWeb user account to use for anonymous user (if you want to |
135 # login of the CubicWeb user account to use for anonymous user (if you want to |
224 # allow anonymous) |
136 # allow anonymous) |
227 # password of the CubicWeb user account matching login |
139 # password of the CubicWeb user account matching login |
228 anonymous-password=anon |
140 anonymous-password=anon |
229 |
141 |
230 You also must ensure that this `anon` user is a registered user of |
142 You also must ensure that this `anon` user is a registered user of |
231 the DB backend. If not, you can create through the administation |
143 the DB backend. If not, you can create through the administation |
232 interface of your instance by adding a user with the role `guests`. |
144 interface of your instance by adding a user with in the group `guests`. |
233 This could be the admin account (for development |
|
234 purposes, of course). |
|
235 |
145 |
236 .. note:: |
146 .. note:: |
237 While creating a new instance, you can decide to allow access |
147 While creating a new instance, you can decide to allow access |
238 to anonymous user, which will automatically execute what is |
148 to anonymous user, which will automatically execute what is |
239 decribed above. |
149 decribed above. |
240 |
150 |
241 |
151 How to load data from a script ? |
242 How to change the instance logo ? |
152 -------------------------------- |
243 ------------------------------------ |
153 |
244 |
154 The following script aims at loading data within a script assuming pyro-nsd is |
245 There are two ways of changing the logo. |
155 running and your instance is configured with ``pyro-server=yes``, otherwise |
246 |
156 you would not be able to use dbapi. |
247 1. The easiest way to use a different logo is to replace the existing |
157 |
248 ``logo.png`` in ``myapp/data`` by your prefered icon and refresh. |
158 .. sourcecode:: python |
249 By default all instance will look for a ``logo.png`` to be |
159 |
250 rendered in the logo section. |
160 from cubicweb import dbapi |
251 |
161 |
252 .. image:: ../images/lax-book_06-main-template-logo_en.png |
162 cnx = dbapi.connect(database='instance-id', user='admin', password='admin') |
253 |
163 cur = cnx.cursor() |
254 2. In your cube directory, you can specify which file to use for the logo. |
164 for name in (u'Personal', u'Professional', u'Computers'): |
255 This is configurable in ``mycube/data/external_resources``: :: |
165 cur.execute('INSERT Tag T: T name %(n)s', {'n': name}) |
256 |
166 cnx.commit() |
257 LOGO = DATADIR/path/to/mylogo.gif |
167 |
258 |
168 Wether your instance as pyro activated or not, you can still acheive this by |
259 where DATADIR is ``mycube/data``. |
169 using cubicweb-ctl shell scripts. |
|
170 |
|
171 How to format an entity date attribute ? |
|
172 ---------------------------------------- |
|
173 |
|
174 If your schema has an attribute of type `Date` or `Datetime`, you usually want to |
|
175 format it when displaying it. First, you should define your preferred format |
|
176 using the site configuration panel |
|
177 ``http://appurl/view?vid=systempropertiesform`` and then set ``ui.date`` and/or |
|
178 ``ui.datetime``. Then in the view code, use: |
|
179 |
|
180 .. sourcecode:: python |
|
181 |
|
182 entity.printable_value(date_attribute) |
|
183 |
|
184 which will always return a string whatever the attribute's type (so it's |
|
185 recommended also for other attribute types). By default it expects to generate |
|
186 HTML, so it deals with rich text formating, xml escaping... |
|
187 |
|
188 How do I translate an msg id defined (and translated) in another cube ? |
|
189 ----------------------------------------------------------------------- |
|
190 |
|
191 You should put these translations in the `i18n/static-messages.pot` |
|
192 file of your own cube. |
|
193 |
|
194 How to update a database after a schema modification ? |
|
195 ------------------------------------------------------ |
|
196 |
|
197 It depends on what has been modified in the schema. |
|
198 |
|
199 * update the permissions and properties of an entity or a relation: |
|
200 ``sync_schema_props_perms('MyEntityOrRelation')``. |
|
201 |
|
202 * add an attribute: ``add_attribute('MyEntityType', 'myattr')``. |
|
203 |
|
204 * add a relation: ``add_relation_definition('SubjRelation', 'MyRelation', 'ObjRelation')``. |
|
205 |
|
206 I get `NoSelectableObject` exceptions, how do I debug selectors ? |
|
207 ----------------------------------------------------------------- |
|
208 |
|
209 You just need to put the appropriate context manager around view/component |
|
210 selection. One standard place for components is in cubicweb/vregistry.py: |
|
211 |
|
212 .. sourcecode:: python |
|
213 |
|
214 def possible_objects(self, *args, **kwargs): |
|
215 """return an iterator on possible objects in this registry for the given |
|
216 context |
|
217 """ |
|
218 from cubicweb.selectors import traced_selection |
|
219 with traced_selection(): |
|
220 for appobjects in self.itervalues(): |
|
221 try: |
|
222 yield self._select_best(appobjects, *args, **kwargs) |
|
223 except NoSelectableObject: |
|
224 continue |
|
225 |
|
226 Don't forget the 'from __future__ import with_statement' at the module |
|
227 top-level if you're using python 2.5. |
|
228 |
|
229 This will yield additional WARNINGs, like this:: |
|
230 |
|
231 2009-01-09 16:43:52 - (cubicweb.selectors) WARNING: selector one_line_rset returned 0 for <class 'cubicweb.web.views.basecomponents.WFHistoryVComponent'> |
|
232 |
|
233 For views, you can put this context in `cubicweb/web/views/basecontrollers.py` in |
|
234 the `ViewController`: |
|
235 |
|
236 .. sourcecode:: python |
|
237 |
|
238 def _select_view_and_rset(self, rset): |
|
239 ... |
|
240 try: |
|
241 from cubicweb.selectors import traced_selection |
|
242 with traced_selection(): |
|
243 view = self._cw.vreg['views'].select(vid, req, rset=rset) |
|
244 except ObjectNotFound: |
|
245 self.warning("the view %s could not be found", vid) |
|
246 req.set_message(req._("The view %s could not be found") % vid) |
|
247 vid = vid_from_rset(req, rset, self._cw.vreg.schema) |
|
248 view = self._cw.vreg['views'].select(vid, req, rset=rset) |
|
249 ... |
|
250 |
|
251 I get "database is locked" when executing tests |
|
252 ----------------------------------------------- |
|
253 |
|
254 If you have "database is locked" as error when you are executing security tests, |
|
255 it is usually because commit or rollback are missing before login() calls. |
|
256 |
|
257 You can also use a context manager, to avoid such errors, as described |
|
258 here: :ref:`securitytest`. |
|
259 |
|
260 |
|
261 What are hooks used for ? |
|
262 ------------------------- |
|
263 |
|
264 Hooks are executed around (actually before or after) events. The most common |
|
265 events are data creation, update and deletion. They permit additional constraint |
|
266 checking (those not expressible at the schema level), pre and post computations |
|
267 depending on data movements. |
|
268 |
|
269 As such, they are a vital part of the framework. |
|
270 |
|
271 Other kinds of hooks, called Operations, are available |
|
272 for execution just before commit. |
|
273 |
|
274 For more information, read :ref:`hooks` section. |
|
275 |
260 |
276 |
261 Configuration |
277 Configuration |
262 ````````````` |
278 ````````````` |
263 |
279 |
264 How to configure a LDAP source ? |
280 How to configure a LDAP source ? |
265 -------------------------------- |
281 -------------------------------- |
266 |
282 |
267 Your instance's sources are defined in ``/etc/cubicweb.d/myapp/sources``. |
283 See :ref:`LDAP`. |
268 Configuring an LDAP source is about declaring that source in your |
|
269 instance configuration file such as: :: |
|
270 |
|
271 [ldapuser] |
|
272 adapter=ldapuser |
|
273 # ldap host |
|
274 host=myhost |
|
275 # base DN to lookup for usres |
|
276 user-base-dn=ou=People,dc=mydomain,dc=fr |
|
277 # user search scope |
|
278 user-scope=ONELEVEL |
|
279 # classes of user |
|
280 user-classes=top,posixAccount |
|
281 # attribute used as login on authentication |
|
282 user-login-attr=uid |
|
283 # name of a group in which ldap users will be by default |
|
284 user-default-group=users |
|
285 # map from ldap user attributes to cubicweb attributes |
|
286 user-attrs-map=gecos:email,uid:login |
|
287 |
|
288 Any change applied to configuration file requires to restart your |
|
289 instance. |
|
290 |
|
291 You can find additional information in the section :ref:`LDAP`. |
|
292 |
284 |
293 How to import LDAP users in |cubicweb| ? |
285 How to import LDAP users in |cubicweb| ? |
294 ---------------------------------------- |
286 ---------------------------------------- |
295 |
287 |
296 Here is a useful script which enables you to import LDAP users |
288 Here is a useful script which enables you to import LDAP users |