Exemplo n.º 1
0
 def _walk(self, obj, level=-1):
     yield self._getInfo(obj)
     if level != 0 and (IFolderish.providedBy(obj) \
                    or IBaseFolder.providedBy(obj)):
         for v in obj.contentValues():
             for i in self._walk(v, level - 1):
                 yield i
 def walk(self, obj):
     if IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj):
         contained = self.getContained(obj)
         yield obj, tuple([(k, v.getPortalTypeName()) for k, v in contained])
         for k, v in contained:
             for x in self.walk(v):
                 yield x
     else:
         yield obj, ()
 def walk(self, obj):
     if IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj):
         contained = self.getContained(obj)
         yield obj, tuple([(k, v.getPortalTypeName()) for k, v in contained])
         for k, v in contained:
             for x in self.walk(v):
                 yield x
     else:
         yield obj, ()
Exemplo n.º 4
0
 def walk(self, obj):
     if IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj):
         contained = [(k, v.getPortalTypeName()) for k, v in obj.contentItems()]
         yield obj, tuple(contained)
         for v in obj.contentValues():
             for x in self.walk(v):
                 yield x
     else:
         yield obj, ()
Exemplo n.º 5
0
 def walk(self, obj):
     if self.limit and self.count >= self.limit:
         raise StopIteration
     else:
         self.count += 1
         if IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj):
             contained = self.getContained(obj)
             yield obj, tuple([(k, v.getPortalTypeName()) for k, v in contained])
             for k, v in contained:
                 for x in self.walk(v):
                     yield x
         else:
             yield obj, ()
Exemplo n.º 6
0
 def __iter__(self):
     for item in self.previous:
         keys = item.keys()
         typekey = self.typekey(*keys)[0]
         pathkey = self.pathkey(*keys)[0]
         
         if not (typekey and pathkey):             # not enough info
             yield item; continue
         
         type_, path = item[typekey], item[pathkey]
         
         fti = self.ttool.getTypeInfo(type_)
         if fti is None:                           # not an existing type
             yield item; continue
         
         elems = path.strip('/').rsplit('/', 1)
         container, id = (len(elems) == 1 and ('', elems[0]) or elems)
         context = self.context.unrestrictedTraverse(container, None)
         if context is None:                       # container doesn't exist
             yield item; continue
         
         # check if context is container, if we didn't do this AttributeError
         # will be raised when calling fti._constructInstance(context, id)
         if not (IFolderish.providedBy(context) or IBaseFolder.providedBy(context)):
             # we can't construct this content item, so remove it from pipeline
             continue
         
         # content object always have some default attributes, but sometimes
         # these attributes can be also used as content ids
         if id in ALLWAYS_EXISTING_ATTRIBUTES:
             # 'getattr' function always return ComputedAttribute object for 'index_html'
             # whether 'index_html' object is in context or no, but 'get' method
             # returns correct value
             if aq_base(context).get(id, None) is not None:
                 yield item; continue
         elif getattr(aq_base(context), id, None) is not None: # item exists
             yield item; continue
         
         obj = fti._constructInstance(context, id)
         obj = fti._finishConstruction(obj)
         if obj.getId() != id:
             item[pathkey] = '%s/%s' % (container, obj.getId())
         
         yield item
def cut_and_paste(ob, *args, **kw):
    """ Uses OFS to cut and paste an object.
    """
    err = list()
    if not kw['target_path']:
        err.append('You must specify a target path')
    id = kw['id_to_move']
    if not id:
        err.append(u'You must select an object to move')
    id = safe_unicode(id)
    if len(err):
        return err

    lang = kw['lang']
    target_base = kw['target_base']
    if target_base is None:
        err.append(
            u'No object was found at the given taget path %s'
            % kw['target_path'])
        return err
    if ITranslatable.providedBy(target_base):
        target_manager = ITranslationManager(target_base)
        target = target_manager.get_translation(lang)
    else:
        err.append(
            u'The target object is not translatable. Please '
            'choose a different target that is translatable.')
        return err
    if target is None:
        err.append(
            u'No translation in language "%s" was found of '
            'the target %s' % (lang, kw['target_path']))
        return err
    if not IBaseFolder.providedBy(target):
        err.append(
            u'The target object is not folderish - pasting is '
            'not possible.')
        return err
    name = None
    if id in ob.objectIds():
        name = id
        trans_object = getattr(ob, name)
    else:
        # look for translation via get_translation
        manager = ITranslationManager(kw['target_object'])
        trans_object = manager.get_translation(lang)
        if trans_object:
            if Acquisition.aq_parent(trans_object) == ob:
                name = trans_object.getId()

    if name is None:
        err.append(
            u'No translation of the requested object for language '
            '%s found in %s' % (lang, '/'.join(ob.getPhysicalPath())))
        return err
    if target == trans_object:
        err.append(
            u'The target cannot be identical to the object you want to move')
        return err

    # we need to pass a string
    name = safe_unicode(name).encode('utf-8')
    try:
        cut = ob.manage_cutObjects(name)
    except ResourceLockedError:
        lockable = ILockable(trans_object)
        lockable.unlock()
        cut = ob.manage_cutObjects(name)
    try:
        target.manage_pasteObjects(cut)
    except Exception, error:
        err.append(
            u'Not possible to paste item in language %s to target %s.'
            'Error message: %s' % (lang, target.absolute_url(), error))