Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python script into a plone template to render a list of objects

Tags:

python

plone

I was trying to render a list of objects into a plone template, I wrote the python script with the query to get a list of objects, then it returns a list with the objects.

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

And here I try to get then

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

Here is the script and the template http://pastie.org/5530478

My problem is that everytime that I try to call the template it give me the following error:

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']
like image 671
Pcasari Avatar asked Sep 14 '26 14:09

Pcasari


1 Answers

Try removing the .py part from the call. ie:

tal:define="results here/getCatalogDestaques"
like image 164
Lennart Regebro Avatar answered Sep 16 '26 04:09

Lennart Regebro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!