Exemplo n.º 1
0
def input_xml(request):
    # return the review page with the order dict and quantity from parsing the given XML input as context
    # used for rendering the review page
    if request.method == "POST":
        form = InputXML(request.POST, request.FILES)
        if form.is_valid():
            try:
                print("Request is valid for XML uploader")

                # retrieve drive order and XML file from request
                drive_order = list(request.POST.get("drive_order").split(","))
                xmlfile = request.FILES['file'].read()

                # parse the XML file to obtain the order dict and quantity in this order
                (order, qty) = parse_xml(xmlfile, 0)

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

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

            except IndexError:
                # IndexErrors can occur when trying to parse old XMLs that don't include the search query
                return redirect('index')

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

    # parse the XML input to obtain the order dict and quantity in this addition to the order
    (order, qty) = parse_xml(xml, 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)