dtml-tree: wrong branchesexpanded/collapsed
Hello List, I've a problem with dtml-tree. When I click on the first "plus sign" the branches may be expanded, or nothing may be happen or one of the other branches may be expanded. The same behaviour occurs with the attempt to collapse or expand the other branches. Dtml-code: <dtml-tree branches="getBranches"> branch: <dtml-var expr="__str__"> Product-code: class TestBranch: def __init__(self, str= "a"): self.str = str def getBranches(self): if not "x" in self.str: return [TestBranch(self.str + "x")] else: return None def __str__(self): return self.str def getBranches(self): return [TestBranch("a"), TestBranch("b"), TestBranch("c")] Do you have an idea, what I make wrong? Many thanks in advance, Ulla.
Ulla Theiss wrote at 2005-3-6 11:05 +0100:
I've a problem with dtml-tree. When I click on the first "plus sign" the branches may be expanded, or nothing may be happen or one of the other branches may be expanded. The same behaviour occurs with the attempt to collapse or expand the other branches.
"dtml-tree" needs persistent (!) ids to get expansion/collapsing right. It has an attribute with which you can control how the "id" is determined. In your case, it probably should be "str". -- Dieter
Hallo list, thank you for the helping. Now, I've derived my class TestBranch from "OFS.SimpleItem", which does have a method "getId()" and from "Persistent". The behaviour is much better and reproducible - but still not correct: Clicking on one plus-sign all the plus-signs of the chosen layer change to minus and are expanded, nevertheless the branch belongs to the chosen sign or not. In my example: I have the branches: a b c Clicking on a the branches of b and c are expanded, too. Do you have an idea, what I make wrong? Again, many thanks in advance, Ulla. Dieter Maurer wrote:
Ulla Theiss wrote at 2005-3-6 11:05 +0100:
I've a problem with dtml-tree. When I click on the first "plus sign" the branches may be expanded, or nothing may be happen or one of the other branches may be expanded. The same behaviour occurs with the attempt to collapse or expand the other branches.
"dtml-tree" needs persistent (!) ids to get expansion/collapsing right. It has an attribute with which you can control how the "id" is determined. In your case, it probably should be "str".
Ulla Theiss wrote at 2005-3-7 12:41 +0100:
Now, I've derived my class TestBranch from "OFS.SimpleItem", which does have a method "getId()" and from "Persistent". The behaviour is much better and reproducible - but still not correct: Clicking on one plus-sign all the plus-signs of the chosen layer change to minus and are expanded, nevertheless the branch belongs to the chosen sign or not.
Now, you should give your objects different ids and you are done... When you do not set the id, it is ''. And such an id is not differentiating (as you observe from your "dtml-tree"). -- Dieter
Hello List, thank you for the helping. I've tested the whole day along the ids and the behaviour is still the same. They are different. <dtml-var id> proofs. In the html-sourcecode I've seen 2 things: 1st: The Name of the Anchor is the same for each branch 2nd: The Href for all branches of one layer is exactly the same, but different from the other layers. Layer 1: <a name="Tm9uZQ==" href="show_html?tree-c=eJyLVneEAnf9ZFt1HQX1kFzL0qhAW1v1WABnawdT#Tm9uZQ=="> Layer 2: <a name="Tm9uZQ==" href="show_html?tree-e=eJyLVneEAnf9ZFt1HQX1kFzL0qhAW1R2LADSHgqB#Tm9uZQ=="> The dtml-code now looks like: <dtml-tree branches="getBranches"> branch: id: <dtml-var id> <dtml-var title_or_id> </dtml-tree> And the Product-Code: class StaticTestBranch(OFS.SimpleItem.Item, Persistent): def __init__(self, id, children): self.id = id self.children = children def getBranches(self): return self.children def getId(self): return self.id class tstProd . def getBranches(self): e1 = StaticTestBranch("e1", None) e2 = StaticTestBranch("e2", None) e3 = StaticTestBranch("e3", None) s1 = StaticTestBranch("s1", [e1, e2]) s2 = StaticTestBranch("s2", [e3]) v1 = StaticTestBranch("v1", [s1]) v2 = StaticTestBranch("v2", [s2]) branches = [v1, v2] return branches Do you have an idea, what I still make wrong? Again, many thanks in advance, Ulla. Dieter Maurer wrote:
Ulla Theiss wrote at 2005-3-7 12:41 +0100:
Now, I've derived my class TestBranch from "OFS.SimpleItem", which does have a method "getId()" and from "Persistent". The behaviour is much better and reproducible - but still not correct: Clicking on one plus-sign all the plus-signs of the chosen layer change to minus and are expanded, nevertheless the branch belongs to the chosen sign or not.
Now, you should give your objects different ids and you are done...
When you do not set the id, it is ''. And such an id is not differentiating (as you observe from your "dtml-tree").
Ulla Theiss wrote at 2005-3-8 22:06 +0100:
... I've tested the whole day along the ids and the behaviour is still the same. They are different. <dtml-var id> proofs. In the html-sourcecode I've seen 2 things: 1st: The Name of the Anchor is the same for each branch 2nd: The Href for all branches of one layer is exactly the same, but different from the other layers.
Maybe, you should switch from "dtml-tree" to a ZPT based solution? I often read recommendations for the "ZopeTree" product. I use the facilities provides by "ZTUtils" (and you can find an example use in the PageTemplates examples). But, when you want to stick with the complex "dtml-tree". Looking at the code in "TreeDisplay.TreeTag.Tree.__init__", I see that the default for id determination is the method "tpId". Apparently, "tpId" (or whatever you use as "id" attribute for "dtml-tree") return the same value for all siblings. -- Dieter
Hallo Dieter, again many thanks for helping. The thing with the tpId has exactly been the problem. Adding an attribute "tpId" to the class "TestBranch" with the same content as id everything works fine. Thank you, Ulla. Dieter Maurer wrote:
Ulla Theiss wrote at 2005-3-8 22:06 +0100:
... I've tested the whole day along the ids and the behaviour is still the same. They are different. <dtml-var id> proofs. In the html-sourcecode I've seen 2 things: 1st: The Name of the Anchor is the same for each branch 2nd: The Href for all branches of one layer is exactly the same, but different from the other layers.
Maybe, you should switch from "dtml-tree" to a ZPT based solution?
I often read recommendations for the "ZopeTree" product. I use the facilities provides by "ZTUtils" (and you can find an example use in the PageTemplates examples).
But, when you want to stick with the complex "dtml-tree".
Looking at the code in "TreeDisplay.TreeTag.Tree.__init__", I see that the default for id determination is the method "tpId".
Apparently, "tpId" (or whatever you use as "id" attribute for "dtml-tree") return the same value for all siblings.
participants (2)
-
Dieter Maurer -
Ulla Theiss