def walk_folder(folder): for idx, ob in folder.ZopeFind(folder, obj_metatypes=REPORTEK_META_TYPES, search_sub=0): yield ob if IObjectManager.providedBy(ob): for sub_ob in walk_folder(ob): yield sub_ob
def isDirectory(self, path): try: obj = self.context.unrestrictedTraverse(path) except: obj = None return IObjectManager.providedBy(obj)
def isDirectory(self, path): try: obj = self.context.unrestrictedTraverse(path) except: obj = None return IObjectManager.providedBy(obj)
def zope_find_user(container, username): while IObjectManager.providedBy(container): if container._getOb('acl_users', None) is not None: user = container.acl_users.getUser(username) if user is not None and user.getUserName() is not None: return user.__of__(container.acl_users) container = aq_parent(container) fail("%s is not a valid user." % username)
def create_subobjects(root, context, data, total=0): amount = int(data.get('amount', 3)) types = data.get('portal_type') if types is None: base = aq_base(context) if IBaseContent.providedBy(base): types = [] if hasattr(base, 'constrainTypesMode') and base.constrainTypesMode: types = context.locallyAllowedTypes elif IDexterityContent.providedBy(base): fti = component.getUtility(IDexterityFTI, name=context.portal_type) types = fti.filter_content_types and fti.allowed_content_types if not types: msg = _('Either restrict the addable types in this folder or ' \ 'provide a type argument.') addStatusMessage(context.request, msg) return total else: msg = _("The context doesn't provide IBaseContent or " "IDexterityContent. It might be a Plone Site object, " "but either way, I haven't gotten around to dealing with " "it. Why don't you jump in and help?") addStatusMessage(context.request, msg) return total recurse = False if data.get('recurse', None) not in [None, '0', 'False', False]: depth = 0 node = context while IUUID(node) != IUUID(root): depth += 1 node = node.aq_parent if depth < data.get('recursion_depth'): recurse = True for portal_type in types: for n in range(0, amount): obj = create_object(context, portal_type, data) total += 1 if not IObjectManager.providedBy(obj): continue if recurse: if shasattr(obj, 'getLocallyAllowedTypes'): data['portal_type'] = \ list(obj.getLocallyAllowedTypes()) elif shasattr(obj, 'allowedContentTypes'): data['portal_type'] = \ [t.id for t in obj.allowedContentTypes()] total = create_subobjects(root, obj, data, total) return total
def copyroles(source, dest): """ recursive copy of local roles for a copied content item or tree thereof. """ local_roles = source.get_local_roles() for (userid, roles) in local_roles: dest.manage_setLocalRoles(userid, list(roles)) if IObjectManager.providedBy(source): for name, contained in source.objectItems(): if name in dest.objectIds(): copyroles(contained, dest[name])
def traverse(path, content, request=None): """Simple helper to traverse path from content, following only Zope 2 containers API. """ for piece in path: if not IObjectManager.providedBy(content): raise BadRequest( u'Invalid path, not a container /%s.' % '/'.join(path)) child = content._getOb(piece, None) if child is None: raise BadRequest( u'Invalid path, content not found /%s' % '/'.join(path)) if request is not None: hook = getattr(child, '__before_publishing_traverse__', None) if hook is not None: hook(child, request) request['PARENTS'].append(child) content = child return content
def create_subobjects(root, context, data, total=0): amount = int(data.get('amount', 3)) types = data.get('portal_type') request = getRequest() depth = 0 node = context if not IPloneSiteRoot.providedBy(root): while IUUID(node) != IUUID(root): depth += 1 node = node.aq_parent else: while not IPloneSiteRoot.providedBy(node): depth += 1 node = node.aq_parent if types is None or depth > 0: base = aq_base(context) if IBaseContent.providedBy(base): types = [] if hasattr(base, 'constrainTypesMode') and base.constrainTypesMode: types = context.locallyAllowedTypes elif IDexterityContent.providedBy(base): fti = component.getUtility(IDexterityFTI, name=context.portal_type) types = fti.filter_content_types and fti.allowed_content_types if not types: msg = _('Either restrict the addable types in this folder ' 'or provide a type argument.') addStatusMessage(request, msg) return total else: msg = _("The context doesn't provide IBaseContent or " "IDexterityContent. It might be a Plone Site object, " "but either way, I haven't gotten around to dealing with " "it. Why don't you jump in and help?") addStatusMessage(request, msg) return total recurse = False if data.get('recurse', None) not in [None, '0', 'False', False] and \ depth < data.get('recursion_depth'): recurse = True for portal_type in types: for n in range(0, amount): obj = create_object(context, portal_type, data) total += 1 if not IObjectManager.providedBy(obj): continue if recurse: if not data.get('recurse_same_ptypes', False): if shasattr(obj, 'getLocallyAllowedTypes'): data['portal_type'] = \ list(obj.getLocallyAllowedTypes()) elif shasattr(obj, 'allowedContentTypes'): data['portal_type'] = \ [t.id for t in obj.allowedContentTypes()] total = create_subobjects(root, obj, data, total) return total