Re: [Zope3-Users] pagelets vs. pages

2007-06-27 Thread Stephan Richter
On Tuesday 26 June 2007 12:46, Hermann Himmelbauer wrote:
 At first, thanks for your reply, this clears things up a lot for me. The
 link to the Blog-entry above was also very valuable.

Great!

 What I still don't understand is how to implement a simple, quasi-static
 html-page. With browser:page I'd do it like this:

   browser:page
       name=index.html
       for=myapp.interfaces.IMyApp
       template=index.pt
       layer=swarmfinder.layer.IMyAppLayer
       permission=zope.Public
       /

I'll note that Zope 3 does a lot of black magic to make this directive work 
correctly.

 And the template mypage1.pt would e.g. use the body macro and have some
 static content.

Right.

 In case of pagelets, I'd do it like this (correct me if I'm wrong):

   z3c:pagelet
       for=*
       name=index.html
       permission=zope.View
       class=.MyAppPage1
       layer=z3c.layer.pagelet.IPageletBrowserLayer
       /

     z3c:template
       for=.MyAppPage1
       layer=z3c.layer.pagelet.IPageletBrowserLayer
       template=mypage1.pt
       /

 And then I'd have to implement an interface and a class:

 class IMyAppPage1(zope.interface.Interface):
   pass

 class MyAppPage1(BrowserPagelet)
   implements(IMyAppPage1)

 This is a lot more code than with the browser:page example.
 As a solution, I'm thinking about a magic template directive in the
 z3c:pagelet namespace, e.g. something like that:

   z3c:pagelet
       for=*
       name=index.html
       permission=zope.View
       template=mypage1.pt
       layer=z3c.layer.pagelet.IPageletBrowserLayer
       /

This example is longer than it needs to be. For starters, you do not need the 
interface; in your example it serves no use. Optionally, if you do not need 
to keep template registration independent of view registration, the following 
will work as well:

class MyAppPage1(BrowserPagelet):
template = viewpagetemplatefile.ViewPageTemplateFile('mypage1.pt')

z3c:pagelet
for=*
name=index.html
permission=zope.View
class=.MyAppPage1
layer=z3c.layer.pagelet.IPageletBrowserLayer
/

In our experience, we rarely do static pages, maybe one every 20-30 other 
views. Then, we purposefully did not provide the semantics of the 
browser:page directive, because we *want* transparency. So why optimize this 
rare use case at the cost of losing transparency?

 Perhaps in case of this template directive, the interface/view class
 could be created on the fly? What do you think?

No, one of the (maybe implicit) goals of pagelets is to require view classes 
and get rid of the class building magic.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics  Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Trouble with Skins

2007-06-27 Thread Hermann Himmelbauer
Am Dienstag, 26. Juni 2007 12:43 schrieb Arne Nordmann:
 Hi,

 I tried to create my own skin for a website of mine. I used Phillip's
 book (2nd version) and tried to do everything analog (just different
 names and a slightly different file structure).

 If I call a test view (registered for IRootFolder) with the skin I get
 the following error:

 ComponentLookupError: ((zope.app.folder.folder.Folder object at
 0x886916c, zope.publisher.browser.BrowserRequest instance
 URL=http://localhost:9673/++skin++norro/test), InterfaceClass
 zope.interface.Interface, 'h')

 (Full traceback attached)

 I don't know what this traceback wants to say. I'm wondering about the
 value of the name-parameter that seems to be 'h' in this case. Where
 does this 'h' come from? I really don't know where to look at.

Looking at the traceback, it seems that the lookup error is happening here:
File /usr/lib/python2.4/site-packages/zope/app/basicskin/standardmacros.py, 
line 41, in __getitem__
page = getMultiAdapter((context, request), name=name)

And above there's this:

   - Warning: Macro expansion failed
   - Warning: zope.component.interfaces.ComponentLookupError: 
((zope.app.folder.folder.Folder object at 0x886916c, 
zope.publisher.browser.BrowserRequest instance 
URL=http://localhost:9673/++skin++norro/test), InterfaceClass 
zope.interface.Interface, 'h')

So it seems it's some macro-related problem, perhaps you check the 
metal:define-macro/metal:use-macro definitions.

However, this case shows me that I'm not the only one with such problems. 
These ComponentLookupErrors and cryptic tracebacks (at least for newbies) 
drove me mad and costed me hours to resolve. In the end it was always my 
fault, e.g.:

- Forgot to add the appropriate  layer to the request
- Forgot to omit __parent__ in my formlib class
- Forgot to register something or registered it for the wrong interface

I'm curious how others deal with this problem because I'm often paralyzed by 
this ComponentLookupError. The traceback also does not show which interface 
my objects provide - for example it cannot be seen if a BrowserRequest 
provides a specific layer or not. To solve this problem, I had to insert 
something like print IMyLayer.providedBy(request) into the Zope source to 
find out what happens.

Maybe a Zope3 newbie-debug-mode would help a lot that throws a traceback 
like this (regarding to the original problem)?


... Original Traceback ...
--- Verbose Traceback ---
A query for a named adapter adapting from the object(s):

 - zope.app.folder.folder.Folder object at 0x886916c (providing IFolder)
 - zope.publisher.browser.BrowserRequest instance 
URL=http://localhost:9673/++skin++norro/test (providing IBrowserRequest)

to the interface:

- InterfaceClass zope.interface.Interface

With the adapter name 'h' could not be found.
Helpful tips how to resolve this are given at http://zope3faq.org/123


Best Regards,
Hermann

-- 
[EMAIL PROTECTED]
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Getting view result from Python

2007-06-27 Thread Thierry Florac

  Hi,

I'd like to get a view output from some Python code.

Actually, I don't have any problem if I use a page template with a
simple tal:x content=structure context/@@viewname / expression and
return self.template() in Python.
But it should certainly be cleaner and less expensive to get view
output directly from Python code, which I don't actually manage to do...

So any advise to this probably simple problem would be welcome.

Thanks,

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : [EMAIL PROTECTED]
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Trouble with Skins

2007-06-27 Thread Arne Nordmann
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Herman,

thank you very much for your answer.

 However, this case shows me that I'm not the only one with such problems. 
 These ComponentLookupErrors and cryptic tracebacks (at least for newbies) 
 drove me mad and costed me hours to resolve. In the end it was always my 
 fault, e.g.:
 
 - Forgot to add the appropriate  layer to the request
 - Forgot to omit __parent__ in my formlib class
 - Forgot to register something or registered it for the wrong interface
You were completely right. The problem was an absent comma in
standardmacros.py and an incorrect closed metal-tag. [1]

 I'm curious how others deal with this problem because I'm often paralyzed by 
 this ComponentLookupError. The traceback also does not show which interface 
 my objects provide - for example it cannot be seen if a BrowserRequest 
 provides a specific layer or not. To solve this problem, I had to insert 
 something like print IMyLayer.providedBy(request) into the Zope source to 
 find out what happens.
Phillip von Weitershausen had a great talk at the DZUG conference this
year about Zope on a Paste[2]. He demonstrated some kind of middleware
that does what you asked for - giving you the possibility to look into
every object in the moment the error occurred.
I wonder if a tool like this will find it's way to the ordinary Zope3
user. Phillip?

 Maybe a Zope3 newbie-debug-mode would help a lot that throws a traceback 
 like this (regarding to the original problem)?
 
 
 ... Original Traceback ...
 --- Verbose Traceback ---
 ...
I'm completely with you at this point. When I came to the point to solve
a problem based on a traceback for the first time, I was stuck.
Even when I solved those problems in the past, I often couldn't find a
hint in the traceback retroactively, even with knowing the actual problem.

I often thought about something like you suggested - a kinda comfort
traceback.
One of the advantages of a CMS-like system like Zope is, that you don't
have to care about the entire machine that is working in the background
behind your application. But from the moment on you get the error, you
are forced to deal with the traceback that gives you lots of information
on parts of this machine you don't really want to deal with.

As I mentioned, I'm loosely thinking about this kinda comfort traceback
for months, but I don't really think that my understanding of the Zope3
machine is deep enough to do this on my own.
Perhaps there should be a draft or some kind of feature request thrown
to the Zope3-dev list to exchange opinions with the developers.

Regards,

Arne

- -
[1] For those, who deal with the same error:
- - I forgot to type the comma in the value of the attribute 'macro_pages'
of zope.app.basicskin.standardmacros.StandardMacros (see example 10.3.2
in Phillip's book Web Component Development With Zope3, 2nd Edition)
- - I falsely closed a metal:slot-tag with /metal instead of
/metal:slot in my custom page macro.

[2]
http://www.zope.de/redaktion/dzug/tagung/potsdam-2007/folien/zope-on-a-paste.pdf
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGgj+5RawDj1XqbtwRAg1nAJ4sru+DtJXqF+r+hw3ESJpPslMYlACbBFnd
49eUvBiLeIj7sAMvdGJpwVw=
=c7AO
-END PGP SIGNATURE-
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


AW: [Zope3-Users] pagelets vs. pages

2007-06-27 Thread Roger Ineichen
Hi Stephan, Herman

 Betreff: Re: [Zope3-Users] pagelets vs. pages
 
 On Tuesday 26 June 2007 12:46, Hermann Himmelbauer wrote:
  At first, thanks for your reply, this clears things up a 
 lot for me. 
  The link to the Blog-entry above was also very valuable.
 
 Great!
 
  What I still don't understand is how to implement a simple, 
  quasi-static html-page. With browser:page I'd do it like this:
 
    browser:page
        name=index.html
        for=myapp.interfaces.IMyApp
        template=index.pt
        layer=swarmfinder.layer.IMyAppLayer
        permission=zope.Public
        /
 
 I'll note that Zope 3 does a lot of black magic to make this 
 directive work correctly.
 
  And the template mypage1.pt would e.g. use the body 
 macro and have 
  some static content.
 
 Right.
 
  In case of pagelets, I'd do it like this (correct me if I'm wrong):
 
    z3c:pagelet
        for=*
        name=index.html
        permission=zope.View
        class=.MyAppPage1
        layer=z3c.layer.pagelet.IPageletBrowserLayer
        /
 
      z3c:template
        for=.MyAppPage1
        layer=z3c.layer.pagelet.IPageletBrowserLayer
        template=mypage1.pt
        /
 
  And then I'd have to implement an interface and a class:
 
  class IMyAppPage1(zope.interface.Interface):
    pass
 
  class MyAppPage1(BrowserPagelet)
    implements(IMyAppPage1)
 
  This is a lot more code than with the browser:page example.
  As a solution, I'm thinking about a magic template 
 directive in the 
  z3c:pagelet namespace, e.g. something like that:
 
    z3c:pagelet
        for=*
        name=index.html
        permission=zope.View
        template=mypage1.pt
        layer=z3c.layer.pagelet.IPageletBrowserLayer
        /
 
 This example is longer than it needs to be. For starters, you 
 do not need the interface; in your example it serves no use. 
 Optionally, if you do not need to keep template registration 
 independent of view registration, the following will work as well:
 
 class MyAppPage1(BrowserPagelet):
 template = viewpagetemplatefile.ViewPageTemplateFile('mypage1.pt')
 
 z3c:pagelet
 for=*
 name=index.html
 permission=zope.View
 class=.MyAppPage1
 layer=z3c.layer.pagelet.IPageletBrowserLayer
 /


Please don't use the z3c.viewtemplate package.

You can use the z3c.template package which offers
you a much better separated concept.

z3c.template and z3c.macro replaces the z3c.viewtemplate
package.

Regards
Roger Ineichen

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Re: z3c.form now has group support

2007-06-27 Thread David Pratt
Woo hoo! This is excellent Stephan and an easy way to handle this common 
scenario (and much more elegant than Django for sure). Many thanks for 
your great work on this!


Regards,
David

Stephan Richter wrote:

Hi David,

I just wanted to let you know that I just checked in some group support for 
z3c.form. I am quite happy how it turned out. I have not done any formui work 
or wrote an example, but there is a group.txt document explaining how it 
works.


Regards,
Stephan

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Getting view result from Python

2007-06-27 Thread Christophe Combelles

Thierry Florac a écrit :

  Hi,

I'd like to get a view output from some Python code.

Actually, I don't have any problem if I use a page template with a
simple tal:x content=structure context/@@viewname / expression and
return self.template() in Python.
But it should certainly be cleaner and less expensive to get view
output directly from Python code, which I don't actually manage to do...

So any advise to this probably simple problem would be welcome.


It depends on what you call a view,
if this is a BrowserPage, you have a __call__ method that returns the output.
so just call your view().
If this is a BrowserView, there is no __call__ because a BrowserView is not 
intended to be published as is. But you can have any method that returns HTML.
If this is a Viewlet or a ContentProvider, there is a render method that returns 
the output. (provided you first call the update method)


Christophe

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Getting view result from Python

2007-06-27 Thread Thierry Florac
Le mercredi 27 juin 2007 à 14:31 +0200, Christophe Combelles a écrit :
 Thierry Florac a écrit :
Hi,
  
  I'd like to get a view output from some Python code.
  
  Actually, I don't have any problem if I use a page template with a
  simple tal:x content=structure context/@@viewname / expression and
  return self.template() in Python.
  But it should certainly be cleaner and less expensive to get view
  output directly from Python code, which I don't actually manage to do...
  
  So any advise to this probably simple problem would be welcome.
 
 It depends on what you call a view,
 if this is a BrowserPage, you have a __call__ method that returns the output.
 so just call your view().
 If this is a BrowserView, there is no __call__ because a BrowserView is not 
 intended to be published as is. But you can have any method that returns HTML.
 If this is a Viewlet or a ContentProvider, there is a render method that 
 returns 
 the output. (provided you first call the update method)

In fact it's a little bit more complicated...
What I have at first is a BrowserPage view, which is generally called
from a page template with context/@@viewname syntax, without any
problem.

But I need also to be able to get the same view output from a JSON call,
so that I can update a little bit of HTML code dynamically. I don't have
any problem when defining a template with the same syntax. But if I call
in python :

  view = zapi.getMultiAdapter((myContext,myRequest), Interface,
  name=u'viewname')

I receive an error message :

  __init__() takes at least 3 arguments (1 given)

So zapi.getMultiAdapter creates the view, but how can I initialize it
with it's required parameters (context and request) ?

Thanks,

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : [EMAIL PROTECTED]
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Getting view result from Python

2007-06-27 Thread Marius Gedminas
On Wed, Jun 27, 2007 at 04:59:07PM +0200, Thierry Florac wrote:
 Le mercredi 27 juin 2007 à 14:31 +0200, Christophe Combelles a écrit :
  Thierry Florac a écrit :
   I'd like to get a view output from some Python code.
   
   Actually, I don't have any problem if I use a page template with a
   simple tal:x content=structure context/@@viewname / expression and
   return self.template() in Python.
   But it should certainly be cleaner and less expensive to get view
   output directly from Python code, which I don't actually manage to do...
  
  It depends on what you call a view,
  if this is a BrowserPage, you have a __call__ method that returns the 
  output.
  so just call your view().
  If this is a BrowserView, there is no __call__ because a BrowserView is not 
  intended to be published as is. But you can have any method that returns 
  HTML.

If you use getMultiAdapter to get the view, all these differences are
hidden and you can call the view to get its output.

  If this is a Viewlet or a ContentProvider, there is a render method that 
  returns 
  the output. (provided you first call the update method)

Then it's not really a view, is it?  ;-)

 In fact it's a little bit more complicated...
 What I have at first is a BrowserPage view, which is generally called
 from a page template with context/@@viewname syntax, without any
 problem.
 
 But I need also to be able to get the same view output from a JSON call,
 so that I can update a little bit of HTML code dynamically. I don't have
 any problem when defining a template with the same syntax. But if I call
 in python :
 
   view = zapi.getMultiAdapter((myContext,myRequest), Interface,
   name=u'viewname')

This should work.  You don't have to pass Interface explicitly, by the
way, view = getMultiAdapter((context, request), name='...') will work as
well.

 I receive an error message :
 
   __init__() takes at least 3 arguments (1 given)

I don't believe you :-)

Can you show the full traceback?  getMultiAdapter definitely passes the
context tuple to the adapter's __init__.  There must be some other piece
of code that fails for you.

 So zapi.getMultiAdapter creates the view, but how can I initialize it
 with it's required parameters (context and request) ?

getMultiAdapter does that.  I speak from personal experience.

Marius Gedminas
-- 
...the only place for 63,000 bugs is a rain forest


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users