DTML-IN only over special documents??
Hi, I've got a question concerning dtml-in. I know that it is possible to loop only over DTML Documents in a folder containing objects of different type. But is it possible to loop only over documents, that id's e.g. start with 'mydoc' ??? Example-folder with the objects: mydoc1 mydoc35 picture567 picture33 mydoc98 So dtml-in shall only loop over 'mydoc1', 'mydoc35', 'mydoc98' How can I do that? TIA Marc
<dtml-in "objectValues(['some meta type'])"> <dtml-if "_.string.find(_['sequence-item'].getId(),'mydoc') ==0"> do something here </dtml-if> </dtml-in> or preferably do it in a python script: #script called mydoc_filter import string l=context.objectValues(['some_meta_type']) retval=[] for a in l: if string.find(a.getId(),'mydoc'): retval.append(a) return a then in dtml: <dtml-in mydoc_filter> do something here </dtml-in> hth Phil ----- Original Message ----- From: "Breitenreicher, Marc" <Marc.Breitenreicher@friatec.de> To: <zope@zope.org> Sent: Monday, March 18, 2002 3:28 PM Subject: [Zope] DTML-IN only over special documents??
Hi, I've got a question concerning dtml-in.
I know that it is possible to loop only over DTML Documents in a folder containing objects of different type. But is it possible to loop only over documents, that id's e.g. start with 'mydoc' ???
Example-folder with the objects: mydoc1 mydoc35 picture567 picture33 mydoc98
So dtml-in shall only loop over 'mydoc1', 'mydoc35', 'mydoc98'
How can I do that?
TIA
Marc
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
change: if string.find(a.getId(),'mydoc'): to: if string.find(a.getId(),'mydoc') == 0: ----- Original Message ----- From: "Phil Harris" <phil@harris-family.info> To: "Breitenreicher, Marc" <Marc.Breitenreicher@friatec.de>; <zope@zope.org> Sent: Monday, March 18, 2002 3:38 PM Subject: Re: [Zope] DTML-IN only over special documents??
<dtml-in "objectValues(['some meta type'])"> <dtml-if "_.string.find(_['sequence-item'].getId(),'mydoc') ==0"> do something here </dtml-if> </dtml-in>
or preferably do it in a python script:
#script called mydoc_filter import string l=context.objectValues(['some_meta_type']) retval=[] for a in l: if string.find(a.getId(),'mydoc'): retval.append(a) return a
then in dtml:
<dtml-in mydoc_filter> do something here </dtml-in>
hth
Phil ----- Original Message ----- From: "Breitenreicher, Marc" <Marc.Breitenreicher@friatec.de> To: <zope@zope.org> Sent: Monday, March 18, 2002 3:28 PM Subject: [Zope] DTML-IN only over special documents??
Hi, I've got a question concerning dtml-in.
I know that it is possible to loop only over DTML Documents in a folder containing objects of different type. But is it possible to loop only over documents, that id's e.g. start with 'mydoc' ???
Example-folder with the objects: mydoc1 mydoc35 picture567 picture33 mydoc98
So dtml-in shall only loop over 'mydoc1', 'mydoc35', 'mydoc98'
How can I do that?
TIA
Marc
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
then in dtml:
<dtml-in mydoc_filter> do something here </dtml-in>
Phil, To show a solution first in DTML, and then in Python and DTML is an excellent idea! I never quite grasped the meaning of "separate logic from presentation" until I saw it in this form. I think that everyone who contributes code to the mailing list should occasionally include both solutions.... it is a very educational experience. -- Milos Prudek
[Phil Harris]
<dtml-in "objectValues(['some meta type'])"> <dtml-if "_.string.find(_['sequence-item'].getId(),'mydoc') ==0"> do something here </dtml-if> </dtml-in>
or preferably do it in a python script:
#script called mydoc_filter import string l=context.objectValues(['some_meta_type']) retval=[] for a in l: if string.find(a.getId(),'mydoc'): retval.append(a) return a
Remember that string.find returns -1, not 0, if it can't find the substring, so this test won't work if the value starts with the search string. The test needs to be if string.find(a.getId(),'mydoc')>-1: Cheers, Tom P
dtml in does not have a built in facility to filter this way, but you can write a short python script that returns a list of objects named a certain way: docs = [] for id in context.objectIds('DTML Document'): if id.startswith('mydoc'): docs.append(context[id]) return docs If you call this getDocs, you could use it in dtml like so: <dtml-in expr="Folder.getDocs()"> ... </dtml-in> Just put getDocs somewhere where Folder can acquire it. Or if you want to squirrel it away somewhere (like in a "scripts" folder), add an parameter to the script so you can pass it the folder to look in. You could also add parameters for the meta-type and name to look for to make it more generic. BTW: The above code assumes Python 2.0 or better. hth, Casey Breitenreicher, Marc wrote:
Hi, I've got a question concerning dtml-in.
I know that it is possible to loop only over DTML Documents in a folder containing objects of different type. But is it possible to loop only over documents, that id's e.g. start with 'mydoc' ???
Example-folder with the objects: mydoc1 mydoc35 picture567 picture33 mydoc98
So dtml-in shall only loop over 'mydoc1', 'mydoc35', 'mydoc98'
How can I do that?
TIA
Marc
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (5)
-
Breitenreicher, Marc -
Casey Duncan -
Milos Prudek -
Phil Harris -
Thomas B. Passin