Exemplo n.º 1
0
 def check_add_child(self, child):
     """
     Checks if *child"* can be added to *self*.
     If *child* can not be added, an exception is raised.
     
     :param child: child to be added
     :type child: :class:`.Part`
     
     :raises: :exc:`ValueError` if *child* is already a child or a parent.
     :raises: :exc:`.PermissionError` if :attr:`_user` is not the owner of
         :attr:`object`.    
     """
     self.check_permission("owner")
     self.check_editable()
     if not child.is_part:
         raise TypeError("Can not add child: not a Part")
     # check if child is not a parent
     if child.id == self.object.id:
         raise ValueError("Can not add child: child is current object")
     get_controller(child.type)(child, self._user).check_readable()
     parents = (p.link.parent.pk for p in self.get_parents(-1))
     if child.pk in parents:
         raise ValueError("Can not add child %s to %s, it is a parent" %
                             (child, self.object))
     link = self.parentchildlink_parent.filter(child=child, end_time=None)
     if link:
         raise ValueError("Can not add child, %s is already a child of %s" %
                             (child, self.object))
Exemplo n.º 2
0
    def check_attach_document(self, document):
        self.check_permission("owner")
        if not hasattr(document, "is_document") or not document.is_document:
            raise TypeError("%s is not a document" % document)

        if isinstance(document, PLMObjectController):
            document.check_readable()
            document = document.object
        else:
            get_controller(document.type)(document, self._user).check_readable()
        if self.is_document_attached(document):
            raise ValueError("Document is already attached.")
Exemplo n.º 3
0
    def check_attach_part(self, part):
        self.check_permission("owner")
        if not (hasattr(part, "is_part") and part.is_part):
            raise TypeError("%s is not a part" % part)

        if isinstance(part, PLMObjectController):
            part.check_readable()
            part = part.object
        else:
            get_controller(part.type)(part, self._user).check_readable()
        if self.is_part_attached(part):
            raise ValueError("part is already attached.")
Exemplo n.º 4
0
 def check_attach_part(self, part, detach=False):
     if not (hasattr(part, "is_part") and part.is_part):
         raise TypeError("%s is not a part" % part)
     if not isinstance(part, PLMObjectController):
         part = get_controller(part.type)(part, self._user)
     part.check_attach_document(self, detach)
Exemplo n.º 5
0
 def test_get_mock4(self):
     self.assertEqual(Mock2Ctrl, get_controller("Mock4"))
Exemplo n.º 6
0
 def test_get_mock3(self):
     self.assertEqual(MockController, get_controller("Mock3"))
Exemplo n.º 7
0
 def test_get_mock4(self):
     self.assertEqual(Mock2Ctrl, get_controller("Mock4"))
Exemplo n.º 8
0
 def test_get_mock3(self):
     self.assertEqual(MockController, get_controller("Mock3"))
Exemplo n.º 9
0
 def check_attach_part(self, part, detach=False):
     if not (hasattr(part, "is_part") and part.is_part):
         raise TypeError("%s is not a part" % part)
     if not isinstance(part, PLMObjectController):
         part = get_controller(part.type)(part, self._user)
     part.check_attach_document(self, detach)