Include Python scripts with Plone add-on

I have a Plone add-in (created through Zope) that includes Javascript files and page templates. Some of the Javascript functions must call Python scripts (via AJAX calls) - how do I include these Python scripts in my add-on without going through ZMI?

I have a browser folder that contains the configure.zcml file - registering resource directories and template files. I would suggest that registering python files would be similar to this or similar to a way to register Javascript files, but maybe not?

+3
source share
1 answer

You register your python as Views in the content object:

<browser:page
 for="**INTERFACE**"
 name="**name**"
 class="**class**"
 attribute="**method**"
 permission="zope2.View"
 />

- , , - (.. http://path-to-object/@@name), - Python, script, - ( __ __). , , - , .

script, kss ( , AJAX) - BrowserView (PloneKSSView - KSS):

<browser:page
 for="Products.VirtualDataCentre.interfaces.IDDCode"
 name="getTableColumns"
 class="Products.VirtualDataCentre.browser.DDActions.DDActions"
 attribute="getTableColumns"
 permission="zope2.View"
 />

IDDCode - , , DDActions.py:

from Products.Five import BrowserView
from plone.app.kss.plonekssview import PloneKSSView
class DDActions(PloneKSSView):
    def getTableColumns(self, table, currValue, currLabel):
        columns = self.context.getColumnNames(table)
        for (field, curr) in [('valueColumn', currValue), ('labelColumn',currLabel)]:
            self.replaceSelect(field, columns, (curr or self.context[field]))
+6
source

All Articles