I've a template which shows some details.I want to get an image to template from a method.How to do that?
def get_image(self):
<-- ##### -->
return img
I've a template which shows some details.I want to get an image to template from a method.How to do that?
def get_image(self):
<-- ##### -->
return img
No idea what you are trying to accomplish (lack of details). A resource an Image object can be referenced through its URL, same as in HTML.
actually my current task is to show the current user's name and and portrait img in avatar.
@zopyx My method
def get_portrait_url(self):
super(ToolbarViewletManager,self).get_portrait_url()
member_tool = api.portal.get_tool('portal_membership')
user = api.user.get_current()
user_id = user.id
portrait = member_tool.getPersonalPortrait(id=user_id)
return portrait
How will its template looks like? <img src=""'/>
If the method returns a URL the template will look like this:
<img src="${view/get_portrait_url}">
In one project I have the following method so you probably miss the call to absolute_url method aswell:
def get_user_portrait(self):
portal_membership = api.portal.get_tool('portal_membership')
portrait = portal_membership.getPersonalPortrait(self.user_id).absolute_url()
return portrait
If you are trying to override the toolbar viewlet manager check this documentation:
While overriding the viewlet manager
Traceback (innermost last):
Module ZPublisher.WSGIPublisher, line 176, in transaction_pubevents
Module ZPublisher.WSGIPublisher, line 385, in publish_module
Module ZPublisher.WSGIPublisher, line 288, in publish
Module ZPublisher.mapply, line 85, in mapply
Module ZPublisher.WSGIPublisher, line 63, in call_object
Module senaite.core.browser.dashboard.dashboard, line 211, in call
Module Products.Five.browser.pagetemplatefile, line 126, in call
Module Products.Five.browser.pagetemplatefile, line 61, in call
Module zope.pagetemplate.pagetemplate, line 135, in pt_render
Module Products.PageTemplates.engine, line 378, in call
Module z3c.pt.pagetemplate, line 176, in render
Module chameleon.zpt.template, line 302, in render
Module chameleon.template, line 192, in render
Module e4c62f22e8500498d775851f0a1c4357, line 1705, in render
Module 708fd70a32990165975d3aebf0e16a91, line 1110, in render_master
Module zope.contentprovider.tales, line 79, in call
Module senaite.core.browser.viewlets.toolbar, line 44, in render
Module Products.Five.browser.pagetemplatefile, line 126, in call
Module Products.Five.browser.pagetemplatefile, line 61, in call
Module zope.pagetemplate.pagetemplate, line 135, in pt_render
Module Products.PageTemplates.engine, line 378, in call
Module z3c.pt.pagetemplate, line 176, in render
Module chameleon.zpt.template, line 302, in render
Module chameleon.template, line 215, in render
Module chameleon.template, line 192, in render
Module 1ba0994f769c658347df92572894de25, line 541, in render
Module zope.tales.pythonexpr, line 73, in call
can you show us the zcml code you used to override the viewlet?
Viewlets and Views usually have two parts: 1) Sometemplate.pt and view.py. It looks like you have not defined 'get_portrait_url' the right place.
I would make an addon with plonecli and add a viewlet. That way all the code you need will be made for you, and you can just add the code suggested.
Note: Your view.py (or viewlets.py) file MUST have
def get_portrait_url(self):
return 'something'
for you to use
${view/get_portrait_url}
In you viewlet template
UPDATE: I now see that you have posted another question, looks like you want to override a viewlet.