[doc] Update the advanced tutorial
authorOlivier Giorgis <olivier.giorgis@logilab.fr>
Fri, 15 Sep 2017 14:14:46 +0200
changeset 12209 3a3551fff787
parent 12208 159dce89a145
child 12218 d3f3c4a4edd9
[doc] Update the advanced tutorial to follow the new style layout of cubes among others.
doc/tutorials/advanced/part01_create-cube.rst
doc/tutorials/advanced/part02_security.rst
doc/tutorials/advanced/part03_bfss.rst
doc/tutorials/advanced/part04_ui-base.rst
--- a/doc/tutorials/advanced/part01_create-cube.rst	Tue Sep 12 15:05:22 2017 +0200
+++ b/doc/tutorials/advanced/part01_create-cube.rst	Fri Sep 15 14:14:46 2017 +0200
@@ -5,26 +5,35 @@
 
 .. _adv_tuto_create_new_cube:
 
-Step 1: creating a new cube for my web site
+Step 1: creating a virtual environment
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Fisrt I need a python virtual environment with cubicweb::
+
+  virtualenv python-2.7.5_cubicweb
+  . /python-2.7.5_cubicweb/bin/activate
+  pip install cubicweb
+
+
+Step 2: creating a new cube for my web site
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 One note about my development environment: I wanted to use the packaged
-version of CubicWeb and cubes while keeping my cube in my user
-directory, let's say `~src/cubes`.  I achieve this by setting the
-following environment variables::
+version of CubicWeb and cubes while keeping my cube in the current
+directory, let's say `~src/cubes`::
 
-  CW_CUBES_PATH=~/src/cubes
+  cd ~src/cubes
   CW_MODE=user
 
 I can now create the cube which will hold custom code for this web
 site using::
 
-  cubicweb-ctl newcube --directory=~/src/cubes sytweb
+  cubicweb-ctl newcube sytweb
 
 
 .. _adv_tuto_assemble_cubes:
 
-Step 2: pick building blocks into existing cubes
+Step 3: pick building blocks into existing cubes
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Almost everything I want to handle in my web-site is somehow already modelized in
@@ -50,7 +59,7 @@
   entities supporting the `tags` relation by linking the to `Tag` entities. This
   will allows navigation into a large number of picture.
 
-Ok, now I'll tell my cube requires all this by editing :file:`cubes/sytweb/__pkginfo__.py`:
+Ok, now I'll tell my cube requires all this by editing :file:`cubicweb-sytweb/cubicweb_sytweb/__pkginfo__.py`:
 
   .. sourcecode:: python
 
@@ -64,26 +73,20 @@
 
 Notice that you can express minimal version of the cube that should be used,
 `None` meaning whatever version available. All packages starting with 'cubicweb-'
-will be recognized as being cube, not bare python packages. You can still specify
-this explicitly using instead the `__depends_cubes__` dictionary which should
-contains cube's name without the prefix. So the example below would be written
-as:
-
-  .. sourcecode:: python
-
-    __depends__ = {'cubicweb': '>= 3.10.0'}
-    __depends_cubes__ = {'file': '>= 1.9.0',
-		         'folder': '>= 1.1.0',
-		   	 'person': '>= 1.2.0',
-		   	 'comment': '>= 1.2.0',
-		   	 'tag': '>= 1.2.0',
-		   	 'zone': None}
+will be recognized as being cube, not bare python packages.
 
 If your cube is packaged for debian, it's a good idea to update the
 `debian/control` file at the same time, so you won't forget it.
 
+Now, I need to install all the dependencies::
 
-Step 3: glue everything together in my cube's schema
+  cd cubicweb-sytweb
+  pip install -e .
+  pip install cubicweb[etwist]
+  pip install psycopg2 # for postgresql
+
+
+Step 4: glue everything together in my cube's schema
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 .. sourcecode:: python
@@ -131,7 +134,7 @@
 features (and goals), we won't worry about it for now and see that later when needed.
 
 
-Step 4: creating the instance
+Step 5: creating the instance
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Now that I have a schema, I want to create an instance. To
@@ -139,6 +142,8 @@
 
   cubicweb-ctl create sytweb sytweb_instance
 
+Don't forget to say "yes" to the question: `Allow anonymous access ? [y/N]:`
+
 Hint: if you get an error while the database is initialized, you can
 avoid having to answer the questions again by running::
 
--- a/doc/tutorials/advanced/part02_security.rst	Tue Sep 12 15:05:22 2017 +0200
+++ b/doc/tutorials/advanced/part02_security.rst	Fri Sep 15 14:14:46 2017 +0200
@@ -194,7 +194,7 @@
 
 	def precommit_event(self):
 	    for eid in self.get_data():
-		entity = self.session.entity_from_eid(eid)
+		entity = self.cnx.entity_from_eid(eid)
 		if entity.visibility == 'parent':
 		    entity.cw_set(visibility=u'authenticated')
 
@@ -364,7 +364,7 @@
 
 .. sourcecode:: bash
 
-    $ pytest unittest_sytweb.py
+    $ python test/unittest_sytweb.py
     ========================  unittest_sytweb.py  ========================
     -> creating tables [....................]
     -> inserting default user and default groups.
@@ -382,7 +382,7 @@
 
 .. sourcecode:: bash
 
-    $ pytest unittest_sytweb.py
+    $ python test/unittest_sytweb.py
     ========================  unittest_sytweb.py  ========================
     .
     ----------------------------------------------------------------------
@@ -396,11 +396,6 @@
     $ rm data/database/tmpdb*
 
 
-.. Note::
-  pytest is a very convenient utility used to control test execution. It is available from the `logilab-common`_ package.
-
-.. _`logilab-common`: http://www.logilab.org/project/logilab-common
-
 .. _adv_tuto_migration_script:
 
 Step 4: writing the migration script and migrating the instance
--- a/doc/tutorials/advanced/part03_bfss.rst	Tue Sep 12 15:05:22 2017 +0200
+++ b/doc/tutorials/advanced/part03_bfss.rst	Fri Sep 15 14:14:46 2017 +0200
@@ -12,7 +12,7 @@
 
 Since the function to register a custom storage needs to have a repository
 instance as first argument, we've to call it in a server startup hook. So I added
-in `cubes/sytweb/hooks.py` :
+in `cubicweb_sytweb/hooks.py` :
 
 .. sourcecode:: python
 
--- a/doc/tutorials/advanced/part04_ui-base.rst	Tue Sep 12 15:05:22 2017 +0200
+++ b/doc/tutorials/advanced/part04_ui-base.rst	Fri Sep 15 14:14:46 2017 +0200
@@ -87,7 +87,7 @@
     class IndexView(startup.IndexView):
 	def call(self, **kwargs):
 	    self.w(u'<div>\n')
-	    if self._cw.cnx.anonymous_connection:
+	    if self._cw.cnx.session.anonymous_session:
 		self.w(u'<h4>%s</h4>\n' % self._cw._('Public Albums'))
 	    else:
 		self.w(u'<h4>%s</h4>\n' % self._cw._('Albums for %s') % self._cw.user.login)
@@ -317,8 +317,8 @@
 
 To see if everything is ok on my test instance, I do: ::
 
-  $ cubicweb-ctl i18ninstance sytweb
-  $ cubicweb-ctl start -D sytweb
+  $ cubicweb-ctl i18ninstance sytweb_instance
+  $ cubicweb-ctl start -D sytweb_instance
 
 The first command compile i18n catalogs (e.g. generates '.mo' files) for my test
 instance. The second command start it in debug mode, so I can open my browser and