Exemplo n.º 1
0
def insert_text(request):
    # return a JSON response with the order dict and quantity from parsing the given input
    # used for inserting new cards into an existing order on the review page
    text = request.POST.get('text')
    offset = int(request.POST.get('offset'))

    # parse the text input to obtain the order dict and quantity in this addition to the order
    (order, qty) = parse_text(text, offset)

    # remove the "-" element from the common cardback slot list so the selected common cardback doesn't reset on us
    order["back"][""]["slots"].pop(0)

    # build context
    context = {
        "order": order,
        "qty": qty,
    }

    return JsonResponse(context)
Exemplo n.º 2
0
def review(request):
    # return the review page with the order dict and quantity from parsing the given text input as context
    # used for rendering the review page

    # TODO: rename this to input_text?
    if request.method == "POST":
        form = InputText(request.POST)
        if form.is_valid():
            print("Request is valid for text uploader")
            # retrieve drive order and raw user input from request
            drive_order = list(request.POST.get("drive_order").split(","))
            lines_raw = form['card_list'].value()

            # parse the text input to obtain the order dict and quantity in this order
            (order, qty) = parse_text(lines_raw)

            # build context
            context = build_context(drive_order, order, qty)

            return render(request, 'cardpicker/review.html', context)

    return redirect('index')