我想在自定义视图中通过Plone-Membertool修改用户肖像的图像大小。我认为应该plone.app.imaging使用以下页面模板片段来解决:
<img tal:define="scales user/img/@@images; image python: scales.scale('image', width=75, height=100);" tal:condition="image" tal:attributes="src image/url; width image/width; height image/height"/>
的user/img是在辅助级如下定义(并且在视图级为“用户”传递):
mtool = api.portal.get_tool(name='portal_membership') uid = user.id fullname = user.getProperty('fullname') ... dct = { 'id': uid, 'img': mtool.getPersonalPortrait(id=uid), 'fullname': fullname, ... } return dct
如果我现在@@images对此应用,则会user/img收到以下AttributeError:
... Module zope.tales.tales, line 696, in evaluate URL: /opt/workspace/my-plone-buildout/src/myproduct.content/myproduct/content/browser/templates/user_list.pt Line 42, Column 4 Expression: <PathExpr standard:u'user/img/@@images'> Names: ... Module Products.PageTemplates.Expressions, line 94, in trustedBoboAwareZopeTraverse Module OFS.Traversable, line 300, in unrestrictedTraverse __traceback_info__: ([], '@@images') AttributeError: @@images
看来,它并不会mtool.getPersonalPortrait(id)返回plone.app.image可以在其上应用的Image-Element 。但是,如果我在模板中使用此构造只是为了显示未更改的图像,则可以正常工作: <img src="#" tal:replace="structure user/img" /> 接下来,我尝试使用绝对肖像URL到用户的肖像来进行@@images工作。辅助类中的第一个:
<img src="#" tal:replace="structure user/img" />
... dct = { ... 'img': mtool.getPersonalPortrait(id=uid), 'imgurl': mtool.getPersonalPortrait(id=uid).absolute_url(), ...
然后在页面模板中:
<img tal:define="scales user/imgurl/@@images; image python: scales.scale('image', width=75, height=100);" ...
然后我得到一个LocationError:
... Expression: <PathExpr standard:u'user/imgurl/@@images'> ... Module Products.CMFPlone.patches.security, line 12, in traverse Module zope.traversing.namespace, line 329, in traverse LocationError: ('http://localhost:8080/Plone/defaultUser.png', 'images')
即使该网址http://localhost:8080/Plone/defaultUser.png显示正确的图片(默认图片也没有变化)。
我没有找到任何文档,找不到哪种类型的对象getPersonalPortrait()以及可以使用哪种方法。以及如何在自定义视图中根据特定需求调整此用户画像的大小(根据一些规则比较python中的宽度和高度以计算正确的调整大小)。
在python的视图类中获得一些用于操纵用户肖像的指针将是很棒的。