Hi, On Mon, Sep 24, 2007 at 06:53:58PM +0200, Maken Seteva wrote: > Fellow Zopers. > I have made a slight modification to my intid util by inheriting from IntId > and overriding > _generateId(). > I do this to be sure that all new created objects will have an incrementing > number where > the first object created gets id 1, the next gets id 2 and so on. This way I > get for "free" > sorting by > oldest/newest. > > > class MyIntIds(IntId): > # We need a non-volatile nextid > nextid = None > > def _generateId(self): > # In the unlikely event that the nextid already > # exists, we run this in a while loop to fix it. > while True: > if len(self) == 0: > self.nextid = 1 > elif self.nextid is None: > self.nextid = self.refs.maxKey() + 1 > uid = self.nextid > self.nextid += 1 > if uid not in self.refs: > return uid > # Normally we would never get here.. > self.nextid = None > > > What do you think about this? Is it "safe" to do this, or have i forgotten > any unforseen oddities > that might occur in the future :O
I'm using a modified IntId utility which starts IDs at 1 and counts upwards, too. I needed some permanent link for each object which was easy to implement via IntId. The modification was made to safe keystrokes when typing the permalink. Typing http://server/~251 is a lot easier than http://server/~344357462 :-) . However, I don't use those IDs for anything else - like sorting. Regards, Frank _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users