Ejemplo n.º 1
0
Archivo: views.py Proyecto: nloncke/tex
def course(request):
    from utils import search_by_course, validate_course
    from search.models import get_offers, get_auctions
    if request.method == "POST":
        course = request.POST.get("search_input","0")
        course = course.lstrip()
        course = course.rstrip()
        if validate_course(course=course):
            result = search_by_course(query=course)
            if result["books"]:
                result["query"] = course
                result["search_length"] = len(result["books"])
                for book in result["books"]:
                    offer = sorted(get_offers(book["isbn"]), key=(lambda x:x["buy_price"]))
                    if offer:
                        book["min_offer"] = offer[0]["buy_price"]
                    auction = sorted(get_auctions(book["isbn"]), key=(lambda y:y["current_price"])) 
                    if auction:
                        book["min_auction"] = auction[0]["current_price"]
                
                return render(request, 'search_results.html', result)
            else:
                return render(request, 'search_empty_prompt.html', {"query": course})
        else:
            return render(request, 'search_empty_prompt.html', {"query": course})
    return render(request, 'error_page.html')       
Ejemplo n.º 2
0
def course(request):
    from utils import search_by_course, validate_course
    from search.models import get_offers, get_auctions
    if request.method == "POST":
        course = request.POST.get("search_input", "0")
        course = course.lstrip()
        course = course.rstrip()
        if validate_course(course=course):
            result = search_by_course(query=course)
            if result["books"]:
                result["query"] = course
                result["search_length"] = len(result["books"])
                for book in result["books"]:
                    offer = sorted(get_offers(book["isbn"]),
                                   key=(lambda x: x["buy_price"]))
                    if offer:
                        book["min_offer"] = offer[0]["buy_price"]
                    auction = sorted(get_auctions(book["isbn"]),
                                     key=(lambda y: y["current_price"]))
                    if auction:
                        book["min_auction"] = auction[0]["current_price"]

                return render(request, 'search_results.html', result)
            else:
                return render(request, 'search_empty_prompt.html',
                              {"query": course})
        else:
            return render(request, 'search_empty_prompt.html',
                          {"query": course})
    return render(request, 'error_page.html')
Ejemplo n.º 3
0
Archivo: views.py Proyecto: nloncke/tex
def isbn(request):
    from utils import search_by_isbn, validate_isbn, convert_to_13
    from search.models import get_offers, get_auctions
    if request.method == "POST":
        isbn = request.POST.get("search_input","0")
        isbn = isbn.lstrip()
        isbn = isbn.rstrip()
        if validate_isbn(isbn=isbn):
            isbn = re.sub("[^0-9Xx]", "", isbn)
            isbn = convert_to_13(isbn=isbn)
            result = search_by_isbn(query=isbn)
            if result["books"]:
                result["query"] = isbn
                result["search_length"] = len(result["books"])
                for book in result["books"]:
                    offer = sorted(get_offers(book["isbn"]), key=(lambda x:x["buy_price"]))
                    if offer:
                        book["min_offer"] = offer[0]["buy_price"]
                    auction = sorted(get_auctions(book["isbn"]), key=(lambda y:y["current_price"])) 
                    if auction:
                        book["min_auction"] = auction[0]["current_price"]
                
                return render(request, 'search_results.html', result)
            else:
                return render(request, 'search_empty.html', {"query": isbn})
        else:
            return render(request, 'search_empty.html', {"query": isbn})
    return render(request, 'error_page.html')    
Ejemplo n.º 4
0
def isbn(request):
    from utils import search_by_isbn, validate_isbn, convert_to_13
    from search.models import get_offers, get_auctions
    if request.method == "POST":
        isbn = request.POST.get("search_input", "0")
        isbn = isbn.lstrip()
        isbn = isbn.rstrip()
        if validate_isbn(isbn=isbn):
            isbn = re.sub("[^0-9Xx]", "", isbn)
            isbn = convert_to_13(isbn=isbn)
            result = search_by_isbn(query=isbn)
            if result["books"]:
                result["query"] = isbn
                result["search_length"] = len(result["books"])
                for book in result["books"]:
                    offer = sorted(get_offers(book["isbn"]),
                                   key=(lambda x: x["buy_price"]))
                    if offer:
                        book["min_offer"] = offer[0]["buy_price"]
                    auction = sorted(get_auctions(book["isbn"]),
                                     key=(lambda y: y["current_price"]))
                    if auction:
                        book["min_auction"] = auction[0]["current_price"]

                return render(request, 'search_results.html', result)
            else:
                return render(request, 'search_empty.html', {"query": isbn})
        else:
            return render(request, 'search_empty.html', {"query": isbn})
    return render(request, 'error_page.html')