RE: [Zope] Updating auto incrementing counter in a propertysheet
From: Bill Anderson [mailto:[EMAIL PROTECTED]] >Is it more important that they be in an order, or that they be in a >specific sequential list? Actually what is important is that they are integers and in a specific order. So the datestamp method isn't that feasible for me. (I'm trying to make a "fake tree" for a diskussion product.) It is really easy to implement and doesn't use recursion, so traversing the tree is done with a simple for loop. It uses a dictionary with tupples as keys to emulate the recursive structure. Simple example here if anybody cares. - class fakeTree: def __init__(self): #create tree and insert root element self.treeKeys = {} self.treeKeys[0] = (0,) self.tree = {} self.tree[(0,)] = '' def insert(self, id, parent, value): # create new key keyList = list(self.treeKeys[parent]) newKeyList = keyList.append(id) newKeyTuple = tuple(newKeyList) self.treeKeys[id] = newKeyTuple # insert in tree with new tuple key self.tree[newKeyTuple] = value def print(self): sortedKeys = treeKeys.keys() sortedKeys.sort() spacesInIndent = 3 for key in sortedKeys: print key print spacesInIndent * len(key) * ' ' + treeKeys[key] tree = fakeTree() tree.insert(1, 0, 'max m') tree.insert(2, 0, 'gitte') tree.insert(3, 1, 'magnus') tree.print() ___ Zope maillist - [EMAIL PROTECTED] 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 )
RE: [Zope] Updating auto incrementing counter in a propertysheet
From: Aleksander Salwa [mailto:[EMAIL PROTECTED]] >> >> >In the above line --- do you want to set up new value for ZClass property, >isn't it ? >If so, you have to use manage_changeProperties method of property sheet. Yes I am afraid that this is the problem. That seems like such a messy solution too. I will try and make a Python based product instead, for this particular solution. My current zClass solution allready seem to be a bit verbose for my liking. And the program logic isn't to nice in dtml either. Regards Max M ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Updating auto incrementing counter in a propertysheet
On Mon, 23 Oct 2000, Max Mřller Rasmussen wrote: > I have a zClass (objectmanger) with a property called "lastID", on a > propertysheet called "hidden". > > I have then written a dtml mehtod that should return the id incremented by 1 > and then sets the lastID to this new id. > > the dtml for the "newID()" dtml method looks like this: > -- > > In the above line --- do you want to set up new value for ZClass property, isn't it ? If so, you have to use manage_changeProperties method of property sheet. [EMAIL PROTECTED] /--\ | `long long long' is too long for GCC | \--/ ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Updating auto incrementing counter in a propertysheet
Max Møller Rasmussen wrote: > > What am I doing wrong here ... please !! > > I am trying to make an autoincrementing counter for use in a diskussion > forum. It's purpose is to autogenereate id's for new messages. > > It is important that the id's are in order, so I need to make them this way. Is it more important that they be in an order, or that they be in a specific sequential list? For example, an id based upon time stamp would indeed provide IDs that re orderable (thus handling the in order part). While a list od IDs named 1,2,3,4... is more like a 'linked list', where you know what follows and what precedes a given id. However, by using objectIds, you can obtian a list of ids in a given object (folder), and thus provide one for yourself, if needed. FTR, I have implemented both ways of doing it. I am leaning towards the timestamp as being more effective, & simpler. -- E PLURIBUS LINUX ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Updating auto incrementing counter in a propertysheet
[..] > When I try to get the property directly via the browser i get a result of > "1" The default value for lastID=0 to begin with so this sounds plausible, > but when I refresh the browser nothing happens. So I guess that lastID isn't > updated in the above code. I think this is a class - object problem. Each time you create an object based on your ZClass, the lastID becomes 0. Each object has its own lastID, rather than what you are expecting which is one instance of last id. My advice... download and install FSCounter from Zope.org (http://www.zope.org/Members/andym/FSCounter) Add an FSCounter, call it "Unique" and turn Cookie? to OFF (very important). This will generate and keep track of an incrementing value on the file system Then in your constructor add / change: That should work like a charm. ___ Zope maillist - [EMAIL PROTECTED] 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] Updating auto incrementing counter in a propertysheet
What am I doing wrong here ... please !! I am trying to make an autoincrementing counter for use in a diskussion forum. It's purpose is to autogenereate id's for new messages. It is important that the id's are in order, so I need to make them this way. I have a zClass (objectmanger) with a property called "lastID", on a propertysheet called "hidden". I have then written a dtml mehtod that should return the id incremented by 1 and then sets the lastID to this new id. the dtml for the "newID()" dtml method looks like this: -- -- When I try to get the property directly via the browser i get a result of "1" The default value for lastID=0 to begin with so this sounds plausible, but when I refresh the browser nothing happens. So I guess that lastID isn't updated in the above code. How do I do that? Also when I the try to insert "newID()" in my "mxm_comment_add" method in my zClass, to autogenerate numbers, like this: I get the following traceback: (And I would expect it to run at least 1 time with "1" as a new id.) Traceback (innermost last): File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 222, in publish_module File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 187, in publish File C:\mxmZope\lib\python\Zope\__init__.py, line 221, in zpublisher_exception_hook (Object: RoleManager) File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 171, in publish File C:\mxmZope\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: index_html) File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: index_html) File C:\mxmZope\lib\python\App\Factory.py, line 178, in index_html (Object: RoleManager) File C:\mxmZope\lib\python\OFS\DTMLMethod.py, line 172, in __call__ (Object: mxm_comment_add) File C:\mxmZope\lib\python\DocumentTemplate\DT_String.py, line 528, in __call__ (Object: mxm_comment_add) File C:\mxmZope\lib\python\DocumentTemplate\DT_With.py, line 133, in render (Object: mxm_comment.createInObjectManager(newID(), REQUEST)) File C:\mxmZope\lib\python\DocumentTemplate\DT_Util.py, line 337, in eval (Object: mxm_comment.createInObjectManager(newID(), REQUEST)) (Info: newID) File, line 0, in ? File C:\mxmZope\lib\python\OFS\DTMLMethod.py, line 168, in __call__ (Object: newID) File C:\mxmZope\lib\python\DocumentTemplate\DT_String.py, line 528, in __call__ (Object: newID) File C:\mxmZope\lib\python\DocumentTemplate\DT_Util.py, line 337, in eval (Object: REQUEST.set('new_id', lastID+1)) (Info: REQUEST) File , line 0, in ? NameError: (see above) ___ Zope maillist - [EMAIL PROTECTED] 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 )