Hello all, I have a question about the dtml-in tag. When it is iterating over a sequence, and the items in the sequence happen to be tuples containing exactly two items, then dtml-in places the first item from the sequence in sequence-key, and the second item goes in sequence-item. If the items in the sequence are not tuples of two items, then sequence-item contains the whole item. For example, if I have: <dtml-in "[(1,2),(3,4),(5,6)]"> <dtml-var sequence-item> </dtml-in> then I get 2,4,6 when I view this. The 1, 3 and 5 have been assigned to sequence-key. Now, if I change the dtml to be this: <dtml-in "[(1,2,3),(3,4,5),(5,6,7)]"> <dtml-var sequence-item> </dtml-in> then I get (1,2,3)(3,4,5)(5,6,7) which is what I would expect. I think the reason for this behaviour is to do with iterating over dictionaries, but I'm not sure. The problem I have is this: I have code which retrieves data from a database, and the result is a list of tuples, with each tuple corresponding to a record, and each item in the tuple corresponding to a field. I don't know in advance how many fields will be in the record. I want to iterate over the records and fields, wrapping them in a html table. If the database I'm talking to happens to return a list of records with two fields, ie a tuple of two items, I have to handle this differently than any other case, which makes for some ugly code. I haven't been able to find any way to avoid this, unless I'm missing something. Any information would be greatly appreciated. Regards,
Sean McGrath wrote:
Hello all,
I have a question about the dtml-in tag. When it is iterating over a sequence, and the items in the sequence happen to be tuples containing exactly two items, then dtml-in places the first item from the sequence in sequence-key, and the second item goes in sequence-item. If the items in the sequence are not tuples of two items, then sequence-item contains the whole item. For example, if I have:
<dtml-in "[(1,2),(3,4),(5,6)]"> <dtml-var sequence-item> </dtml-in>
then I get 2,4,6 when I view this. The 1, 3 and 5 have been assigned to sequence-key. Now, if I change the dtml to be this:
<dtml-in "[(1,2,3),(3,4,5),(5,6,7)]"> <dtml-var sequence-item> </dtml-in>
then I get (1,2,3)(3,4,5)(5,6,7)
which is what I would expect. I think the reason for this behaviour is to do with iterating over dictionaries, but I'm not sure. The problem I have is this: I have code which retrieves data from a database, and the result is a list of tuples, with each tuple corresponding to a record, and each item in the tuple corresponding to a field. I don't know in advance how many fields will be in the record. I want to iterate over the records and fields, wrapping them in a html table. If the database I'm talking to happens to return a list of records with two fields, ie a tuple of two items, I have to handle this differently than any other case, which makes for some ugly code. I haven't been able to find any way to avoid this, unless I'm missing something. Any information would be greatly appreciated.
Regards,
in addition to Dieter Maurer's suggestion of fixing this behavior in dtml-in, another possibility is to do the work in a web python method, and directly access the Result object from the query to generate the html. Result object api. /lib/python/Shared/DC/ZRDB/Result.py
I have a ZClass based on OFS:File. The problem is that I can't paste a instance of that class except that I am a "Manager". In other roles, I get a error message which says that that object(instance of my ZClass) doesn't support the paste operation. The work-around is: to set the proxy role of a wrapper DTML-method ( which calls manage_pasteObjects) to be "Manager". I think this work-around gives too much permissions. It implies that user can paste everywhere, doesn't it? My question : is there any better way or probably right way to do the same thing? ( I have tried to check all permissions for that role in context, well, it doesn't work) Thanks. Yap, Singuan
participants (3)
-
Ender -
iap_y2fun.com -
Sean McGrath