Mailing List Archive

Zope 2: traversing and modifying DTM doc in folders?
Greetings, I have a developer here trying to fix a problem with some legacy Zope 2 (2.8.6) material. Basically, she is trying to change properties on a DTML document, but so far cannot get the script to recursively search through folders to act on every document in the hierarchy.

Any advice is greatly appreciated!

Best,

Dan

-------------------------------------------------------------------------------------------------------------
Hello, the things we want to do is to find every media file (DTML document) in a folder structure and change their format. They are a few folders deep and the number of folders that contain the file is unknown, so I tried to use a recursive way to get access to every document.

So this is what I did, I wrote a script named changeType with parameter "object", which is initially 0. Then when object is 0, just set object = context. If in "object" we found that there's another folder called f, just called changeType(f). The script is shown as below:

#parameter object = 0
from Products.PythonScripts.standard import html_quote
request = context.REQUEST
RESPONSE = request.RESPONSE

if object == 0:
object = context

folders = object.objectValues(['Folder'])
for f in folders:
fds = f.objectValues(['Folder'])
if(len(fds) != 0):
f.changeType(f)
.......(methods to change format)

But this causes an error:

Error Type: AttributeError
Error Value: ‘str’ object has no attribute ‘objectValues'
​
I think the reason should be, it doesn't seen "object" or "context" as object and context but seen them just as strings. But I have no idea about how could I solve this or if there's any other way I can call a recursive method to get every DTML document in their respective subfolders. Please let me know if you have any suggestion/examples on Zope/found another error in my code/etc.
_______________________________________________
Zope maillist - Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )
Re: Zope 2: traversing and modifying DTM doc in folders? [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/11/2015 02:05 PM, Dan Gaibel wrote:
> Greetings, I have a developer here trying to fix a problem with some
> legacy Zope 2 (2.8.6) material. Basically, she is trying to change
> properties on a DTML document, but so far cannot get the script to
> recursively search through folders to act on every document in the
> hierarchy.
>
> Any advice is greatly appreciated!
>
> Best,
>
> Dan
>
>
-
-------------------------------------------------------------------------------------------------------------
> Hello, the things we want to do is to find every media file (DTML
> document) in a folder structure and change their format. They are a
> few folders deep and the number of folders that contain the file is
> unknown, so I tried to use a recursive way to get access to every
> document.
>
> So this is what I did, I wrote a script named changeType with
> parameter "object", which is initially 0. Then when object is 0, just
> set object = context. If in "object" we found that there's another
> folder called f, just called changeType(f). The script is shown as
> below:
>
> #parameter object = 0 from Products.PythonScripts.standard import
> html_quote request = context.REQUEST RESPONSE = request.RESPONSE
>
> if object == 0: object = context
>
> folders = object.objectValues(['Folder']) for f in folders: fds =
> f.objectValues(['Folder']) if(len(fds) != 0): f.changeType(f)
> .......(methods to change format)
>
> But this causes an error:
>
> Error Type: AttributeError Error Value: ‘str’ object has no attribute
> ‘objectValues'


You likely want to use 'ZopeFind', which handles all the recursion for
you. E.g.:

for _, dtml_doc in context.ZopeFind(obj_metatypes=['DTML Document']):
# do something with 'dtml_doc' here.


Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver@palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBAgAGBQJVyj6LAAoJEPKpaDSJE9HYMI8P/1kXr5HkXlQaX35MM3JPBFG4
cMfDUwumSfD2LQF9NDJPGMWZszu//DBLJ4iQ8Sis7Vu0F5aq9EdruZ8/O3yFYwEh
Asv4p8G0d+M3XX19JUHuH0787xq2Zcf/Jx0lQHBY1gnfg6Jt/xlbL4owaoRqR/gN
zu1iPdc8f00LEKoB7XryXhVilbkkJqn8/wXjNReVBsKwOnCH/E7FPBTKairyzdm0
0Azz5tiRyYvXrndsHsLjok7gBUAWx+aOyJOqqSs/dZmMMj522DDcaXbjfy2jmrr3
JbpccAUTNFIIxKDlgWeoSGNE0fVWaSG/oWnn68IpRWDlpEUrvVjZJZXSBinI0uD/
urXA+1u/r9vinZKjzT/q5qTmrSbuIHd6A2bo2kYTCkTbp8e9gD8Kx8VHWDQjPQCI
tY+iFRxGUAut5oSbdm2fhVx3WhK6qf1SLGCGiEt5x5+Nxyut2d9lPByGpJWmI1Rd
ioJkY1XiE4omsn6blZQfBUauSEkTPEfR+fEtGsj6xDBUv0Uoovjumk+QlV03Zgq+
GJMOUzhBxqxst5QoU6mW5xPV98uQ7Bcspo741Gme+lAjYFoaDSuw8arNWP8clX4P
Gx4LcGoJF4X6kdXIYFwRD4mw+QsTFjD4enDzIUqpIrUL94I6M7nRre0SmDpL5FQk
dSu4D/EGtNxMtkOh/XWp
=6+2r
-----END PGP SIGNATURE-----

_______________________________________________
Zope maillist - Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )