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")
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")
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({})
def insert_link(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 list_url = request.POST.get("list_url") offset = request.POST.get("offset") if list_url and offset: offset = int(offset) # parse the XML input to obtain the order dict and quantity in this addition to the order order = MPCOrder() qty = order.from_link(list_url, offset) # remove the - element from the common cardback slot list so the selected common cardback doesn't reset on us order.remove_common_cardback() # build context context = { "order": order.to_dict(), "qty": qty, } return JsonResponse(context) # 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({})
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")
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")