RE: [Modeling-users] Couple of questions...
Status: Abandoned
Brought to you by:
sbigaret
|
From: Aaron F. <afr...@em...> - 2004-04-21 17:49:11
|
First, thank you all for the fast and details replies; they are much
appreciated. ;-)
I've been playing around with the code that was posted, and while I still
don't have it working, it is getting closer.
First, I tried the Sebastien's code example (called extended.py here); this
is what I got:
jabartik extendedTest # python2.1 extended.py
Traceback (most recent call last):
File "extended.py", line 70, in ?
build(model, define_properties=1)
File "/usr/lib/python2.1/site-packages/Modeling/dynamic.py", line 168, in
build
add_properties(c, e)
File "/usr/lib/python2.1/site-packages/Modeling/dynamic.py", line 148, in
add_properties
prop=property(getattr(aClass, 'get'+part_func_name),
NameError: global name 'property' is not defined
I also tried loading (and tweaking for the added Publisher table) the
AuthorBooks example into the Zope ZModeler tool and then using it generate
the code skeletons and database schema; that worked just fine. I then tried
using these along with the code from Sebastien's example with the via the
python interpreter, which had some issues, as follows:
>>> from Modeling.EditingContext import EditingContext
>>> ec=EditingContext()
>>> from AuthorBooks.Publisher import Publisher
>>> from AuthorBooks.Writer import Writer
>>> from AuthorBooks.Book import Book
>>> p1=Publisher()
>>> p1.bizname="P1"
>>> ec.insert(p1)
>>> ec.saveChanges()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.1/site-packages/Modeling/EditingContext.py", line
737, in saveChanges
self.validateChanges()
File "/usr/lib/python2.1/site-packages/Modeling/EditingContext.py", line
765, in validateChanges
self.objectForGlobalID(gID).validateForSave()
File "/usr/lib/python2.1/site-packages/Modeling/CustomObject.py", line
595, in validateForSave
error.finalize()
File "/usr/lib/python2.1/site-packages/Modeling/Validation.py", line 145,
in finalize
if self._dict: raise self
Modeling.Validation.ValidationException: Validation for key
OBJECT_WIDE_VALIDATION failed:
- Validation of object <AuthorBooks.Publisher.Publisher instance at
0x849e07c> as a whole failed
Validation for key bizname failed:
- Key is required but value is void
After some scratching, I realized that the setBizname method in
Publisher.py, below, isn't getting called.
def setBizname(self, bizname):
"Change the Publisher / bizname attribute value"
self.willChange()
self._bizname = bizname
Doing a dir(p1) revealed:
>>> dir(p1)
['_CustomObject__editingContext', '_bizname', '_books', '_location',
'_v_classDescription', 'bizname']
So the 'bizname' attribute is getting appended and self._bizname = bizname
isn't getting called, which causes the insert to die since bizname is set to
non-null in the database. Manually forcing it with a p1._bizname="xyz" and
then doing an insert works fine.
So, the questions:
1) Based on some archived posts, I was under the impression that Modeling
core supports Python 2.1 (I am using 2.1.3 since this is leading up to a
Zope 2.6.4 product); is that still true?
2) Do I need the Modeling.dynamic module? This appears to require python
2.2, but if the classes are being generated via an XML file or the ZModeler
tool, this shouldn't be required, right?
At any rate, thanks again for your time and help.
-Aaron
|