zope cheat sheet

some example snippets of zope/ plone,  zpt and python code (beware word wrap - will sort out another template for these cheat sheets)

Get local roles on an object

local_roles = my_obj.get_local_roles()

Set local roles on an object

my_obj.manage_setLocalRoles('auser',('Owner', 'Manager', 'Publisher'))

(both the above were done from an external method)

Add a property to an object

my_obj.manage_addProperty('my_property_id', value="", type="string")

Get a list (array?) of objects

my_list = context.foo.bar.objectValues(['MyObjectType'])

Check user has manager role (zpt/ tal)

tal:condition="python:user.hasRole(here, ['Manager'])"

List attributes/ properties/ other stuff on an object

pp dir(myobj)

(note: this is something you do from a python prompt. pp id “pretty print”)

Get an object by ID from within a folder

myobj = getattr(myfolder,'idofobject')

Take a look at the source code of a function

(i.e from a pdb prompt

import inspect
inspect.getsource(myobj.mymethod)