Re: [Zope] load_site.py and zpt files
hello, I am still trying to enhance load_site.py to create zope page template files for files with suffix .zpt . Dieter Maurer has suggested to use Client.call
From dieter@handshake.de Fri Sep 13 20:32 MET 2002 From: Dieter Maurer <dieter@handshake.de> Subject: Re: [Zope] load_site.py and zpt files
jbr@FIZ-Karlsruhe.DE writes:
... call(object.manage_addProduct['PageTemplates'].manage_addPageTemplate( id=name, title='', text=f)) ... call(object.manage_addProduct['PageTemplates'].manage_addPageTemplate( id=name, title='', text=f)) AttributeError: Function instance has no attribute '__getitem__' "object.manage_addProduct" is a "Function" instance (defined in "ZPublisher.Client"). It does not have a "__getitem__" instance. Therefore, you cannot use subscription ("[...]").
Use 'Client.call("%s/manage_addProduct/PageTemplates/manage_addPageTemplate" % URL_TO_OBJECT, id=name, title='', text=f)'
Dieter
therefore I changed function upload_zpt: def upload_zpt(object, f): import ZPublisher.Client dir, name = os.path.split(f) f=open(f) ZPublisher.Client.call("%s/manage_addProduct/PageTemplates/manage_addPageTemplate" % object.url, username=object.username, password=object.password, id=name, title='', text=f) if verbose: print 'in upload_zpt end of function' I tried to upload file: test35.zpt to URL: http://a7dsid1:8040/Testordner where "Testordner" is a normal zope folder. object.url is: http://a7dsid1:8040/Testordner id is: test35.zpt But I have got some strange results: 1.) a zope page template file http://a7dsid1:8040/Testordner/test35.zpt was created, but a error was raised ( see trace below) 2.) the content of http://a7dsid1:8040/Testordner/test35.zpt is not the the content of file test35.zpt (It seems that Parameter text=f is ignored.) but a standard zope page template instead: <html> <head> <title tal:content="template/title">The title</title> </head> <body> <h2><span tal:replace="here/title_or_id">content title or id</span> <span tal:condition="template/title" tal:replace="template/title">optional template id</span></h2> This is Page Template <em tal:content="template/id">template id</em>. </body> </html> upload_zpt test35.zpt Traceback (most recent call last): File "/opt/projects/idep/zope/utilities/load_site_fiz.py", line 314, in ? if __name__=='__main__': main() File "/opt/projects/idep/zope/utilities/load_site_fiz.py", line 102, in main for f in files: upload_file(object, f) File "/opt/projects/idep/zope/utilities/load_site_fiz.py", line 121, in upload_file return globals()['upload_'+ext](object, f) File "/opt/projects/idep/zope/utilities/load_site_fiz.py", line 302, in upload_zpt ZPublisher.Client.call("%s/manage_addProduct/PageTemplates/manage_addPageTemplate" % object.url, username=object.username, password=object.password, id=name, title='', text=f) File "/opt/projects/idep/zope/lib/python/ZPublisher/Client.py", line 274, in call return apply(Function(url,username=username, password=password), (), kw) File "/opt/projects/idep/zope/lib/python/ZPublisher/Client.py", line 109, in __call__ if hasattr(v,'read'): return self._mp_call(kw) File "/opt/projects/idep/zope/lib/python/ZPublisher/Client.py", line 231, in _mp_call self.handleError('', ec, em, headers, response) File "/opt/projects/idep/zope/lib/python/ZPublisher/Client.py", line 170, in handleError raise t, RemoteException(t,v,f,l,self.url,query,ec,em,response) bci.ServerError: 302 (File: Unknown Line: Unknown) 302 Moved Temporarily for http://a7dsid1:8040/Testordner/manage_addProduct/PageTemplates/manage_addPag... With kind regards, Juergen Berger
jbr@FIZ-Karlsruhe.DE wrote:
hello,
I am still trying to enhance load_site.py to create zope page template files for files with suffix .zpt .
Dieter Maurer has suggested to use Client.call
From dieter@handshake.de Fri Sep 13 20:32 MET 2002 From: Dieter Maurer <dieter@handshake.de> Subject: Re: [Zope] load_site.py and zpt files
jbr@FIZ-Karlsruhe.DE writes:
... call(object.manage_addProduct['PageTemplates'].manage_addPageTemplate( id=name, title='', text=f)) ... call(object.manage_addProduct['PageTemplates'].manage_addPageTemplate( id=name, title='', text=f)) AttributeError: Function instance has no attribute '__getitem__' "object.manage_addProduct" is a "Function" instance (defined in "ZPublisher.Client"). It does not have a "__getitem__" instance. Therefore, you cannot use subscription ("[...]").
Use 'Client.call("%s/manage_addProduct/PageTemplates/manage_addPageTemplate" % URL_TO_OBJECT, id=name, title='', text=f)'
Dieter
therefore I changed function upload_zpt:
def upload_zpt(object, f): import ZPublisher.Client
dir, name = os.path.split(f) f=open(f)
ZPublisher.Client.call("%s/manage_addProduct/PageTemplates/manage_addPageTemplate" % object.url, username=object.username, password=object.password, id=name, title='', text=f)
if verbose: print 'in upload_zpt end of function'
I tried to upload file: test35.zpt to URL: http://a7dsid1:8040/Testordner where "Testordner" is a normal zope folder.
object.url is: http://a7dsid1:8040/Testordner id is: test35.zpt
But I have got some strange results: 1.) a zope page template file http://a7dsid1:8040/Testordner/test35.zpt was created, but a error was raised ( see trace below)
This is an easy one. This error is due to the fact that you do a call like a webbrowser. Therefore manage_addTemplate gets a REQUEST variable passed, and most, if not all, "through the web callable" methods in zope contain something like: if REQUEST is not None: [return a redirect to another page] Because it doesn't get a 200 response, ZPublisher.Client raises an exception. Look at the call() method of load_site to see how they handle this (they ignore exceptions caused by 3xy responses) and just copy the code.
2.) the content of http://a7dsid1:8040/Testordner/test35.zpt is not the the content of file test35.zpt (It seems that Parameter text=f is ignored.) but a standard zope page template instead:
This is because manage_addPageTemplate handling of the uploaded file is slightly different from e.g. addDTMLMethod. manage_addPageTemplate forces you to upload a File (in the sense of a <input type="File"...> form tag (maybe because it needs information about the content type?), while addDTMLMethod also works when text is just a string. Look in the source of lib/python/Products/PageTemplates/ZopePageTemplate.py for manage_addPageTemplate for more infos. So the best might be to first add the zpt as you do, and afterwards call it's edit method to upload your text content, unfortunately I'm not experienced in ZPTs. From a glance at the source, maybe it suffices to call ZPublisher.Client.call("%s/%s/pt_upload" % (object.url, name), username=object.username, password=object.password, file=f) after you added the ZPT. Don't forget to catch any 3xy responses again. HTH, oliver
participants (2)
-
jbr@FIZ-Karlsruhe.DE -
Oliver Bleutgen