Author: tziade
Date: Thu Mar 30 18:28:32 2006
New Revision: 2745

Added:
   cookbook/trunk/recipe60.en.tex
   cookbook/trunk/recipe60.fr.tex
Modified:
   cookbook/trunk/cookbook.en.kilepr
   cookbook/trunk/cookbook.fr.kilepr
   cookbook/trunk/recipe_list.txt
Log:
added recipe 60 (tgv commit)

Modified: cookbook/trunk/cookbook.en.kilepr
==============================================================================
--- cookbook/trunk/cookbook.en.kilepr   (original)
+++ cookbook/trunk/cookbook.en.kilepr   Thu Mar 30 18:28:32 2006
@@ -1,7 +1,7 @@
 [General]
 img_extIsRegExp=false
 img_extensions=.eps .pdf .dvi .ps .fig .gif .jpg .jpeg .png
-lastDocument=file:///home/svn.z3lab.org/cookbook/recipe50.en.tex
+lastDocument=file:///home/svn.z3lab.org/cookbook/recipe60.en.tex
 masterDocument=
 name=Zope 3 Cookbook, English
 pkg_extIsRegExp=false
@@ -31,10 +31,10 @@
 
 [item:recipe07.en.tex]
 archive=true
-column=0
+column=4
 encoding=ISO 8859-15
 highlight=LaTeX
-line=6
+line=127
 open=true
 
 [item:recipe48.en.tex]
@@ -82,5 +82,21 @@
 column=0
 encoding=ISO 8859-15
 highlight=LaTeX
-line=6
+line=28
+open=true
+
+[item:recipe60.en.tex]
+archive=true
+column=33
+encoding=ISO 8859-15
+highlight=LaTeX
+line=54
+open=true
+
+[item:recipe60.en.txt]
+archive=true
+column=0
+encoding=ISO 8859-15
+highlight=LaTeX
+line=0
 open=true

Modified: cookbook/trunk/cookbook.fr.kilepr
==============================================================================
--- cookbook/trunk/cookbook.fr.kilepr   (original)
+++ cookbook/trunk/cookbook.fr.kilepr   Thu Mar 30 18:28:32 2006
@@ -84,3 +84,11 @@
 highlight=LaTeX
 line=0
 open=true
+
+[item:recipe60.fr.tex]
+archive=true
+column=145167160
+encoding=
+highlight=
+line=0
+open=false

Added: cookbook/trunk/recipe60.en.tex
==============================================================================
--- (empty file)
+++ cookbook/trunk/recipe60.en.tex      Thu Mar 30 18:28:32 2006
@@ -0,0 +1,66 @@
+\documentclass{book}
+\pagestyle{headings}
+\include{macros}
+\status{draft}
+\author{Tarek Ziad�}
+
+\begin{document}
+
+\chapter*{Retrieving an object URL}
+
+\begin{problem}
+Zope 3 has a different, cleaner approach on how to handle URLs of objects.
+A given object doesn't have its proper URL like it use to have in Zope 2.
+This recipe presents how to retrieve an URL for a given object, and the logic
+behind.
+\end{problem}
+
+\begin{solution}
+\section*{Understanding URLs}
+Each persistent object stored in the ZODB is reached through views, that
+handles its display. The URL is the location from wich the object is reached
+through the browser. For example, is the user tries to display \code{foo}, 
which
+is in \code{bar}, she will type: \code{http://server/foo/bar}. The object is
+pulled by the publisher which traverses the tree of objects from the root.
+In our case, it traverses \code{foo}, ask it for \code{bar}, and so on.
+\code{foo} will point \code{bar} to the publisher, because its
+\code{\_\_name\_\_} property is \code{bar}.
+
+Getting an object URL is done by doing the back trip from the object to
+the root, building the string with the names of all traversed objects.
+
+The main difference with older behaviors is that \code{bar} doesn't hold its
+URL.
+
+\section*{Getting an object URL}
+
+The URL of all publishable objects can be retrieved this way, and a generic
+view class, called \code{AbsoluteURL} provide this feature under the
+\code{absolute\_url} name.
+
+In a ZPT for instance, a given object URL can be retrieved with:
+\code{my\_object/@@absolute\_url}. In Python code, a call to
+\code{zapi.getMultiAdapter()} that knows how to retrieve a given view, can be
+used.
+
+\codetitle{Retrieving an object URL:}
+\begin{Verbatim}
+>>> from zope.app.testing.functional import BrowserTestCase
+>>> from zope.app import zapi
+>>> class MyTest(BrowserTestCase):
+...     def test_url(self):
+...         root = self.getRootFolder()
+...         request = self.makeRequest()
+...         url = zapi.getMultiAdapter((root, request), name='absolute_url')()
+...         self.assertEquals(url, 'http://localhost')
+...
+>>> import unittest
+>>> suite = unittest.makeSuite(MyTest)
+>>> test_runner = unittest.TextTestRunner()
+>>> test_runner.run(suite)
+<unittest._TextTestResult run=1 errors=0 failures=0>
+\end{Verbatim}
+
+\end{solution}
+
+\end{document}

Added: cookbook/trunk/recipe60.fr.tex
==============================================================================
--- (empty file)
+++ cookbook/trunk/recipe60.fr.tex      Thu Mar 30 18:28:32 2006
@@ -0,0 +1,67 @@
+\documentclass{book}
+\pagestyle{headings}
+\include{macros}
+\status{draft}
+\author{Tarek Ziad�}
+\translator{Tarek Ziad�}
+
+\begin{document}
+
+\chapter*{R�cup�rer l'URL d'un objet}
+
+\begin{problem}
+Zope 3 propose une approche plus \textit{propre} que la version pr�c�dente en
+ce qui concerne les URL des objets. Un objet donn� ne conserve pas
+son URL comme attribut. Cette recette explique le m�canisme de calcul
+de l'URL d'un objet et la logique sous-jacente.
+\end{problem}
+
+\begin{solution}
+\section*{Comprendre le principe}
+Chaque objet persistent de la ZODB est acc�d� au travers de vues, qui sont
+en charge de la publication. L'URL repr�sente la location de l'objet du point
+de vue du navigateur. Par exemple, si l'utilisateur souhaite afficher
+l'objet \code{foo} du r�pertoire \code{bar}, il tapera:
+\code{http://server/foo/bar}. L'objet est r�cup�r� par le publisher, qui
+traverse l'arborescence d'objets depuis la racine. Dans notre cas, il traverse
+\code{foo} et lui demande \code{bar}. \code{foo} fournira \code{bar} car
+son attribut \code{\_\_name\_\_} est  \code{bar}.
+
+R�cup�rer l'URL d'un objet consiste donc � faire le chemin inverse jusqu'�
+la racine, en construisant la cha�ne avec les noms des objets travers�s.
+
+La diff�rence majeure de ce nouveau m�canisme est que \code{bar} ne contient
+plus son URL.
+
+\section*{R�cup�rer l'URL d'un objet}
+
+L'URL de tous les objets publiables peut �tre r�cup�r� par ce m�canisme. Une
+vue g�n�rique \code{AbsoluteURL} fournie cette fonctionnalit� par le nom
+\code{absolute\_url}.
+
+Dans un ZPT par exemple, l'URL d'un objet peut �tre r�cup�r� par:
+\code{my\_object/@@absolute\_url}. Dans du code Python, un appel �
+\code{zapi.getMultiAdapter()}, qui permet de r�cup�rer les vues, peut �tre
+utilis�.
+
+\codetitle{R�cup�rer l'URL d'un objet:}
+\begin{Verbatim}
+>>> from zope.app.testing.functional import BrowserTestCase
+>>> from zope.app import zapi
+>>> class MyTest(BrowserTestCase):
+...     def test_url(self):
+...         root = self.getRootFolder()
+...         request = self.makeRequest()
+...         url = zapi.getMultiAdapter((root, request), name='absolute_url')()
+...         self.assertEquals(url, 'http://localhost')
+...
+>>> import unittest
+>>> suite = unittest.makeSuite(MyTest)
+>>> test_runner = unittest.TextTestRunner()
+>>> test_runner.run(suite)
+<unittest._TextTestResult run=1 errors=0 failures=0>
+\end{Verbatim}
+
+\end{solution}
+
+\end{document}

Modified: cookbook/trunk/recipe_list.txt
==============================================================================
--- cookbook/trunk/recipe_list.txt      (original)
+++ cookbook/trunk/recipe_list.txt      Thu Mar 30 18:28:32 2006
@@ -75,13 +75,15 @@
 57 - organizing the code in a package
 58 - learning naming conventions
 59 - creating a new content object
+60 - retrieving an object url (TZ)
+61 - creatin a rss feed for a container
 - ...
 
 Developping Zope - advanced recipes
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-60 - extending ZCML
-61 - extending ZPT
-62 - implementing a new publisher
+70 - extending ZCML
+71 - extending ZPT
+72 - implementing a new publisher
 - ...
 
 Administrating Zope
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to