[Zope3-Users] Re: Varying Default Value for Subschema (Object in
Tuple)
Derek Richardson
derek.richardson at gatech.edu
Mon Apr 30 12:20:07 EDT 2007
Derek Richardson wrote:
> I have a schema (the Tuple of Objects is the important part):
>
> class ISyndications(Interface):
> """Annotation that indicates the object can provide IFeed
> and that stores the current syndication configuration.
> """
>
> enabled = Bool(title=_(u'Enable syndication'),
> description=_(u'...'),
> default=False,
> )
>
> syndications = Tuple(title=_(u'Feeds'),
> description=_(u'...'),
> required=False,
> default=(),
> value_type=Object(title=_(u'Feed'),
> description=_(u'...'),
> schema=ISyndication,
> ),
> )
>
> def findSyndicationByLocalURL(url):
> """Find an ISyndication in syndications by the local URL it
> contains.
> """
>
> The subschema is (the UUID field is the important part):
>
> class ISyndication(Interface):
> """Configuration for an individual feed.
> """
>
> name = TextLine(title=_(u'Name'),
> description=_(u'...'),
> )
>
> format = Choice(title=_(u'Format'),
> description=_(u'Data format for this feed'),
> values=[u'atom', u'rss 1.0', u'rss 2.0'],
> )
>
> recurse = Bool(title=_(u'Recurse'),
> description=_(u'...'),
> default=False,
> )
>
> enabled = Bool(title=_(u'Enabled'),
> description=_(u'...'),
> default=True,
> )
>
> referring_URL = URI(title=_(u'URL'),
> description=_(u'...'),
> )
>
> local_URL = URI(title=_(u'Local URL'),
> description=_(u'...'),
> )
>
> UUID = TextLine(title=_(u'UUID'),
> description=_(u'UUID for this feed.'),
> required=False,
> readonly=True,
> )
>
> I want to populate the UUID upon creation from a function. So I tried
> this (the __init__ is the important part):
>
> class Syndication(persistent.Persistent):
> """See ISyndication
> """
>
> implements(ISyndication, IItemUUIDable)
>
>
> self.name = u''
> self.format = u''
> self.recurse = False
> self.enabled = False
> self.referring_URL = None
> self.local_URL = None
>
> def __init__(self):
> self.UUID = uuid1()
>
> However, the UUID field does not show up in the interface as initialized
> when I do:
>
> class SyndicationsEditForm(EditForm):
> """Edit form for syndications.
> """
>
> form_fields = Fields(ISyndications)
>
> ow = CustomWidgetFactory(ObjectWidget, Syndication)
> sw = CustomWidgetFactory(SequenceWidget, subwidget=ow)
> form_fields['syndications'].custom_widget = sw
> label = u'Configure syndications'
>
> This seems like it should be an easy thing to do. Who can tell me what
> I'm doing wrong?
>
> Thanks,
>
> Derek
The problem *may* stem from sequencewidget.py (lines 235-239 in Zope 3.3.1):
# add an entry to the list if the add button has been pressed
if self.name + ".add" in self.request.form:
# Should this be using self.context.value_type.missing_value
# instead of None?
sequence.append(None)
When I hack it just to prove a point, like so:
# add an entry to the list if the add button has been pressed
if self.name + ".add" in self.request.form:
# Should this be using self.context.value_type.missing_value
# instead of None?
from plone.syndication.syndication import Syndication
sequence.append(Syndication())
#sequence.append(None)
The UUID field gets populated.
But I'm not sure where to go with this. I don't see any bugs for SequenceWidget
on launchpad, so I'm still figuring I'm doing something wrong...
Derek
More information about the Zope3-users
mailing list