[Zope] load_site.py and zpt files

jbr@FIZ-Karlsruhe.DE jbr@FIZ-Karlsruhe.DE
Mon, 16 Sep 2002 17:55:27 +0200 (MEST)


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_addPageTemplate




With kind regards, Juergen Berger