2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
def stringify(value):
|
|
|
|
'''Transforms p_value such that it can be dumped as a string into a
|
|
|
|
generated file.'''
|
|
|
|
if isinstance(value, tuple) or isinstance(value, list):
|
|
|
|
res = '('
|
|
|
|
for v in value:
|
|
|
|
res += '%s,' % stringify(v)
|
|
|
|
res += ')'
|
2009-11-11 13:22:13 -06:00
|
|
|
elif value.__class__.__name__ == 'DateTime':
|
|
|
|
res = 'DateTime("%s")' % value.strftime('%Y/%m/%d %H:%M')
|
2009-06-29 07:06:01 -05:00
|
|
|
else:
|
|
|
|
res = str(value)
|
|
|
|
if isinstance(value, basestring):
|
|
|
|
if value.startswith('python:'):
|
|
|
|
res = value[7:]
|
|
|
|
else:
|
|
|
|
res = "'%s'" % value.replace("'", "\\'")
|
2009-09-29 07:32:34 -05:00
|
|
|
res = res.replace('\n', '\\n')
|
2009-06-29 07:06:01 -05:00
|
|
|
return res
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
def updateRolesForPermission(permission, roles, obj):
|
|
|
|
'''Adds roles from list p_roles to the list of roles that are granted
|
|
|
|
p_permission on p_obj.'''
|
|
|
|
from AccessControl.Permission import Permission
|
|
|
|
# Find existing roles that were granted p_permission on p_obj
|
|
|
|
existingRoles = ()
|
|
|
|
for p in obj.ac_inherited_permissions(1):
|
|
|
|
name, value = p[:2]
|
|
|
|
if name == permission:
|
|
|
|
perm = Permission(name, value, obj)
|
|
|
|
existingRoles = perm.getRoles()
|
|
|
|
allRoles = set(existingRoles).union(roles)
|
|
|
|
obj.manage_permission(permission, tuple(allRoles), acquire=0)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
from appy.gen.utils import AppyRequest
|
|
|
|
def getAppyRequest(zopeRequest, obj=None):
|
|
|
|
'''This method creates a nice (Appy) object representation of a
|
|
|
|
dictionary-like Zope REQUEST object.'''
|
|
|
|
return AppyRequest(zopeRequest, obj)
|
|
|
|
# ------------------------------------------------------------------------------
|