Exemple #1
0
 def Paste(self, ids, pos, user):
     """
     Paste the copied object with id to this object
     """
     root = self.dataroot
     new = []
     msgs = []
     result = True
     for id in ids:
         id = int(id)
         if self.GetID() == id:
             continue
         obj = root.LookupObj(id, preload="skip")
         if not obj:
             msgs.append(_(u"Object not found"))
             result = False
             continue
         newobj = self.Duplicate(obj, user) 
         if not newobj:
             raise TypeError, "Duplicate failed"
         if ISort.providedBy(self):
             self.InsertAfter(newobj.id, pos, user=user)
         new.append(newobj)
     if not self.app.configuration.autocommit:
         for o in new:
             o.Commit(user)
     if result:
         msgs.append(_(u"OK. Copied and pasted."))
     return result, msgs
Exemple #2
0
 def Paste(self, ids, pos, user):
     """
     Paste the copied object with id to this object
     """
     root = self.dataroot
     new = []
     msgs = []
     result = True
     for id in ids:
         id = int(id)
         if self.GetID() == id:
             continue
         obj = root.LookupObj(id, preload="skip")
         if not obj:
             msgs.append(_(u"Object not found"))
             result = False
             continue
         newobj = self.Duplicate(obj, user)
         if not newobj:
             raise TypeError, "Duplicate failed"
         if ISort.providedBy(self):
             self.InsertAfter(newobj.id, pos, user=user)
         new.append(newobj)
     if not self.app.configuration.autocommit:
         for o in new:
             o.Commit(user)
     if result:
         msgs.append(_(u"OK. Copied and pasted."))
     return result, msgs
Exemple #3
0
    def Move(self, ids, pos, user):
        """
        Move the object with id to this object
        
        Events
        
        - beforeAdd(data=obj.meta, type=type)
        - afterDelete(id=obj.id)
        - moved()
        - afterAdd(obj=obj)
        """
        root = self.dataroot
        oldParent=None

        moved = []
        msgs = []
        result = True
        for id in ids:
            id = int(id)
            if self.GetID() == id:
                continue
            obj = root.LookupObj(id, preload="skip")
            if not obj:
                msgs.append(_(u"Object not found"))
                result = False
                continue

            type=obj.GetTypeID()
            # allow subobject
            if not self.IsTypeAllowed(type, user):
                raise TypeError, "Object cannot be added here"

            self.Signal("beforeAdd", data=obj.meta, type=type)
            if not oldParent or oldParent.id != obj.parent.id:
                oldParent = obj.parent
            obj.__parent__ = self
            obj.meta["pool_unitref"] = self.GetID()
            oldParent.Signal("afterDelete", id=obj.id)
            obj.Signal("moved")
            #obj.Close()
            moved.append(obj)

        for o in moved:
            o.Commit(user)
            if ISort.providedBy(self):
                self.InsertAfter(o.id, pos, user=user)
            self.Signal("afterAdd", obj=o)
        if result:
            msgs.append(_(u"OK. Cut and pasted."))
        return result, msgs
Exemple #4
0
    def Move(self, ids, pos, user):
        """
        Move the object with id to this object
        
        Events
        
        - beforeAdd(data=obj.meta, type=type)
        - afterDelete(id=obj.id)
        - moved()
        - afterAdd(obj=obj)
        """
        root = self.dataroot
        oldParent = None

        moved = []
        msgs = []
        result = True
        for id in ids:
            id = int(id)
            if self.GetID() == id:
                continue
            obj = root.LookupObj(id, preload="skip")
            if not obj:
                msgs.append(_(u"Object not found"))
                result = False
                continue

            type = obj.GetTypeID()
            # allow subobject
            if not self.IsTypeAllowed(type, user):
                raise TypeError, "Object cannot be added here"

            self.Signal("beforeAdd", data=obj.meta, type=type)
            if not oldParent or oldParent.id != obj.parent.id:
                oldParent = obj.parent
            obj.__parent__ = self
            obj.meta["pool_unitref"] = self.GetID()
            oldParent.Signal("afterDelete", id=obj.id)
            obj.Signal("moved")
            #obj.Close()
            moved.append(obj)

        for o in moved:
            o.Commit(user)
            if ISort.providedBy(self):
                self.InsertAfter(o.id, pos, user=user)
            self.Signal("afterAdd", obj=o)
        if result:
            msgs.append(_(u"OK. Cut and pasted."))
        return result, msgs