Beispiel #1
0
def input_link(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 = InputLink(request.POST)
        if form.is_valid():
            try:
                # retrieve drive order and list URL from request
                drive_order, fuzzy_search = retrieve_search_settings(request)
                if drive_order is None or fuzzy_search is None:
                    return redirect("index")
                url = form["list_url"].value()

                # parse the link input to obtain the order dict and quantity in this order
                order = MPCOrder()
                qty = order.from_link(url)

                # build context
                context = build_context(drive_order, fuzzy_search,
                                        order.to_dict(), 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")
Beispiel #2
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:
                # retrieve drive order and XML file from request
                drive_order, fuzzy_search = retrieve_search_settings(request)
                if drive_order is None or fuzzy_search is None:
                    return redirect("index")
                xmlfile = request.FILES["file"].read()

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

                # build context
                context = build_context(drive_order, fuzzy_search,
                                        order.to_dict(), 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")
Beispiel #3
0
def search_individual(request):
    # search endpoint function - the frontend requests the search results for this query as JSON
    drive_order, fuzzy_search = retrieve_search_settings(request)
    if drive_order is not None and fuzzy_search is not None:
        query = request.POST.get("query").rstrip("\n")
        req_type = request.POST.get("req_type")

        return JsonResponse(search(drive_order, fuzzy_search, query, req_type))

    # if drive order or fuzzy search can't be determined from the given request, return an
    # empty JsonResponse and the frontend will handle it (views should always return a response)
    return JsonResponse({})
Beispiel #4
0
def search_multiple(request):
    # search endpoint function - the frontend requests the search results for this query as JSON
    drive_order, fuzzy_search = retrieve_search_settings(request)
    if drive_order is not None and fuzzy_search is not None:
        order = MPCOrder()
        order.from_json(json.loads(request.POST.get("order")))

        for face in Faces.FACES.value:
            for item in order[face].values():
                result = search(drive_order, fuzzy_search, item.query,
                                item.req_type)
                item.insert_data(result)
        result = search(drive_order, fuzzy_search, order.cardback.query,
                        order.cardback.req_type)
        order.cardback.insert_data(result)
        return JsonResponse(order.to_dict())

    # if drive order or fuzzy search can't be determined from the given request, return an
    # empty JsonResponse and the frontend will handle it (views should always return a response)
    return JsonResponse({})
Beispiel #5
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():
            # retrieve drive order and csv file from request
            drive_order, fuzzy_search = retrieve_search_settings(request)
            if drive_order is None or fuzzy_search is None:
                return redirect("index")
            csvfile = request.FILES["file"].read()

            # parse the csv file to obtain the order dict and quantity in this order
            order = MPCOrder()
            qty = order.from_csv(csvfile)

            # build context
            context = build_context(drive_order, fuzzy_search, order.to_dict(),
                                    qty)

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

    return redirect("index")
Beispiel #6
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
    if request.method == "POST":
        form = InputText(request.POST)
        if form.is_valid():
            # retrieve drive order and raw user input from request
            drive_order, fuzzy_search = retrieve_search_settings(request)
            if drive_order is None or fuzzy_search is None:
                return redirect("index")
            lines_raw = form["card_list"].value()

            # parse the text input to obtain the order dict and quantity in this order
            order = MPCOrder()
            qty = order.from_text(lines_raw)

            # build context
            context = build_context(drive_order, fuzzy_search, order.to_dict(),
                                    qty)

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

    return redirect("index")