Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: Dev

Making PersistentList satisfy zope.schema.List

 

 

Zope dev RSS feed   Index | Next | Previous | View Threaded


paulcarduner at gmail

Jun 30, 2009, 12:17 PM

Post #1 of 3 (333 views)
Permalink
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?

--
Paul Carduner
http://www.carduner.net
_______________________________________________
Zope-Dev maillist - Zope-Dev[at]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 )


dev at projekt01

Jun 30, 2009, 2:04 PM

Post #2 of 3 (303 views)
Permalink
Re: Making PersistentList satisfy zope.schema.List [In reply to]

Hi Paul



> -----Ursprüngliche Nachricht-----
> Von: zope-dev-bounces[at]zope.org
> [mailto:zope-dev-bounces[at]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[at]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[at]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 )


agroszer at gmail

Jul 1, 2009, 1:26 AM

Post #3 of 3 (298 views)
Permalink
Re: Making PersistentList satisfy zope.schema.List [In reply to]

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 GROSZER mailto:agroszer[at]gmail.com
--
Quote of the day:
If you risk nothing, then you risk everything.
- Geena Davis

_______________________________________________
Zope-Dev maillist - Zope-Dev[at]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 RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.