Re: [Zope-dev] Making PersistentList satisfy zope.schema.List

2009-07-01 Thread Adam GROSZER
Hello,

I think then it's the widgets bad behavour.
It should do a

``newValue = previousValue.__class__(newItems)``

instead of a dumb

``newValue = list(newItems)``

(Where available of course)
The problem is when the previousValue is None so we can't determine
the the type.

Tuesday, June 30, 2009, 11:04:49 PM, you wrote:


RI I think it's different. If you use a zope.schem.List field
RI the widgets will store the list at once. This whould replace
RI the initial created PeristentList. (or not?)

RI In general if you store a simple list as attribute on a 
RI persistent class it's fine, everything is stored.

RI If you like to append or pop from this list, then yes, you
RI will need a PersistentList otherwise the changes in the 
RI list are not stored back to the DB. (right?)

RI Fazit,
RI the zope.schema.List field and the Sequence widget
RI is not compatible with initial PersitentList beause
RI the widget will probably replace the list with a
RI simple list.

RI Note, I'm not 100% sure if I'm correct. But it is at
RI least something which we have to make sure that this
RI is working.


-- 
Best regards,
 Adam GROSZERmailto:agros...@gmail.com
--
Quote of the day:
If you risk nothing, then you risk everything. 
- Geena Davis 

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Making PersistentList satisfy zope.schema.List

2009-06-30 Thread Roger Ineichen
Hi Paul

  

 -Ursprüngliche Nachricht-
 Von: zope-dev-boun...@zope.org 
 [mailto:zope-dev-boun...@zope.org] Im Auftrag von Paul Carduner
 Gesendet: Dienstag, 30. Juni 2009 21:18
 An: zope-dev
 Betreff: [Zope-dev] Making PersistentList satisfy zope.schema.List
 
 I noticed that PersistentList and PersistentDict do not 
 satisfy zope.schema.List or zope.schema.Dict, which is rather 
 annoying.  For
 example:
 
 class IBlogPost(Interface):
 tags = zope.schema.List(title=u'Tags', 
 value_type=zope.schema.TextLine)
 
 class BlogPost(Persistent):
 implements(IBlogPost)
 
 tags = FieldProperty(IBlogPost['tags'])
 
 def __init__(self):
 super(BlogPost, self).__init__()
 self.tags = persistent.list.PersistentList() #aaah, 
 WrongType error...

 will throw a WrongType: ([], type 'list') error, which is 
 especially confusing because the repr for PersistentList 
 makes it look an awful lot like a regular list.
 
 same thing happens with PersistentDict.
 
 I would like to modify zope.schema._bootstrapfields by 
 changing the _type attribute of the List class to (list, 
 UserList), and do the same for Dict with (dict, UserDict).  
 Then anything inheriting from UserList (including 
 PersistentList) will satisfy the schema.
 
 Can anyone think of a reason why this would be bad?

I think it's different. If you use a zope.schem.List field
the widgets will store the list at once. This whould replace
the initial created PeristentList. (or not?)

In general if you store a simple list as attribute on a 
persistent class it's fine, everything is stored.

If you like to append or pop from this list, then yes, you
will need a PersistentList otherwise the changes in the 
list are not stored back to the DB. (right?)

Fazit,
the zope.schema.List field and the Sequence widget
is not compatible with initial PersitentList beause
the widget will probably replace the list with a
simple list.

Note, I'm not 100% sure if I'm correct. But it is at
least something which we have to make sure that this
is working.

Regards
Roger Ineichen
 
 --
 Paul Carduner
 http://www.carduner.net
 ___
 Zope-Dev maillist  -  Zope-Dev@zope.org
 http://mail.zope.org/mailman/listinfo/zope-dev
 **  No cross posts or HTML encoding!  ** (Related lists -  
 http://mail.zope.org/mailman/listinfo/zope-announce
  http://mail.zope.org/mailman/listinfo/zope )
 

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )