[z3-five] FieldProperty, acquisition and Zope 2

Martin Aspeli optilude at gmx.net
Sat Feb 24 04:19:20 CET 2007


Hi all,

I was using FieldProperty in something like this:

class ITask(Interface):
      assigned_to = schema.Choice(title=_(u"Assigned to"),
                                  vocabulary="assignees")

The assignees vocabulary is defined as such:

def assigneeVocabularyFactory(context):
      """Get possible assignees from the immediate parent project
      """
      team = ()
      parent = context
      while parent is not None and not team:
          project = IProject(parent, None)
          if project is not None:
              team = project.team
          else:
              parent = aq_parent(parent)
      return SimpleVocabulary.fromValues(team)
alsoProvides(assigneeVocabularyFactory, IVocabularyFactory)

I then have a class which uses a FieldProperty:

class Task(SimpleItem):
      implements(ITask)
      assigned_to = FieldProperty(IDeliverable['assigned_to'])

I've got an add form which uses form.applyChanges(task,
self.form_fields, data)

Now, this fails horribly, miserably and deep-deep inside zope.schema or
thereabouts. To be honest, the traceback is pretty useless, but I've
worked out that the error occurs because FieldProperty is a property,
with __get__() and __set__() methods, and as soon as I go there, the
task loses its acquisition context.

Now, http://zope.org/Collectors/Zope/2163 tells me that we can't have
acquisition inside property accessors.

I'm wondering, though, if we have other options? Could Five provide
something similar to FieldProperty but which is acquisition-aware?

Martin



More information about the z3-five mailing list