some Zope issues: dtml-zpt, permissions, scalability
Dear Zopers During the last few weeks I have been working through the documentation of Zope for building my own products. One valuable source was the Zope Bible. With help from this list and the authors of the book I decided to go for a file system based product using ZPT. Unfortunately, the example in the book is using DTML like most others still do. When trying to convert from DTML to ZPT I found the following problem: It is easy to change dtml-in to tal:repeat and the like. But how to convert from dtml-call to tal? Look at the folowing snippet: -------------------------------------------------------------------------------- <dtml-unless SelectedGroup> <dtml-call "REQUEST.set('SelectedGroup', 'All')"> </dtml-unless> <dtml-unless start> <dtml-call "REQUEST.set('start', 1)"> </dtml-unless> <dtml-unless sort_by> <dtml-call "REQUEST.set('sort_by', 'LastName,FirstName,MiddleInitial')"> </dtml-unless> -------------------------------------------------------------------------------- Another problem occurs with permissions. The following snippet works in dtml, but when converted to zpt (accessing here/listEntriesByGroup) the same method cannot be accessed any longer. -------------------------------------------------------------------------------- <dtml-in "listEntriesByGroup(_['SelectedGroup'])" size=20 start=start sort_expr="sort_by"> <tr <dtml-if sequence-even>bgcolor="#CCCCCC"</dtml-if>> <td><input type=checkbox name="EntryIDs:list" value="&dtml-id;"></td> <td><a href="&dtml-id;"><dtml-var title></td> <td><dtml-var Title> </td> <td><dtml-var Company> </td> <td><a href="<dtml-var id>/editEntryForm">Edit</a></td> </tr> </dtml-in> -------------------------------------------------------------------------------- Yet another issue is related to scalability when I have an object that references a list of other objects using a dictionary. How does this perform when the dictionary contains 10.000 or 50.000 entries? Is that feasible or are there better solutions? thanks a lot for your help Andre
Hi I think this will help http://old.zope.org/Members/peterbe/DTML2ZPT/index_html?pp=1 dragos ----- Original Message ----- From: Andre Meyer To: zope@zope.org Cc: webmaven@cox.net Sent: Thursday, November 20, 2003 9:53 AM Subject: [Zope] some Zope issues: dtml-zpt, permissions, scalability Dear Zopers During the last few weeks I have been working through the documentation of Zope for building my own products. One valuable source was the Zope Bible. With help from this list and the authors of the book I decided to go for a file system based product using ZPT. Unfortunately, the example in the book is using DTML like most others still do. When trying to convert from DTML to ZPT I found the following problem: It is easy to change dtml-in to tal:repeat and the like. But how to convert from dtml-call to tal? Look at the folowing snippet: ------------------------------------------------------------------------------ <dtml-unless SelectedGroup> <dtml-call "REQUEST.set('SelectedGroup', 'All')"> </dtml-unless> <dtml-unless start> <dtml-call "REQUEST.set('start', 1)"> </dtml-unless> <dtml-unless sort_by> <dtml-call "REQUEST.set('sort_by', 'LastName,FirstName,MiddleInitial')"> </dtml-unless> ------------------------------------------------------------------------------ Another problem occurs with permissions. The following snippet works in dtml, but when converted to zpt (accessing here/listEntriesByGroup) the same method cannot be accessed any longer. ------------------------------------------------------------------------------ <dtml-in "listEntriesByGroup(_['SelectedGroup'])" size=20 start=start sort_expr="sort_by"> <tr <dtml-if sequence-even>bgcolor="#CCCCCC"</dtml-if>> <td><input type=checkbox name="EntryIDs:list" value="&dtml-id;"></td> <td><a href="&dtml-id;"><dtml-var title></td> <td><dtml-var Title> </td> <td><dtml-var Company> </td> <td><a href="<dtml-var id>/editEntryForm">Edit</a></td> </tr> </dtml-in> ------------------------------------------------------------------------------ Yet another issue is related to scalability when I have an object that references a list of other objects using a dictionary. How does this perform when the dictionary contains 10.000 or 50.000 entries? Is that feasible or are there better solutions? thanks a lot for your help Andre ------------------------------------------------------------------------------ _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Thu, Nov 20, 2003 at 08:53:09AM +0100, Andre Meyer wrote:
Dear Zopers
During the last few weeks I have been working through the documentation of Zope for building my own products. One valuable source was the Zope Bible. With help from this list and the authors of the book I decided to go for a file system based product using ZPT. Unfortunately, the example in the book is using DTML like most others still do. When trying to convert from DTML to ZPT I found the following problem: It is easy to change dtml-in to tal:repeat and the like. But how to convert from dtml-call to tal? Look at the folowing snippet:
--------------------------------------------------------------------------------
<dtml-unless SelectedGroup> <dtml-call "REQUEST.set('SelectedGroup', 'All')"> </dtml-unless>
As Dragos said, you don't need REQUEST.set() to achieve this, just use tal:define in the appropriate enclosing tag. But in general, if you need to call something without displaying the results, there is no equivalent to dtml-call so we just use tal:define with a dummy name, like so: <span tal:define="dummy python:some_method(arg=foo)"> </span>
Another problem occurs with permissions. The following snippet works in dtml, but when converted to zpt (accessing here/listEntriesByGroup) the same method cannot be accessed any longer.
--------------------------------------------------------------------------------
<dtml-in "listEntriesByGroup(_['SelectedGroup'])" size=20 start=start sort_expr="sort_by"> <tr <dtml-if sequence-even>bgcolor="#CCCCCC"</dtml-if>> <td><input type=checkbox name="EntryIDs:list" value="&dtml-id;"></td> <td><a href="&dtml-id;"><dtml-var title></td> <td><dtml-var Title> </td> <td><dtml-var Company> </td> <td><a href="<dtml-var id>/editEntryForm">Edit</a></td> </tr> </dtml-in>
--------------------------------------------------------------------------------
That seems unlikely. Can you post your ZPT version, and the actual error it gives you?
Yet another issue is related to scalability when I have an object that references a list of other objects using a dictionary. How does this perform when the dictionary contains 10.000 or 50.000 entries? Is that feasible or are there better solutions?
Dictionaries are quite fast and scale pretty well. 50,000 is not too many. But there might be performance issues, depending on how & how often this dictionary is generated; whether it is stored as part of a persistent object; and what its values are (paths? object references? what?); and how many of them you have. -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's CAKE MEGA! (random hero from isometric.spaceninja.com)
Andre Meyer wrote:
Another problem occurs with permissions. The following snippet works in dtml, but when converted to zpt (accessing here/listEntriesByGroup) the same method cannot be accessed any longer.
Soon after writing the 'Zope Bible', but before it was published, I discovered that PageTemplateFile instances were restricted code, unlike DTMLFile instances. The relevant thread starts here: http://mail.zope.org/pipermail/zpt/2002-February/002856.html To fix the problems you're having in converting the Addressit product to ZPTs, you'll simply need to add the appropriate security assertions to the relevant methods. I believe you'll also need to grant access to some class attributes (or else expose them via accessor methods). Read the whole thread referenced above, it should give you all the information you need.
Yet another issue is related to scalability when I have an object that references a list of other objects using a *dictionary*. How does this perform when the dictionary contains 10.000 or 50.000 entries? Is that feasible or are there better solutions?
The dictionary based approach is *not* truly scalable, instead you can replace the dictionary with a BTree, which gives you the same access-by-key interface as a dict, but doesn't suffer from the same problems as a dictionary. Information about using BTrees can be found here: http://zope.org/Members/ajung/BTrees/DataTypes/FrontPage The most critical difference in using a BTree is that you cannot simply use assignment such as self.Entries[id] = entry But will instead have to use the Btree's insert method, like this: self.Entries.insert(id, entry) I may have forgotten some other minor changes. If so, I apologize. I hope this information is helpful to you, - Michael R. Bernstein michaelbernstein.com Author of Zope Bible
Michael Bernstein wrote at 2003-11-25 13:00 -0800:
... The most critical difference in using a BTree is that you cannot simply use assignment such as
self.Entries[id] = entry
This is not true as you can see from this transcript. linux: python Python 2.1.3 (#2, Mar 13 2003, 13:39:51)
from BTrees.OOBTree import OOBTree t=OOBTree() t[1]=2 t[1] 2
"BTrees" behave much like dictionaries. Essential differences are for the "keys", "values" and "items" methods: unlike as for dictionaries their return values are "life"; they change when the tree is changed. This can lead to very strange effects, e.g. in code like for k in tree.keys(): ... tree[k] = ... tree[l] = ... del tree[m] Use the "tuple(tree.keys())" idiom when you plan to modify the tree while using the "keys()" result (same for friends, of course). Another essential note: determining the length of a tree (or "keys()" and friends) is expensive (linear in the length). -- Dieter
On Wed, 2003-11-26 at 11:41, Dieter Maurer wrote:
Michael Bernstein wrote at 2003-11-25 13:00 -0800:
... The most critical difference in using a BTree is that you cannot simply use assignment such as
self.Entries[id] = entry
This is not true as you can see from this transcript.
Michael was probably thinking of IISet/OOSet objects, which *do* use an obj.insert() and obj.remove() interface instead of __setitem__ and __delitem__. HTH, Dylan
Dylan Reinhardt wrote:
On Wed, 2003-11-26 at 11:41, Dieter Maurer wrote:
Michael Bernstein wrote at 2003-11-25 13:00 -0800:
... The most critical difference in using a BTree is that you cannot simply use assignment such as
self.Entries[id] = entry
This is not true as you can see from this transcript.
Michael was probably thinking of IISet/OOSet objects, which *do* use an obj.insert() and obj.remove() interface instead of __setitem__ and __delitem__.
Maybe. I'm not sure where I picked up that odd notion. Guess I'll have to put it down to old age. - Michael
participants (6)
-
Andre Meyer -
Dieter Maurer -
Dragos Chirila -
Dylan Reinhardt -
Michael Bernstein -
Paul Winkler