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

时间:2012-12-14 16:55:16

标签: 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']

1 个答案:

答案 0 :(得分:3)

尝试从通话中删除.py部分。即:

tal:define="results here/getCatalogDestaques"