def create_board(cls, **kwargs): board = Board() board.created_by = kwargs.get('created_by', cls.user.id) board.name = kwargs.get( 'name', cls.fake.pystr(min_chars=1, max_chars=256), ) board.owner_id = kwargs.get('owner_id', cls.user.id) board.type = kwargs.get('type', BoardType.PERSONAL.id) board.visibility = kwargs.get('visibility', BoardVisibility.PRIVATE.id) saved_board = board.save() user = User.objects(id=saved_board.owner_id).first() if user: user.boards.append(saved_board) user.save() return saved_board
def index_POST(): if not current_user.is_authenticated: return jsonify({ 'error': 'Could not create board because you are not logged in.', }), 401 form = CreateBoardForm(request.form) if not form.validate_on_submit(): return jsonify(form.errors), 400 owner = get_owner_from_id(form.owner.data) board = Board() board.created_by = current_user.id board.name = form.name.data board.owner_id = owner.id board.type = BoardType.PERSONAL.id if owner.id == current_user.id \ else BoardType.TEAM.id board.visibility = form.visibility.data board.save() owner.boards.append(board) owner.save() return jsonify({ 'id': str(board.id), 'url': url_for( 'board.board_GET', board_id=board.id, message='New board has been created.', category='success', ), }), 201