[Grok-dev] Entity Relations and Forms
Jeroen Michiel
jmichiel at yahoo.com
Tue Jan 20 10:56:53 EST 2009
Martijn Faassen-2 wrote:
>
> I think the best library to look at is zc.sourcefactory:
>
> http://pypi.python.org/pypi/zc.sourcefactory/
>
> you can include this as a dependency in your project's setup.py. Perhaps
> you may want to lock it down to a particular version in a [versions]
> list in buildout.cfg as well.
>
> You'd use it something like this:
>
> class IFoo(Interface):
> contributor = schema.Choice(
> title=u'object',
> required=True,
> source=ContributorSource())
>
> Off the top of my head, your ContributorSource could be implemented
> something like this:
>
> class ContributorSource(BasicSourceFactory):
> def getValues(self):
> # assuming 'contributors' is a subfolder in your site...
> return grok.getSite()['contributors'].values()
>
> def getTitle(self, value):
> return value.name_attributge_of_contributor
>
>
I'm trying to get something similar, but as soon as I go to a form using the
schema, I get an error:
ComponentLookupError: ((<zc.sourcefactory.source.FactoredSource object at
0x0259BE10>, <zope.publisher.browser.BrowserRequest instance
URL=http://localhost
:8080/arts/candidates/add>), <InterfaceClass
zope.app.form.browser.interfaces.ITerms>, u'')
Seems like he's looking for a ITerms implementation, but can't find one...
What's missing?
This is my code:
class TargetSource(zc.sourcefactory.basic.BasicSourceFactory):
def getValues(self):
return grok.getSite()['targets'].values()
def getTitle(self, value):
return value.name
class ICandidate(Interface):
target = schema.Choice(source=TargetSource(), title=u'Target',
description=u'The Target file this Candidate can be matched to')
--
View this message in context: http://www.nabble.com/Entity-Relations-and-Forms-tp19014121p21565938.html
Sent from the Grok mailing list archive at Nabble.com.
More information about the Grok-dev
mailing list