将 Python 脚本放入 plone 模板以呈现对象列表

标签 python plone

我试图将对象列表渲染到 plone 模板中, 我用查询编写了 python 脚本以获取对象列表,然后它返回包含对象的列表。

lista-fixos = context.portal_catalog.searchResults(
        Subject = { "query": ["Destaques", "Destaques-fixo"],
                     "operator": "and" 
                     }
)
lista-normal = context.portal_catalog.searchResults(
        Subject = { "query": ["Destaques"]}

)

lista-fixos.append(lista-normal)

for e in lista-fixos:
       if e not in lista-final:
           lista-final.append(e)
return lista-fixos

然后在这里我尝试得到然后

tal:define="results here/getCatalogDestaques.py"

这是脚本和模板 http://pastie.org/5530478

我的问题是每次我尝试调用模板时都会出现以下错误:

Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.CMFCore.FSPageTemplate, line 240, in _exec
  Module Products.CMFCore.FSPageTemplate, line 180, in pt_render
  Module Products.PageTemplates.PageTemplate, line 79, in pt_render
  Module zope.pagetemplate.pagetemplate, line 113, in pt_render
   - Warning: Macro expansion failed
   - Warning: <type 'exceptions.AttributeError'>: header
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 851, in do_condition
  Module Products.PageTemplates.Expressions, line 205, in evaluateBoolean
  Module zope.tales.tales, line 696, in evaluate
   - URL: file:/media/New Volume/ambiente_nportal/ploneAmbiente/eggs/Products.CMFContentPanels-2.6b2-py2.7.egg/Products/CMFContentPanels/skins/contentpanels/cp_new_panel_form.pt
   - Line 160, Column 7
   - Expression: <PythonExpr usemacro and exists(viewletConfPath)>
   - Names:
      {'container': <PloneSite at /Plone>,
       'context': <ATTopic at /Plone/destaques/destaques-portal>,
       'default': <object object at 0xb73016b0>,
       'here': <ATTopic at /Plone/destaques/destaques-portal>,
       'loop': {},
       'nothing': None,
       'options': {'args': ()},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0xce95c84>,
       'request': <HTTPRequest, URL=http://localhost:8080/Plone/destaques/destaques-portal/cp_new_panel_form>,
       'root': <Application at >,
       'template': <FSPageTemplate at /Plone/cp_new_panel_form used for /Plone/destaques/destaques-portal>,
       'traverse_subpath': [],
       'user': <PropertiedUser 'admin'>}
  Module Products.PageTemplates.ZRPythonExpr, line 48, in __call__
   - __traceback_info__: usemacro and exists(viewletConfPath)
  Module PythonExpr, line 1, in <expression>
  Module zope.tales.pythonexpr, line 77, in __call__
  Module zope.tales.expressions, line 216, in __call__
  Module Products.PageTemplates.Expressions, line 162, in _exists
  Module zope.tales.expressions, line 124, in _eval
  Module Products.PageTemplates.Expressions, line 74, in boboAwareZopeTraverse
  Module OFS.Traversable, line 315, in restrictedTraverse
  Module OFS.Traversable, line 248, in unrestrictedTraverse
   - __traceback_info__: ([], 'macros')
  Module Products.PageTemplates.PageTemplate, line 51, in macros
  Module Products.CMFCore.FSPageTemplate, line 168, in pt_macros
  Module Products.PageTemplates.PageTemplate, line 60, in pt_macros
   - Warning: Compilation failed
   - Warning: zope.tal.taldefs.TALError: Invalid variable name "here.getCatalogDestaques" in expression u'here.getCatalogDestaques', at line 7, column 1
PTRuntimeError: Page Template template-destaques has errors: ['Compilation failed', 'zope.tal.taldefs.TALError: Invalid variable name "here.getCatalogDestaques" in expression u\'here.getCatalogDestaques\', at line 7, column 1']

最佳答案

尝试从调用中删除 .py 部分。即:

tal:define="results here/getCatalogDestaques"

关于将 Python 脚本放入 plone 模板以呈现对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13882991/

相关文章:

python - 使用用户输入调用函数

javascript - Django CORS 访问控制允许来源丢失

python - Pandas 按销售项目分组并统计列中每月的销售额

plone - 如何将 "display layout"/"view_method"添加到文件夹?

python - Plone 如何为事件添加内容规则,该事件在结束日期后应移至另一个文件夹

python - 如何加载和使用 PyTorch (.pth.tar) 模型

python - 在 pandas 数据框中查找包含 inf 的单元格的行位置和列名

Plone:编辑 portlet 的名称

python - 创建后的 Plone Archetypes 重定向