[Zope3-Users] Varying Default Value for Subschema (Object in Tuple)

Derek Richardson derek.richardson at gatech.edu
Mon Apr 30 11:41:54 EDT 2007


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



More information about the Zope3-users mailing list