def sell_edit_submit(request): from buy.models import edit_offer, edit_auction result = {} if request.method == 'POST': isbn = request.POST.get("target_isbn", "0") if validate_isbn(isbn=isbn): is_auction = request.POST.get("is_auction", "") offer_id = request.POST.get("offer_id", "0") course = request.POST.get("course", "0") condition = request.POST.get("picked_condition", "0") description = request.POST.get("description", "0") if is_auction: auction_id=offer_id edit_auction(auction_id=auction_id, course=course, condition=condition, description=description) else: price = request.POST.get("price" , "0") edit_offer(offer_id=offer_id, price=price, course=course, condition=condition, description=description) result["offer_id"] = offer_id result["is_auction"] = is_auction result["isbn"] = isbn return render(request, 'sell_submit.html', result) else: return render(request, "error_page.html") else: return render(request, "error_page.html")
def book_index(request): from account.models import get_follow_list from utils import get_book user = request.user result = {} i = 0 if request.method == "POST": from sell.utils import get_book_info from account.models import follow, unfollow action = request.POST.get("book_action", "") isbn = request.POST.get("target_isbn", "0") isbn = convert_to_13(isbn=isbn) if validate_isbn(isbn): if action == "follow": follow_isbns = get_follow_list(user=user) for follow_isbn in follow_isbns: if follow_isbn != isbn: i = i + 1 if i == len(follow_isbns): follow(user=user, isbn=isbn) elif action == "unfollow": unfollow(user=user, isbn=isbn) else: return render(request, 'error_page.html') else: isbn = request.GET.get("isbn", "0") isbn = convert_to_13(isbn=isbn) if validate_isbn(isbn=isbn): result = get_book(isbn=isbn) follow_isbns = get_follow_list(user=user) for follow_isbn in follow_isbns: if follow_isbn: if follow_isbn == isbn: result["is_follow"] = "true" return render(request, 'book_index.html', result) return render(request, 'error_page.html')
def book_index(request): from account.models import get_follow_list from utils import get_book user = request.user result = {} i = 0 if request.method == "POST": from sell.utils import get_book_info from account.models import follow, unfollow action = request.POST.get("book_action","") isbn = request.POST.get("target_isbn", "0") isbn = convert_to_13(isbn=isbn) if validate_isbn(isbn): if action == "follow": follow_isbns = get_follow_list(user=user) for follow_isbn in follow_isbns: if follow_isbn != isbn: i = i + 1 if i == len(follow_isbns): follow(user=user, isbn=isbn) elif action == "unfollow": unfollow(user=user, isbn=isbn) else: return render(request, 'error_page.html') else: isbn = request.GET.get("isbn","0") isbn = convert_to_13(isbn=isbn) if validate_isbn(isbn=isbn): result = get_book(isbn=isbn) follow_isbns = get_follow_list(user=user) for follow_isbn in follow_isbns: if follow_isbn: if follow_isbn == isbn: result["is_follow"] = "true" return render(request, 'book_index.html', result) return render(request, 'error_page.html')
def add(request): from search.utils import search_by_isbn result = {} if request.method == 'GET': isbn = request.GET.get("isbn", "0") isbn = isbn.lstrip() isbn = isbn.rstrip() if validate_isbn(isbn=isbn): isbn = re.sub("[^0-9Xx]", "", isbn) isbn = convert_to_13(isbn=isbn) results = search_by_isbn(isbn)["books"] if results: return book_index(request) return render(request, 'search_empty.html', {"query": isbn}) return render(request, "error_page.html")
def add(request): from search.utils import search_by_isbn result = {} if request.method == 'GET': isbn = request.GET.get("isbn","0") isbn = isbn.lstrip() isbn = isbn.rstrip() if validate_isbn(isbn=isbn): isbn = re.sub("[^0-9Xx]", "", isbn) isbn = convert_to_13(isbn=isbn) results = search_by_isbn(isbn)["books"] if results: return book_index(request) return render(request, 'search_empty.html', {"query": isbn}) return render(request, "error_page.html")
def sell_form(request): from search.utils import search_by_isbn from book.utils import add_links result = {} if request.method == 'GET': isbn = request.GET.get("isbn","0") isbn = isbn.lstrip() isbn = isbn.rstrip() if validate_isbn(isbn=isbn): isbn = re.sub("[^0-9Xx]", "", isbn) isbn = convert_to_13(isbn=isbn) results = search_by_isbn(query=isbn, thumb=False)["books"] if results: result["book"] = results[0] add_links(result["book"]) return render(request, 'sell_form.html', result) return render(request, 'search_empty.html', {"query": isbn}) return render(request, "error_page.html")
def account_index(request): from account.models import get_seller_offers, get_seller_auctions, get_follow_list, unfollow, save_user from buy.models import remove_offer, remove_auction from sell.utils import get_book_info from book.utils import get_book from search.utils import validate_isbn # only post if removing offer if request.method == "POST": action = request.POST.get("action", "") if action == "remove_offer": offer_id = request.POST.get("offer_id", "0") remove_offer(offer_id=offer_id) elif action == "unfollow": isbn = request.POST.get("target_isbn", "0") user = request.user if validate_isbn(isbn=isbn): unfollow(user=user, isbn=isbn) elif action == "update": info = {"class_year": request.POST.get("class_year")} info["default_search"] = request.POST.get("default_search") save_user(request.user, **info) else: return render(request, 'error_page.html') result_offers = [] result_auctions = [] result_follow = [] seller_id = request.user.username user = request.user seller_offers = get_seller_offers(seller_id=seller_id) offers = {} for seller_offer in seller_offers: book_info = get_book_info(isbn=seller_offer.isbn)["book"] result_offers.append({"title":book_info["title"], "price":seller_offer.price, "offer_id":seller_offer.id, "isbn":seller_offer.isbn}) seller_auctions = get_seller_auctions(seller_id=seller_id) auctions = {} for seller_auction in seller_auctions: book_info = get_book_info(isbn=seller_auction.isbn)["book"] result_auctions.append({"title":book_info["title"], "current_price":seller_auction.current_price, "auction_id":seller_auction.id, "isbn":seller_auction.isbn, "end_time":seller_auction.end_time}) follow_isbns = get_follow_list(user=user) for isbn in follow_isbns: min_offer = {} min_auction = {} if isbn: book_info = get_book(isbn=isbn) offers = book_info["offers"] auctions = book_info["auctions"] if offers: min_offer = offers[0] if auctions: min_auction = auctions[0] result_follow.append({"isbn":isbn, "book":book_info["book"], "min_offer":min_offer, "min_auction":min_auction}) else: pass return render(request,'account_index.html', {"offers":result_offers, "auctions":result_auctions, "follows":result_follow})