[Zope] Using Zope Page Templates for forms (tabs of products)

Josef Meile jmeile at hotmail.com
Sun Aug 15 13:55:10 EDT 2004


--- In zope at yahoogroups.com, Pupeno <pupeno at p...> wrote:
 > -----BEGIN PGP SIGNED MESSAGE-----
 > Hash: SHA1
 >
 > On Friday August 13 2004 16:48, Josef Albert Meile wrote:
 > > def myTemplate(self):
 > >   """Here some attributes are added to the template"""
 > >   _myTemplate._owner=None
 > >   #Adds the management_view attribute to the built-in variable 
"options"
 > >   return _myTemplate.__of__(self)(management_view='Bounce')
 > Can you elaborate that a bit more ? what is __of__ ? why did you make
 > _ownner=None ?

"_myTemplate.__of__(self)" means "_myTemplate in the context of self". 
Take a look at the book of Dieter where he talks about Acquisition. It 
is explained there:
http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html

About _owner=None, taken textualy from this page:
http://www.zope.org/Members/Zen/howto/ZPT_management

"The important line here is manage_editThingyForm._owner = None. Without 
this line, your management screens will fail to work if the Thingy 
instance was created or owned by a user with restricted permissions, as 
access to the management screen helpers such as manage_page_header will 
fail."

 > > Then you can do this on zpt:
 > > <div tal:define="management_view options/management_view">
 > >   Do something here
 > > </div>
 > What about <p tal:content="options/management_view" /> ?
That should work as well.

 >
 > What I'm trying to do is this:
 >     security.declareProtected('Manage properties','manage_importForm')
 >     manage_importForm = PageTemplateFile('www/manage_importForm', 
globals())
 >     manage_importForm._owner = None
 >
 >     security.declareProtected('Manage properties', 'manage_import')
 >     def manage_import(self, REQUEST):
 > 	message="something"
 >         REQUEST.RESPONSE.setHeader('content-type', 'text/html')
 >         return self.manage_importForm.__of__(self)(message=message)
 >
 > And in the template:
 >
 > And when I try to access, I get the error:
 > Error Type: KeyError
 > Error Value: 'message'
 > What am I doing wrong ?
 > <div tal:define="message options/message">
 > </div>
I think you are a little bit confused. Normaly by convention, 
manage_importForm is the zpt object and manage_import is the submit 
method of the import form. If you see your code, you will see that you 
are not defining message on manage_import_Form. You define it later on 
manage_import, so, when you call your template "manage_import_Form, you 
will get a KeyError as expected.

I would redefine your sample like this:

_manage_importForm = PageTemplateFile('www/manage_importForm', globals())
security.declareProtected('Manage properties','manage_importForm')
def manage_importForm(self,REQUEST)
   _manage_importForm._owner=None
   message="something"
   REQUEST.RESPONSE.setHeader('content-type','text/html')
   return _manage_importForm.__of__(self)(message=message)

def manage_import(self, param1, param2, REQUEST=None):
   #Do somthing here to process the
   #information on the manage_importForm

Regards,
Josef


More information about the Zope mailing list