[Zope3-Users] How to get the icon for a content item.

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Dec 1 09:06:48 EST 2004


On Wednesday 01 December 2004 09:00, Tom Dossis wrote:
> Stephan Richter wrote:
> > On Tuesday 30 November 2004 23:23, Tom Dossis wrote:
> >>>How can I get the icon for a content object, e.g. Folder?
> >>>My ui is a gui, not a browser, but I'd like to use the zmi_icon (for
> >>>now).
> >>
> >>The following works, but is hackish..
> >>
> >> >>> root
> >>
> >><zope.app.folder.folder.Folder object at 0x4120c36c>
> >>
> >> >>> from zope.app import zapi
> >> >>> from zope.publisher.browser import TestRequest
> >> >>>
> >> >>> icon = zapi.queryView(root, 'zmi_icon', TestRequest())
> >> >>> icon
> >>
> >><zope.app.publisher.browser.icon.IconView object at 0x4117ea2c>
> >>
> >> >>> icon()
> >>
> >>u'<img
> >>src="http://127.0.0.1/@@/zope-app-folder-interfaces-IFolder-zmi_icon.gif"
> >>alt="Folder" width="16" height="16" border="0" />'
> >
> > What is hackish about that? It is exactely what I would have done. The
> > icon is just a view named zmi_icon.
>
> I meant hackish, by having to create a TestRequest.  Maybe I'm being
> pedantic.

Well, you should only need the icon when you are in a view and a view always 
has access to the request: self.request. It does not make sense to look up 
the icon outside of view code.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-users mailing list