Lets try this again - auto-creation
OK, since the last round seemed to be roundly ignored :-) Does anybody know of a way to create a ZClass object without entering an "ID"... I want the user to create an object, and the ID be "autocreated" (a random number, the date/time, whatever). I'll be accessing them through a ZCatalog searching on properties, creation date, etc. and don't care about the unique ID. Any suggestions? Thanks, Bruce -- Bruce C. Dillahunty Peachbush Enterprises bdillahu@mindspring.com
On Sat, 17 Jul 1999 16:22:25 -0400, "Bruce C. Dillahunty" <bdillahu@mindspring.com> said: Bruce> Does anybody know of a way to create a ZClass object without Bruce> entering an "ID"... I want the user to create an object, and the Bruce> ID be "autocreated" (a random number, the date/time, Bruce> whatever). I'll be accessing them through a ZCatalog searching on Bruce> properties, creation date, etc. and don't care about the unique Bruce> ID. Maybe you can use an external method that does something similar to what ZClass._new_class_id() does. This generates something like HM4tXUeVmZJNmNfBf2s4ew== from lib/python/ZClasses/ZClass.py: def _new_class_id(self): import md5, base64, time id=md5.new() id.update(self.absolute_url()) id.update(str(time.time())) id=id.digest() id=string.strip(base64.encodestring(id)) return '*'+id -- Alex Rice | alrice@swcp.com | http://www.swcp.com/~alrice Current Location: N. Rio Grande Bioregion, Southwestern USA
On Sat, 17 Jul 1999 16:22:25 -0400, "Bruce C. Dillahunty" <bdillahu@mindspring.com> said: Bruce> Does anybody know of a way to create a ZClass object without Bruce> entering an "ID"... I want the user to create an object, and the Bruce> ID be "autocreated" (a random number, the date/time, Bruce> whatever). I'll be accessing them through a ZCatalog searching on Bruce> properties, creation date, etc. and don't care about the unique Bruce> ID. Or maybe it's not the creation of a unique ID that's the problem, rather how to get the ZClass itself created with that ID? How about this? o Create ZClass "X" and choose yes to "Create Factory and add methods". o In your X_factory object, change Method from X_addForm to X_add. o In X_add (the constructor), make a change like this: <!--#with "X.createInObjectManager(_.str(_.whrandom.random()), REQUEST)"--> instead of <!--#with "X.createInObjectManager(REQUEST['id'], REQUEST)"--> _.str(_.whrandom.random()) could be an external method or whatever generates the unique ID (lava-rand!) Now when you create a ZClass X in Zope, a random number is selected as the ID, the object is created, but the user does not see the usual id entry form. -- Alex Rice | alrice@swcp.com | http://www.swcp.com/~alrice Current Location: N. Rio Grande Bioregion, Southwestern USA
participants (2)
-
Alex Rice -
Bruce C. Dillahunty