Re: [Zope] Problem Creating Instances Mysteriously Solved
I spent some time this afternoon after my last post on this topic messaging back and forth with my friend and colleague Kevin Altis of PythonCard fame. I think I understand better now how to proceed with this project, at least *one* way to proceed better. I was making the classic programming error of letting implementation drive design. I don't *need* objects here. I can store all of the data I need stored in standard Zope objects and then use Python and DTML to manipulate their contents. I had allowed myself to become convinced that to "create a new clearing" of necessity meant creating a new clearing *object*. But a Clearing could be a structured document (XML), a collection of SQL database records or, as it turns out after only a little experimentation on my part, a collection of folderish Zope objects and documents manipulated directly through DTML (setting properties, etc.) IOW, no need for custom classes, just extend the built-in classes via properties which can be set in DTML methods and Python scripts. This is clearly no less OO than my original approach, but it will be several orders of magnitude easier to write and maintain. I'll probably finish this project now in about 10%of the time I've already spent just trying to get ZClasses working to my satisfaction. Lesson learned. If it seems too hard, it probably is. Thanks to Chris Weathers, Dieter Maurer, and others on this list for their help and insights. This is a fantastic community demonstrating once again why Zope rules.
Dan Shafer wrote:
Clearing could be a structured document (XML), a collection of SQL database records or, as it turns out after only a little experimentation on my part, a collection of folderish Zope objects and documents manipulated directly through DTML (setting properties, etc.)
No! *slap* *slap* Dammit! Snap out of it! ;-) DTML is evil. Especially when used for manipulating things. DTML should _only_ ever be used for presentation, althought I'd recommend ZPT for that. Use Python in the form of Script (Python)'s when you need to manipulate things...
IOW, no need for custom classes, just extend the built-in classes via properties which can be set in DTML methods and Python scripts.
tada! :-)
This is clearly no less OO than my original approach, but it will be several orders of magnitude easier to write and maintain. I'll probably finish this project now in about 10%of the time I've already spent just trying to get ZClasses working to my satisfaction.
Lesson learned. If it seems too hard, it probably is.
tada! (II)
Thanks to Chris Weathers,
*sigh* Withers, not Whithers, certainly not Weathers... Pretty please? :-) Seriously though, I'm glad things are looking up. So many problems are merely the outlook you bring to them... good luck, Chris (Withers ;-)
At 11:24 PM 4/20/2002 +0100, Chris Withers wrote:
Dan Shafer wrote:
Clearing could be a structured document (XML), a collection of SQL database records or, as it turns out after only a little experimentation on my part, a collection of folderish Zope objects and documents manipulated directly through DTML (setting properties, etc.)
No! *slap* *slap* Dammit! Snap out of it! ;-)
DTML is evil. Especially when used for manipulating things. DTML should _only_ ever be used for presentation, althought I'd recommend ZPT for that.
Use Python in the form of Script (Python)'s when you need to manipulate things...
LOL. OK,OK, I get it. Especially when I look and look and look and I can't see how to set custom-defined properties for an existing DTML Document object. It *appears* I have to create the DTML document in a script, then use the manage_addProperties function to add properties and assign values. Feels a tad indirect but I don't see property setters and getters. And while I have everyone's attention, is there a property to set for the *contents* of a DTMLDocument object?
Thanks to Chris Weathers,
*sigh* Withers, not Whithers, certainly not Weathers...
Pretty please? :-)
Yeesh. I even looked directly at your name and then typed it wrong. Explains a lot about why my code doesn't work, eh? :-(
Seriously though, I'm glad things are looking up. So many problems are merely the outlook you bring to them...
good luck,
Thanks. I'm getting closer. I think.
Chris (Withers ;-)
Dan Shafer wrote:
LOL. OK,OK, I get it. Especially when I look and look and look and I can't see how to set custom-defined properties for an existing DTML Document object. It *appears* I have to create the DTML document in a script, then use the manage_addProperties function to add properties and assign values. Feels a tad indirect but I don't see property setters and getters.
Yeah, properties could have nicer interfaces... Here's a little loop I use in my edit methods when only string properties are used, assuming a form has been submitted that contains the properties you want to set the values of: REQUEST = context.REQUEST for name in ['my_prop1','my_prop2']: update = {} value = REQUEST.get(name,'') if context.hasProperty(name): update[name]=value else: context.manage_addProperty(name,value,'string') apply(context.manage_changeProperties,(),update) cheers, Chris
Chris..... Thanks for the big boost. I was part way down that curve but it would have taken me a long time to get as far as your code propelled me! You are awesome. At 10:02 AM 4/21/2002 +0100, Chris Withers wrote:
Dan Shafer wrote:
LOL. OK,OK, I get it. Especially when I look and look and look and I can't see how to set custom-defined properties for an existing DTML Document object. It *appears* I have to create the DTML document in a script, then use the manage_addProperties function to add properties and assign values. Feels a tad indirect but I don't see property setters and getters.
Yeah, properties could have nicer interfaces...
Here's a little loop I use in my edit methods when only string properties are used, assuming a form has been submitted that contains the properties you want to set the values of:
REQUEST = context.REQUEST for name in ['my_prop1','my_prop2']: update = {} value = REQUEST.get(name,'') if context.hasProperty(name): update[name]=value else: context.manage_addProperty(name,value,'string') apply(context.manage_changeProperties,(),update)
cheers,
Chris
Dan Shafer wrote:
Chris.....
Thanks for the big boost. I was part way down that curve but it would have taken me a long time to get as far as your code propelled me!
No worries :-)
You are awesome.
Uhuh, not always... see mailing list archives... *grinz* Chris
participants (2)
-
Chris Withers -
Dan Shafer