Ejemplo 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')
Ejemplo n.º 2
0
def input_csv(request):
    # return the review page with the order dict and quantity from parsing the given CSV input as context
    # used for rendering the review page
    if request.method == "POST":
        form = InputCSV(request.POST, request.FILES)
        if form.is_valid():
            print("Request is valid for CSV uploader")

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

            # parse the csv file to obtain the order dict and quantity in this order
            (order, qty) = parse_csv(csvfile)

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

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

    return redirect('index')
Ejemplo n.º 3
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')