예제 #1
0
def add_requirement(request, board_id, card_id):
    if request.method != "PUT":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

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

    put_body = json.loads(request.body)
    if not put_body.get("requirement"):
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    requirement = board.requirements.get(id=put_body.get("requirement"))

    # If the requirement is already in the card, we can't continue
    if card.requirements.filter(id=requirement.id).exists():
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    card.add_requirement(member, requirement)

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #2
0
def change_labels(request, board_id, card_id):
    if request.method != "POST":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

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

    post_params = json.loads(request.body)

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

    label_ids = post_params.get("labels")
    card.labels.clear()
    for label_id in label_ids:
        if board.labels.filter(id=label_id).exists():
            label = board.labels.get(id=label_id)
            card.labels.add(label)

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #3
0
def add_new_review(request, board_id, card_id):
    if request.method != "PUT":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

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

    put_body = json.loads(request.body)
    if not put_body.get("members"):
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    reviewers = board.members.filter(id__in=put_body.get("members"))

    description = put_body.get("description", "")

    card.add_review(member, reviewers=reviewers, description=description)

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #4
0
def _add_card(request, board_id):
    if request.method != "PUT":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

    member = request.user.member

    put_params = json.loads(request.body)

    if not put_params.get("name") or not put_params.get(
            "list") or not put_params.get("position"):
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    if put_params.get("position") != "top" and put_params.get(
            "position") != "bottom":
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    try:
        list_ = get_list_or_404(request, board_id, put_params.get("list"))
    except Http404:
        return JsonResponseNotFound({"message": "List not found"})

    new_card = list_.add_card(member=member,
                              name=put_params.get("name"),
                              position=put_params.get("position"))

    serializer = Serializer(board=new_card.board)
    return JsonResponse(serializer.serialize_card(new_card))
예제 #5
0
def get_card(request, board_id, card_id):
    if request.method != "GET":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})
    try:
        card = get_card_or_404(request, board_id, card_id)
    except Http404:
        return JsonResponseNotFound({"message": "Card not found."})
    serializer = Serializer(board=card.board)
    card_json = serializer.serialize_card(card)
    return JsonResponse(card_json)
예제 #6
0
def change(request, board_id, card_id):
    if request.method != "PUT":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

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

    put_params = json.loads(request.body)

    if put_params.get("name"):
        card.change_attribute(member,
                              attribute="name",
                              value=put_params.get("name"))

    elif put_params.get("description"):
        card.change_attribute(member,
                              attribute="description",
                              value=put_params.get("name"))

    elif put_params.get("is_closed") is not None:
        card.change_attribute(member,
                              attribute="is_closed",
                              value=put_params.get("name"))

    elif put_params.get("due_datetime"):
        due_datetime_str = put_params.get("due_datetime")
        due_datetime = dateutil.parser.parse(due_datetime_str)
        card.change_attribute(member,
                              attribute="due_datetime",
                              value=due_datetime)

    elif "due_datetime" in put_params and put_params.get(
            "due_datetime") is None:
        card.change_attribute(member, attribute="due_datetime", value=None)

    elif "value" in put_params:
        card_value = put_params.get("value")
        if card_value == "":
            card_value = None
        card.change_value(member=member, value=card_value)

    else:
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #7
0
def remove_requirement(request, board_id, card_id, requirement_id):
    if request.method != "DELETE":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

    member = request.user.member
    try:
        board = get_user_boards(request.user).get(id=board_id)
        card = board.cards.get(id=card_id)
        requirement = card.requirements.get(id=requirement_id)
    except (Board.DoesNotExist, Card.DoesNotExist) as e:
        return JsonResponseNotFound({"message": "Not found."})

    card.remove_requirement(member, requirement)
    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #8
0
def add_se_time(request, board_id, card_id):
    if request.method != "POST":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

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

    post_params = json.loads(request.body)
    spent_time = post_params.get("spent_time")
    estimated_time = post_params.get("estimated_time")
    date = post_params.get("date")
    description = post_params.get("description", card.name)

    if spent_time != "":
        try:
            spent_time = float(str(spent_time).replace(",", "."))
        except ValueError:
            return JsonResponseNotFound({"message": "Not found."})
    else:
        spent_time = None

    if estimated_time != "":
        try:
            estimated_time = float(str(estimated_time).replace(",", "."))
        except ValueError:
            return JsonResponseNotFound({"message": "Not found."})
    else:
        estimated_time = None

    if spent_time is None and estimated_time is None:
        return JsonResponseNotFound({"message": "Not found."})

    # Optional days ago parameter
    days_ago = None
    matches = re.match(r"^\-(?P<days_ago>\d+)$", date)
    if matches:
        days_ago = int(matches.group("days_ago"))

    card.add_spent_estimated_time(member, spent_time, estimated_time, days_ago,
                                  description)

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #9
0
def remove_blocking_card(request, board_id, card_id, blocking_card_id):
    if request.method != "DELETE":
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    member = request.user.member
    try:
        board = get_user_boards(request.user).get(id=board_id)
        card = board.cards.get(id=card_id)
        blocking_card = card.blocking_cards.exclude(id=card_id).get(
            id=blocking_card_id)
    except (Board.DoesNotExist, Card.DoesNotExist) as e:
        return JsonResponseNotFound({"message": "Not found."})

    card.remove_blocking_card(member, blocking_card)
    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #10
0
def add_blocking_card(request, board_id, card_id):
    if request.method != "PUT":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

    member = request.user.member
    put_body = json.loads(request.body)
    if not put_body.get("blocking_card"):
        return JsonResponseBadRequest(
            {"message": "Bad request: some parameters are missing."})

    try:
        board = get_user_boards(request.user).get(id=board_id)
        card = board.cards.get(id=card_id)
        blocking_card = board.cards.exclude(id=card_id).get(
            id=put_body.get("blocking_card"))
    except (Board.DoesNotExist, Card.DoesNotExist) as e:
        return JsonResponseNotFound({"message": "Not found."})

    card.add_blocking_card(member, blocking_card)
    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))
예제 #11
0
def change_members(request, board_id, card_id):
    if request.method != "POST":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

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

    post_params = json.loads(request.body)

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

    member_ids = post_params.get("members")

    card.update_members(member, board.members.filter(id__in=member_ids))

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card(card))