[Grok-dev] Displaying an image stored on a grok.Model

Dirceu Pereira Tiegs dirceutiegs at gmail.com
Sun Jan 20 20:01:17 EST 2008


Hey,

I'm using z3c.widget.image with the following code:

import grok
from zope import interface, schema
from zope.app.file.interfaces import IImage
from z3c.widget.image.widget import ImageWidget

class z3cwidget_test(grok.Application, grok.Container):
    pass

class IEvent(interface.Interface):
    title = schema.TextLine(title=u"Title")
    image = schema.Object(title=u"Image", schema=IImage, required=False)

class Event(grok.Model):
    interface.implements(IEvent)

    def __init__(self, title, image=None):
        super(Event, self).__init__()
        self.title = title
        self.image = image

class AddEvent(grok.AddForm):
    form_fields = grok.AutoFields(Event)
    form_fields['image'].custom_widget = ImageWidget

    @grok.action('Add event')
    def add(self, **data):
        obj = Event(**data)
        name = data['title'].lower().replace(' ', '_')
        self.context[name] = obj

class Index(grok.DisplayForm):
    grok.context(Event)

It works, but I can't figure out how to show the image on a page
template. Any hints?

Cheers,
-- 
Dirceu Pereira Tiegs
Weimar Consultoria

Hospedagem Plone, Zope e Python
http://www.pytown.com


More information about the Grok-dev mailing list