Floyd May wrote:
How can I use a set object within a page template?

When I attempt to create a set (e.g. tal:define="myset
python:set(some_list)"), zope complains that the name 'set' is not

If you only need to read from some native python objects, you can make a simple wrapper. You can wrap a set() in this class and return it from python.

_marker = []

class Zello:

    Zello (Zellophane)
    A minimal wrapper for viewing native python objects in pagetemplates.

If you try to view attributes on simple Python objects you get a Permission
    error. This is pretty simple to fix in your own objects by setting:

        __allow_access_to_unprotected_subobjects__ = 1

    For some built in objects you cannot do this. This class just puts a
    transparent wrapper around such objects::

        wrapped = Zello(datetime(2005, 10, 12))

    So you can write this zpt code:

        <span tal:replace="wrapped/year" />

    If you wrap a Zope object with it, you basically remove all security
    checkcs. So don't do that.

    __allow_access_to_unprotected_subobjects__ = 1

    def __init__(self, obj):
        self._obj = obj

    def __getattr__(self, attr, default=_marker):
        if default is _marker:
            return getattr(self._obj, attr)
            return getattr(self._obj, attr, default)

    def __getitem__(self, key):
        return self._obj[key]


hilsen/regards Max M, Denmark

IT's Mad Science

Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to