[Zope] HowTo Render txt-Files with LocalFS in PythonScript?

Elena Schulz elena.schulz@gmx.net
Mon, 5 Aug 2002 18:39:52 +0200


Hi Douwe,

thanks for your help, I didn't know that LocalFS checks the ending and
behaves accordingly. Now using

print myLFS['textfile.dtml'](_.None, _)

works well but another problem came up: if there is a <dtml-var id> in that
textfile.dtml I get the following error.
But an id-Property should be everywhere isn't it? So what to do so that the
names in the context are found?

Thanks again for your anwers and your patience,

Elena


Error Type: NameError
Error Value: global name 'id' is not defined


Traceback (innermost last):
  File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 223, in
publish_module
  File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 187, in
publish
  File J:\Zope\ZopeSite\lib\python\Zope\__init__.py, line 226, in
zpublisher_exception_hook
    (Object: jobs)
  File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 171, in
publish
  File J:\Zope\ZopeSite\lib\python\ZPublisher\mapply.py, line 160, in mapply
    (Object: index.html)
  File J:\Zope\ZopeSite\lib\python\ZPublisher\Publish.py, line 112, in
call_object
    (Object: index.html)
  File J:\Zope\ZopeSite\lib\python\OFS\DTMLMethod.py, line 199, in __call__
    (Object: index.html)
  File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_String.py, line 546,
in __call__
    (Object: index.html)
  File J:\Zope\ZopeSite\lib\python\OFS\DTMLMethod.py, line 192, in __call__
    (Object: inhalt)
  File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_String.py, line 546,
in __call__
    (Object: inhalt)
  File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_Util.py, line 231, in
eval
    (Object: getContentFiles(_.None,sourceFolder,contentFiles))
    (Info: getContentFiles)
  File <string>, line 2, in f
    (Object: guarded_getattr)
  File J:\Zope\ZopeSite\lib\python\Shared\DC\Scripts\Bindings.py, line 324,
in __call__
    (Object: getContentFiles)
  File J:\Zope\ZopeSite\lib\python\Shared\DC\Scripts\Bindings.py, line 354,
in _bindAndExec
    (Object: getContentFiles)
  File J:\Zope\ZopeSite\lib\python\Products\PythonScripts\PythonScript.py,
line 363, in _exec
    (Object: getContentFiles)
    (Info: ({'script': <PythonScript instance at 018BF5A0>, 'context':
<Folder instance at 018DFE70>, 'container': <Folder instance at 01847B50>,
'_': <TemplateDict object at 01F4B480>, 'traverse_subpath': []}, (None,
'stxTexte', ['jobs.dtml']), {}, (None, None)))
  File Script (Python), line 16, in getContentFiles
  File J:\Zope\ZopeSite\lib\python\OFS\DTMLMethod.py, line 192, in __call__
    (Object: jobs.dtml)
  File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_String.py, line 546,
in __call__
    (Object: jobs.dtml)
  File J:\Zope\ZopeSite\lib\python\DocumentTemplate\DT_Util.py, line 231, in
eval
    (Object: id)
    (Info: id)
  File <string>, line 2, in f
NameError: (see above)



----- Original Message -----
From: <douwe@oberon.nl>
To: "Elena Schulz" <elena.schulz@gmx.net>; <zope@zope.org>
Sent: Monday, August 05, 2002 12:44 PM
Subject: RE: [Zope] HowTo Render txt-Files with LocalFS in PythonScript?


> Hi,
>
> Just to clarify, you have a .txt file and you want it to be rendered as if
> it was a DTML file with LocalFS.
>
> If so, I don' think that is going to work. See, the LocalFS product does
> not know the types of the files it serves, so it tries to guess them and
> then creates a wrapper object around the file to expose the functionality
> of the zope object normally associated with the object. Anyway, if it sees
> a .txt file, it will produce a file object (print the meta_type), if it
> would serve a .dtml file, it would serve a dtml object. So, in your case
> it serves a file object, which does not support the render method __call__
>
> You could solve this by either renaming your file to .dtml, or you might
> have a try and change the type_map property of your localFS instance.
> associating
> .txt files with DTMLMethod/Document should make localFS produce the right
> kind of objects.
>
> Douwe
>
> > -----Original Message-----
> > From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Elena
> > Schulz
> > Sent: Monday, August 05, 2002 12:01 PM
> > To: zope@zope.org
> > Subject: [Zope] HowTo Render txt-Files with LocalFS in PythonScript?
> >
> >
> > Dear List,
> >
> > with the following PythonScript I try to render the content of txt-Files
> > with LocalFS according to the howto of LocalFS (...snip..." To insert
the
> > text of the file after evaluating it as a DTML template in the current
> > namespace, you would use:  <dtml-var "test['foo.dtml'](_.None, _)">
> > .....snip ...").
> >
> > My Script:
> >
> > ## Script (Python) "getContentFiles"
> > ##bind container=container
> > ##bind context=context
> > ##bind namespace=_
> > ##bind script=script
> > ##bind subpath=traverse_subpath
> > ##parameters=REQUEST=None,myLFSInstance
> > ##title=
> >
> > myLFS = getattr(context, myLFSInstance)
> > print myLFS['textfile.txt'](_.None,_)
> >
> > but I get the below Error-Message. If I try:
> >
> > print myLFS['textfile.txt'].data
> >
> > the content is returned but without rendering (as expected).
> > Does anybody know how to get the rendering done?
> >
> > Thanks a lot for your help,
> >
> > Elena
> >