def test_sort_asc(self): h = list(Transaction.objects.filter(sender=self.allenProfile).order_by('-dateTraded')) bob_h = list(Transaction.objects.filter(sender=self.bobProfile).order_by('-dateTraded')) h.extend(bob_h) print "\n*** Unsorted List ***" for i in h: print str(i.sender.user) + "\t" + str(i.dateTraded) sort.sort(h, 'dateTraded', "asc") print "\n*** Asc Sorted List ***" for i in h: print str(i.sender.user) + "\t" + str(i.dateTraded) self.assertFalse(0) # True = see print stmts
def account_management(request): listing_dict = {} accepted_offer_dict = {} userprofiler = request.user.get_profile() current_listings = list( Currentlist.objects.filter(user=request.user.get_profile(), status="open").order_by("-datePosted") ) for idx, listing in enumerate(current_listings): listing_dict[listing] = list(Transaction.objects.filter(status="offered", current_listing=listing)) try: accepted_offer_dict[listing] = Transaction.objects.get(status="accepted", current_listing=listing) except Transaction.DoesNotExist: accepted_offer_dict[listing] = [] current_offers = list(Transaction.objects.filter(status="offered", sender=request.user.get_profile())) current_offers_deferred = list(Transaction.objects.filter(status="deferred", sender=request.user.get_profile())) current_offers_accepted = list(Transaction.objects.filter(status="accepted", sender=request.user.get_profile())) current_offers.extend(current_offers_deferred) current_offers.extend(current_offers_accepted) sort.sort(current_offers, "dateRequested", "desc") wishlist = list(Wishlist.objects.filter(user=request.user.get_profile())) hist = list(Transaction.objects.filter(status="confirmed", sender=request.user.get_profile())) hist_listings = Currentlist.objects.filter(user=request.user.get_profile(), status="closed") for listing in hist_listings: hist_as_receiver = list(Transaction.objects.filter(status="confirmed", current_listing=listing)) hist.extend(hist_as_receiver) sort.sort(hist, "dateTraded", "desc") return render( request, "users/account_management.html", { "current_listings": current_listings, "wishlist": wishlist, "history": hist, "listing_dict": listing_dict, "username": request.user.username, "current_offers": current_offers, "userprofiler": userprofiler, "accepted_offer_dict": accepted_offer_dict, }, )
def account_management(request): listing_dict = {} accepted_offer_dict = {} userprofiler = request.user.get_profile() current_listings = list(Currentlist.objects.filter(user = request.user.get_profile(), status = 'open').order_by('-datePosted')) for idx, listing in enumerate(current_listings): listing_dict[listing] = list(Transaction.objects.filter(status = 'offered', current_listing = listing)) try: accepted_offer_dict[listing] = Transaction.objects.get(status = 'accepted', current_listing = listing) except Transaction.DoesNotExist: accepted_offer_dict[listing] = [] current_offers = list(Transaction.objects.filter(status = 'offered', sender = request.user.get_profile())) current_offers_deferred = list(Transaction.objects.filter(status = 'deferred', sender = request.user.get_profile())) current_offers_accepted = list(Transaction.objects.filter(status = 'accepted', sender = request.user.get_profile())) current_offers.extend(current_offers_deferred) current_offers.extend(current_offers_accepted) sort.sort(current_offers, 'dateRequested', "desc") wishlist = list(Wishlist.objects.filter(user = request.user.get_profile())) hist = list(Transaction.objects.filter(status = 'confirmed', sender = request.user.get_profile())) hist_listings = Currentlist.objects.filter(user = request.user.get_profile(), status = 'closed') for listing in hist_listings: hist_as_receiver = list(Transaction.objects.filter(status = 'confirmed', current_listing = listing)) hist.extend(hist_as_receiver) sort.sort(hist, 'dateTraded', "desc") return render(request, 'users/account_management.html', { 'current_listings': current_listings, 'wishlist': wishlist, 'history': hist, 'listing_dict': listing_dict, 'username': request.user.username, 'current_offers': current_offers, 'userprofiler': userprofiler, 'accepted_offer_dict':accepted_offer_dict })