Exemplo n.º 1
0
def move_to_list(request, board_id, card_id):
    if request.method != "POST":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

    post_params = json.loads(request.body)

    member = request.user.member
    try:
        card = get_card_or_404(request, board_id, card_id)
    except Http404:
        return JsonResponseNotFound({"message": "Card not found."})

    # The new position of the card
    new_position = post_params.get("position", "top")

    # If there is no new_list param, the card is going to be moved in the same list currently is
    if post_params.get("new_list"):
        list_ = card.board.lists.get(id=post_params.get("new_list"))
        card.move(member,
                  destination_list=list_,
                  destination_position=new_position)
    else:
        card.change_order(member, destination_position=new_position)

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_board())
Exemplo n.º 2
0
def _move_all_list_cards(request, board_id):
    if request.method != "POST":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

    member = request.user.member
    try:
        board = get_board_or_404(request, board_id)
    except Http404:
        return JsonResponseNotFound({"message": "Board not found"})

    post_params = json.loads(request.body)

    if not post_params.get("source_list") or not post_params.get(
            "destination_list"):
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    # Check if the lists exists and if they are different
    try:
        source_list = board.active_lists.get(id=post_params.get("source_list"))
        destination_list = board.active_lists.get(
            id=post_params.get("destination_list"))
        if source_list.id == destination_list.id:
            raise AssertionError()
    except (List.DoesNotExist, AssertionError):
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    # Move the cards
    source_list.move_cards(member=member, destination_list=destination_list)

    serializer = Serializer(board=board)
    return JsonResponse(serializer.serialize_board())
Exemplo n.º 3
0
def get_board(request, board_id):
    if request.method != "GET":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})
    try:
        board = get_user_boards(request.user).get(id=board_id)
    except Board.DoesNotExist:
        return JsonResponseNotFound({"message": "Not found."})

    serializer = Serializer(board=board)
    return JsonResponse(serializer.serialize_board())