Exemplo n.º 1
0
    def _traverseToMountedRoot(self, root, mount_parent):
        """Hook for getting the object to be mounted.
        """
        params = self._v_mount_params
        if params is None:
            params = self._loadMountParams()
        real_root, real_path, container_class = params
        if real_root is None:
            real_root = 'Application'
        try:
            obj = root[real_root]
        except KeyError:
            # DM 2005-05-17: why should we require 'container_class'?
            # if container_class or self._create_mount_points:
            if self._create_mount_points:
                # Create a database automatically.
                from OFS.Application import Application
                obj = Application()
                root[real_root] = obj
                # Get it into the database
                transaction.savepoint(optimistic=True)
            else:
                raise

        if real_path is None:
            real_path = self._path
        if six.PY2 and isinstance(real_path, six.text_type):
            real_path = real_path.encode('utf8')
        if real_path and real_path != '/':
            try:
                obj = obj.unrestrictedTraverse(real_path)
            except (KeyError, AttributeError):
                # DM 2005-05-13: obviously, we do not want automatic
                #  construction when "_create_mount_points" is false
                # if container_class or self._create_mount_points:
                if container_class and self._create_mount_points:
                    blazer = CustomTrailblazer(obj, container_class)
                    obj = blazer.traverseOrConstruct(real_path)
                else:
                    raise
        return obj
    def _traverseToMountedRoot(self, root, mount_parent):
        """Hook for getting the object to be mounted.
        """
        params = self._v_mount_params
        if params is None:
            params = self._loadMountParams()
        real_root, real_path, container_class = params
        if real_root is None:
            real_root = 'Application'
        try:
            obj = root[real_root]
        except KeyError:
            # DM 2005-05-17: why should we require 'container_class'?
            # if container_class or self._create_mount_points:
            if self._create_mount_points:
                # Create a database automatically.
                from OFS.Application import Application
                obj = Application()
                root[real_root] = obj
                # Get it into the database
                transaction.savepoint(optimistic=True)
            else:
                raise

        if real_path is None:
            real_path = self._path
        if six.PY2 and isinstance(real_path, six.text_type):
            real_path = real_path.encode('utf8')
        if real_path and real_path != '/':
            try:
                obj = obj.unrestrictedTraverse(real_path)
            except (KeyError, AttributeError):
                # DM 2005-05-13: obviously, we do not want automatic
                #  construction when "_create_mount_points" is false
                # if container_class or self._create_mount_points:
                if container_class and self._create_mount_points:
                    blazer = CustomTrailblazer(obj, container_class)
                    obj = blazer.traverseOrConstruct(real_path)
                else:
                    raise
        return obj