2012-12-14 57 views
3

我試圖將對象列表呈現爲plone模板, 我用查詢來編寫python腳本以獲取對象列表,然後返回列表與對象。將Python腳本導入到plone模板以呈現對象列表

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'] 

回答

3

嘗試刪除.py部分來自呼叫。即:

tal:define="results here/getCatalogDestaques" 
+0

它的工作。非常感謝你。 – Pcasari