Exemplo n.º 1
0
def process_request(request):
    if request.method == 'GET':
        return get_cards(request)

    elif request.method == 'POST':
        return new_card(request)

    else:
        return utils.create_405_json_response(allow="GET, POST")
Exemplo n.º 2
0
def process_request(request):
    if not request.user.is_authenticated:
        return utils.create_401_json_response()

    if request.method == 'GET':
        return get_tags(request)

    else:
        return utils.create_405_json_response(allow="GET")
Exemplo n.º 3
0
def process_request(request):
    if request.method == 'POST':
        if not request.user.is_authenticated:
            return utils.create_401_json_response()

        if (len(request.FILES) > 0) and ('archive_file' in request.FILES):
            num_cards_imported = utils.import_card_archive(request.FILES['archive_file'],
                                                           request.user)
            return JsonResponse({'num_cards_imported': num_cards_imported}, status=200)

        else:
            return utils.create_400_json_response('No archive file found')

    else:
        return utils.create_405_json_response(allow="POST")
Exemplo n.º 4
0
def process_request(request, card_uuid):
    if not request.user.is_authenticated:
        return utils.create_401_json_response()

    card = Card.from_uuid(card_uuid, request.user)
    if not card:
        return utils.create_404_json_response("Card")

    if request.method == 'GET':
        return get_card_retrieval_attempts(request, card)

    elif request.method == 'POST':
        return new_card_retrieval_attempt(request, card)

    else:
        return utils.create_405_json_response(allow="GET, POST")
Exemplo n.º 5
0
def process_request(request, card_uuid):
    if not request.user.is_authenticated:
        return utils.create_401_json_response()

    card = Card.from_uuid(card_uuid, request.user)
    if not card:
        return utils.create_404_json_response("Card")

    if request.method == 'GET':
        return get_card(request, card)

    elif request.method == 'PATCH':
        return update_card(request, card)

    elif request.method == 'DELETE':
        return delete_card(request, card)

    else:
        return utils.create_405_json_response(allow="GET, PATCH, DELETE")
Exemplo n.º 6
0
def process_request(request, card_uuid, retrieval_attempt_id):
    if not request.user.is_authenticated:
        return utils.create_401_json_response()

    card = Card.from_uuid(card_uuid, request.user)
    if not card:
        return utils.create_404_json_response("Card")

    retrieval_attempt = RetrievalAttempt.from_id(retrieval_attempt_id)
    if not retrieval_attempt:
        return utils.create_404_json_response("RetrievalAttempt")

    if retrieval_attempt.card != card:
        message = "RetrievalAttempt exists but does not belong to specified card"
        return utils.create_400_json_response(message)

    if request.method == 'GET':
        return get_card_retrieval_attempt(request, retrieval_attempt)

    else:
        return utils.create_405_json_response(allow="GET")
Exemplo n.º 7
0
def process_request(request, card_uuid, file_id):
    if not request.user.is_authenticated:
        return utils.create_401_json_response()

    card = Card.from_uuid(card_uuid, request.user)
    if not card:
        return utils.create_404_json_response("Card")

    file_attachment = FileAttachment.from_id(file_id)
    if not file_attachment:
        return utils.create_404_json_response("File")

    if file_attachment.card != card:
        message = "File exists but does not belong to the specified card"
        return JsonResponse({'message': message}, status=400)

    if request.method == 'GET':
        return get_card_file_attachment(request, file_attachment)

    elif request.method == 'DELETE':
        return delete_card_file_attachment(request, file_attachment)

    else:
        return utils.create_405_json_response(allow="GET, DELETE")
Exemplo n.º 8
0
def process_request(request, card_uuid, tag_id):
    if not request.user.is_authenticated:
        return utils.create_401_json_response()

    card = Card.from_uuid(card_uuid, request.user)
    if not card:
        return utils.create_404_json_response("Card")

    tag = None
    tag_id = int(tag_id)

    for card_tag in card.tags.all():
        if card_tag.id == tag_id:
            tag = card_tag
            break

    if not tag:
        return utils.create_404_json_response("Tag")

    if request.method == 'DELETE':
        return delete_card_tag(request, card, tag)

    else:
        return utils.create_405_json_response(allow="DELETE")
Exemplo n.º 9
0
def process_request(request):
    if request.method == 'POST':
        return advance_review_date(request)

    else:
        return utils.create_405_json_response(allow="POST")
Exemplo n.º 10
0
def process_request(request):
    if request.method == 'POST':
        return new_login(request)

    else:
        return utils.create_405_json_response(allow="POST")