def post(self, request): user = request.user parentNode = self.CONTENT.get('parent') text = self.CONTENT.get('text') reType = self.CONTENT.get('type') description = self.CONTENT.get('description') for node in parentNode.node_set.all(): if node.text == text: raise ErrorResponse(status.HTTP_400_BAD_REQUEST, 'Duplicated name under ' + parentNode.text) site, parentRelativePath = parentNode.get_site_and_path() nodeRelativePath = os.path.join(parentRelativePath, text) nodeFolder = os.path.join(parentNode.get_full_path(), text) if(reType == 'R'): if(User.has_perm(user, 'repo.add_repository', None)): p2_folder = p2.Folder(nodeFolder) p2_folder.addRepositoryFolder() repo = dbhandler.create_repository(text, nodeRelativePath, description, site, parentNode) node = repo.node else: raise PermissionDenied if(reType == 'C'): if(User.has_perm(user, 'repo.add_composite', None)): p2_folder = p2.Folder(nodeFolder) p2_folder.addCompositeFolder() com = dbhandler.create_composite(text, nodeRelativePath, site, parentNode) node = com.node else: raise PermissionDenied return node.as_node()
def create_composite(name, path, site): com = dbhandler.create_composite(name, path, site) return com.node