[Grok-dev] problems using zc.sourcefactory (was: Re: Adding a image
to form_fields)
Jan Ulrich Hasecke
janulrich.hasecke at web.de
Mon Sep 3 07:08:17 EDT 2007
Hi,
Am 30.08.2007 um 11:45 schrieb Christian Theune:
> Notice that zc.sourcefactory makes writing sources much easier:
>
> class AnimalImageSource(zc.sourcefactory.basic.BasicSourceFactory):
>
> base = os.path.join(os.path.dirname(__file__), 'static')
>
> def getValues(self):
> return glob.glob(self.base, '*.jpg'))
>
> def getTitle(self, value):
> file = open(os.path.join(self.base, value))
> return <magic metadata extraction happens>(file).title
> images>.
>
> In your form_fields you can then use:
>
> Choice(title=..., source=AnimalImageSource())
>
after finally solving the problem to install zc.sourcefactory in grok
I have made this:
---zoo.py
from zc.sourcefactory.basic import BasicSourceFactory
class GehegeListe(BasicSourceFactory):
def getValues(self):
return [u'Elefantengehege', u'Giraffengehege', u'Paviankäfig']
class GehegeBauen(grok.AddForm):
"""The view to add a cage"""
grok.context(GrokZoo)
grok.name('gehegebauen')
form_fields = grok.Fields(
name=Choice(title=u'Gehege', source=GehegeListe()),
groesse=Int(title=u"Wieviele Tiere sollen Platz haben?"))
label= u'Neues Gehege bauen'
@grok.action('Gehege bauen')
def add(self,name, groesse=8):
if name in self.context.keys():
return
self.redirect(self.url('index'))
self.context.bauegehege(name, groesse, tierart='default', kosten=100)
self.redirect(self.url('index'))
After restarting grok and accessing the page gehegebauen I get a
ComponentLookupError
------
2007-09-03T13:03:09 ERROR SiteError http://localhost:8080/
NeanderthalerZoo/gehegebauen
Traceback (most recent call last):
File "/Users/juh/buildout-eggs/tmpUA_NJV/
zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/
publish.py", line 133, in publish
File "/Users/juh/buildout-eggs/grok-0.10-py2.4.egg/grok/
publication.py", line 41, in callObject
return super(ZopePublicationSansProxy, self).callObject(request,
ob)
File "/Users/juh/buildout-eggs/tmpqj7CcV/
zope.app.publication-3.4.0a1_2-py2.4.egg/zope/app/publication/
zopepublication.py", line 167, in callObject
File "/Users/juh/buildout-eggs/tmpUA_NJV/
zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/
publish.py", line 108, in mapply
- __traceback_info__: <grokzoo.zoo.GehegeBauen object at 0x386a430>
File "/Users/juh/buildout-eggs/tmpUA_NJV/
zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/
publish.py", line 114, in debug_call
File "/Users/juh/buildout-eggs/grok-0.10-py2.4.egg/grok/
components.py", line 386, in __call__
self.update_form()
File "/Users/juh/buildout-eggs/grok-0.10-py2.4.egg/grok/
components.py", line 358, in update_form
super(GrokForm, self).update()
File "/Users/juh/buildout-eggs/tmpMNReCS/zope.formlib-3.4.0a1-
py2.4.egg/zope/formlib/form.py", line 736, in update
File "/Users/juh/buildout-eggs/tmpMNReCS/zope.formlib-3.4.0a1-
py2.4.egg/zope/formlib/form.py", line 717, in setUpWidgets
File "/Users/juh/buildout-eggs/tmpMNReCS/zope.formlib-3.4.0a1-
py2.4.egg/zope/formlib/form.py", line 278, in setUpWidgets
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/_api.py", line 101, in getMultiAdapter
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/_api.py", line 114, in queryMultiAdapter
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/registry.py", line 206, in queryMultiAdapter
File "/Users/juh/buildout-eggs/tmpP7VVO8/zope.interface-3.4.0-
py2.4-macosx-10.3-ppc.egg/zope/interface/adapter.py", line 482, in
queryMultiAdapter
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/zcml.py", line 151, in factory
File "/Users/juh/buildout-eggs/tmpsTSVzh/
zope.app.form-3.4.0b2.dev_r77626-py2.4.egg/zope/app/form/browser/
itemswidgets.py", line 43, in ChoiceInputWidget
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/_api.py", line 101, in getMultiAdapter
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/_api.py", line 114, in queryMultiAdapter
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/registry.py", line 206, in queryMultiAdapter
File "/Users/juh/buildout-eggs/tmpP7VVO8/zope.interface-3.4.0-
py2.4-macosx-10.3-ppc.egg/zope/interface/adapter.py", line 482, in
queryMultiAdapter
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/zcml.py", line 151, in factory
File "/Users/juh/buildout-eggs/tmpsTSVzh/
zope.app.form-3.4.0b2.dev_r77626-py2.4.egg/zope/app/form/browser/
source.py", line 553, in __init__
File "/Users/juh/buildout-eggs/tmpsTSVzh/
zope.app.form-3.4.0b2.dev_r77626-py2.4.egg/zope/app/form/browser/
source.py", line 528, in __init__
File "/Users/juh/buildout-eggs/tmpbRVUh2/zope.component-3.4.0a1-
py2.4.egg/zope/component/_api.py", line 103, in getMultiAdapter
ComponentLookupError: ((<zc.sourcefactory.source.FactoredSource
object at 0x3245c30>, <zope.publisher.browser.BrowserRequest instance
URL=http://localhost:8080/NeanderthalerZoo/gehegebauen>),
<InterfaceClass zope.app.form.browser.interfaces.ITerms>, u'')
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: Signierter Teil der Nachricht
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20070903/c272979c/PGP-0001.bin
More information about the Grok-dev
mailing list