def update_description(request, offset): context_instance = RequestContext(request) try: queryset_product = Product.objects.get(id=offset) queryset_auction = Auction.getAuctionByProductID(offset) if queryset_product.seller_id == request.user.pk: if request.method == 'POST' and request.POST.get('update'): product_form = ProductUpdateForm(request.POST or None) product_form.fields[ "description"].queryset = queryset_product.description if product_form.is_valid(): queryset_product.description = request.POST.get( 'description') queryset_product.save(update_fields=['description']) queryset_auction.save(update_fields=['updated_time']) messages.success(request, "Product description is updated!") return HttpResponseRedirect('/myauction/') else: messages.error(request, "Description field is required!") return HttpResponseRedirect('/updatedescr/%s' % offset) else: product_form = ProductUpdateForm() else: messages.error(request, "No privilege to edit/update the data!") return HttpResponseRedirect('/index/') context = {'form': product_form} return render_to_response('updatedescr.html', context, context_instance) except Auction.DoesNotExist: raise Http404
def ban_auction(request, id): try: queryset = Auction.getAuctionByID(id) if request.method == 'POST' and request.POST.get('ban'): if queryset and queryset.status_id == 1: queryset_bids = AuctionBidder.objects.filter( auc=queryset).count() queryset.status_id = 2 queryset.save(update_fields=['status_id']) email_list = [] if queryset_bids > 0: email_list = getBiddersEmail(queryset) email_list.append(queryset.product.seller.email) emailer(str(email_list), "ban", queryset.title) messages.info( request, "Auction banned, seller and bidder/s are notified with email." ) return HttpResponseRedirect('/index/') else: messages.info(request, "You can not proceed.") return HttpResponseRedirect('/index/') else: messages.info(request, "Something is not right. Try again.") return HttpResponseRedirect('/index/') except Auction.DoesNotExist: raise Http404
def update_description(request, offset): context_instance = RequestContext(request) try: queryset_product = Product.objects.get(id=offset) queryset_auction = Auction.getAuctionByProductID(offset) if queryset_product.seller_id == request.user.pk: if request.method == 'POST' and request.POST.get('update'): product_form = ProductUpdateForm(request.POST or None) product_form.fields["description"].queryset = queryset_product.description if product_form.is_valid(): queryset_product.description = request.POST.get('description') queryset_product.save(update_fields=['description']) queryset_auction.save(update_fields=['updated_time']) messages.success(request, "Product description is updated!") return HttpResponseRedirect('/myauction/') else: messages.error(request, "Description field is required!") return HttpResponseRedirect('/updatedescr/%s' % offset) else: product_form = ProductUpdateForm() else: messages.error(request, "No privilege to edit/update the data!") return HttpResponseRedirect('/index/') context = {'form': product_form} return render_to_response('updatedescr.html', context, context_instance) except Auction.DoesNotExist: raise Http404
def ban_auction(request, id): try: queryset = Auction.getAuctionByID(id) if request.method == 'POST' and request.POST.get('ban'): if queryset and queryset.status_id == 1: queryset_bids = AuctionBidder.objects.filter(auc=queryset).count() queryset.status_id = 2 queryset.save(update_fields=['status_id']) email_list = [] if queryset_bids > 0: email_list = getBiddersEmail(queryset) email_list.append(queryset.product.seller.email) emailer(str(email_list), "ban", queryset.title) messages.info(request, "Auction banned, seller and bidder/s are notified with email.") return HttpResponseRedirect('/index/') else: messages.info(request, "You can not proceed.") return HttpResponseRedirect('/index/') else: messages.info(request, "Something is not right. Try again.") return HttpResponseRedirect('/index/') except Auction.DoesNotExist: raise Http404
def get_context_data(self, **kwargs): context = super(HomeView, self).get_context_data(**kwargs) try: context['auctions'] = Auction.fetchActiveAuctions() return context except Auction.DoesNotExist: raise Http404
def list_auction(request): context_instance = RequestContext(request) try: queryset = Auction.fetchActiveAuctions() context = {'auctions': queryset, } return render_to_response("index.html", context, context_instance) except Product.DoesNotExist: raise Http404
def list_auction(request): context_instance = RequestContext(request) try: queryset = Auction.fetchActiveAuctions() context = { 'auctions': queryset, } return render_to_response("index.html", context, context_instance) except Product.DoesNotExist: raise Http404
def list_auc_category(request, offset): # Fetch all auctions and display to users context_instance = RequestContext(request) try: if offset is not None: queryset = Auction.getAuctionByCategory(offset) if queryset: context = {'auctcategory': queryset, } return render_to_response("listauccat.html", context, context_instance) raise Http404 except Product.DoesNotExist: raise Http404
def list_own_auction(request): context_instance = RequestContext(request) success = None if request.user: queryset = Auction.getAuctionByOwner(request.user.id) if queryset: success = True return render_to_response("myauction.html", { 'myauctions': queryset, 'display': success }, context_instance) else: messages.info(request, "No Auction found.") context = {'display': success} return render_to_response("myauction.html", context, context_instance)
def list_auc_category(request, offset): # Fetch all auctions and display to users context_instance = RequestContext(request) try: if offset is not None: queryset = Auction.getAuctionByCategory(offset) if queryset: context = { 'auctcategory': queryset, } return render_to_response("listauccat.html", context, context_instance) raise Http404 except Product.DoesNotExist: raise Http404
def list_own_auction(request): context_instance = RequestContext(request) success = None if request.user: queryset = Auction.getAuctionByOwner(request.user.id) if queryset: success = True return render_to_response("myauction.html", {'myauctions': queryset, 'display': success}, context_instance) else: messages.info(request, "No Auction found.") context = {'display': success} return render_to_response("myauction.html", context, context_instance)
def search_auction(request): context_instance = RequestContext(request) success = False if request.method == 'POST' and request.POST.get('search'): keytitle = request.POST.get('keytitle') if len(keytitle): aucfound = Auction.fetchActiveAuctions().filter(title__icontains=keytitle) if aucfound: success = True messages.success(request, 'The following auction/s found.') return render_to_response('search.html', {'auc': aucfound, 'display': success}, context_instance) else: messages.info(request, 'No search result found.') return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) else: messages.error(request, 'No auction title provided on the search field!') return render_to_response('search.html', {'display': success}, context_instance)
def auction_detail(request, id): context_instance = RequestContext(request) success = None try: queryset = Auction.getAuctionByID(id) if queryset: queryset_bids = AuctionBidder.objects.filter(auc=queryset) if queryset_bids: success = True num_of_bids = AuctionBidder.objects.filter(auc=queryset).values_list('unique_bidder', flat=True).distinct().count() context = {'singleauction': queryset, 'current_price': queryset.current_price, 'bidders': queryset_bids, 'numofbids': num_of_bids, 'display': success} return render_to_response("aucdetail.html", context, context_instance) except Auction.DoesNotExist: raise Http404
def auction_detail(request, id): context_instance = RequestContext(request) success = None try: queryset = Auction.getAuctionByID(id) if queryset: queryset_bids = AuctionBidder.objects.filter(auc=queryset) if queryset_bids: success = True num_of_bids = AuctionBidder.objects.filter( auc=queryset).values_list('unique_bidder', flat=True).distinct().count() context = { 'singleauction': queryset, 'current_price': queryset.current_price, 'bidders': queryset_bids, 'numofbids': num_of_bids, 'display': success } return render_to_response("aucdetail.html", context, context_instance) except Auction.DoesNotExist: raise Http404
def search_auction(request): context_instance = RequestContext(request) success = False if request.method == 'POST' and request.POST.get('search'): keytitle = request.POST.get('keytitle') if len(keytitle): aucfound = Auction.fetchActiveAuctions().filter( title__icontains=keytitle) if aucfound: success = True messages.success(request, 'The following auction/s found.') return render_to_response('search.html', { 'auc': aucfound, 'display': success }, context_instance) else: messages.info(request, 'No search result found.') return HttpResponseRedirect( request.META.get('HTTP_REFERER', '/')) else: messages.error(request, 'No auction title provided on the search field!') return render_to_response('search.html', {'display': success}, context_instance)
def bid_on_auction(request, offset): context_instance = RequestContext(request) try: query_auction = Auction.getAuctionByID(offset) seller = Auction.getOwnerByAuctionID(offset) placebid = AuctionBidderForm(request.POST) if request.user == seller: messages.info(request, _('You can not bid on your item.')) return HttpResponseRedirect('/myauction/') else: if request.method == 'POST' and request.POST.get('placebid'): if query_auction: if placebid.is_valid(): new_auc_bid = placebid.save(commit=False) initial_price = float( query_auction.product.initial_price) current_price = float(query_auction.current_price) bid_amount = float(request.POST.get('bid_amount', '')) # Amount should be greater than the initial price or the current highest bid by [0.01 min] if (bid_amount > initial_price + 0.01) and ( bid_amount > current_price + 0.01): new_auc_bid.auc = query_auction current_highest = query_auction.current_price email_list = [] try: bid_counter = AuctionBidder.objects.filter( auc=query_auction).count() # Check if any bidders found for this auction if bid_counter > 0: last_bidder = AuctionBidder.objects.get( auc=query_auction, bid_amount=current_highest) if str(request.user) == str( last_bidder.unique_bidder): messages.error( request, "You do not need to bid....you are winning anyways!" ) redirect_url = reverse( 'aucdetail', args=[new_auc_bid.auc.id]) return HttpResponseRedirect( redirect_url) if str(request.user) != str( last_bidder.unique_bidder): email_list = getBiddersEmail( query_auction) bidder = Bidder.objects.create( contender=request.user) new_auc_bid.auc = query_auction new_auc_bid.bidder = bidder new_auc_bid.unique_bidder = bidder query_auction.current_price = bid_amount # Update the highest bid amount query_auction.save( update_fields=['current_price']) new_auc_bid = placebid.save() # get emails as list which are bidding on the same # auction and then append the seller email to the list email = request.user.email if email not in email_list: email_list.append(email) email_list.append(seller.email) emailer(str(email_list), "mass", new_auc_bid.auc) messages.success(request, "Thank you for Bidding!") if soft_deadline( new_auc_bid.bid_time, query_auction.end_time ): # extend last 5 min of the auc query_auction.end_time = query_auction.end_time + timedelta( 0, 300) query_auction.save( update_fields=['end_time']) redirect_url = reverse( 'aucdetail', args=[new_auc_bid.auc.id]) return HttpResponseRedirect(redirect_url) except AuctionBidder.DoesNotExist: raise Http404 else: messages.error( request, "Bid amount should be at least +0.01 " "of the initial price or highest bid amount!") redirect_url = reverse('aucdetail', args=[query_auction.id]) return HttpResponseRedirect(redirect_url) else: messages.error( request, "Invalid data. Please enter the correct amount!") redirect_url = reverse('aucdetail', args=[query_auction.id]) return HttpResponseRedirect(redirect_url) else: messages.info(request, 'No Auction found for bidding.') else: placebid = AuctionBidderForm() context = {'singleauction': query_auction, 'form': placebid} return render_to_response("aucdetail.html", context, context_instance) except Auction.DoesNotExist: raise Http404
def bid_on_auction(request, offset): context_instance = RequestContext(request) try: query_auction = Auction.getAuctionByID(offset) seller = Auction.getOwnerByAuctionID(offset) placebid = AuctionBidderForm(request.POST) if request.user == seller: messages.info(request, _('You can not bid on your item.')) return HttpResponseRedirect('/myauction/') else: if request.method == 'POST' and request.POST.get('placebid'): if query_auction: if placebid.is_valid(): new_auc_bid = placebid.save(commit=False) initial_price = float(query_auction.product.initial_price) current_price = float(query_auction.current_price) bid_amount = float(request.POST.get('bid_amount', '')) # Amount should be greater than the initial price or the current highest bid by [0.01 min] if (bid_amount > initial_price + 0.01) and (bid_amount > current_price + 0.01): new_auc_bid.auc = query_auction current_highest = query_auction.current_price email_list = [] try: bid_counter = AuctionBidder.objects.filter(auc=query_auction).count() # Check if any bidders found for this auction if bid_counter > 0: last_bidder = AuctionBidder.objects.get(auc=query_auction, bid_amount=current_highest) if str(request.user) == str(last_bidder.unique_bidder): messages.error(request, "You do not need to bid....you are winning anyways!") redirect_url = reverse('aucdetail', args=[new_auc_bid.auc.id]) return HttpResponseRedirect(redirect_url) if str(request.user) != str(last_bidder.unique_bidder): email_list = getBiddersEmail(query_auction) bidder = Bidder.objects.create(contender=request.user) new_auc_bid.auc = query_auction new_auc_bid.bidder = bidder new_auc_bid.unique_bidder = bidder query_auction.current_price = bid_amount # Update the highest bid amount query_auction.save(update_fields=['current_price']) new_auc_bid = placebid.save() # get emails as list which are bidding on the same # auction and then append the seller email to the list email = request.user.email if email not in email_list: email_list.append(email) email_list.append(seller.email) emailer(str(email_list), "mass", new_auc_bid.auc) messages.success(request, "Thank you for Bidding!") if soft_deadline(new_auc_bid.bid_time, query_auction.end_time): # extend last 5 min of the auc query_auction.end_time = query_auction.end_time + timedelta(0, 300) query_auction.save(update_fields=['end_time']) redirect_url = reverse('aucdetail', args=[new_auc_bid.auc.id]) return HttpResponseRedirect(redirect_url) except AuctionBidder.DoesNotExist: raise Http404 else: messages.error(request, "Bid amount should be at least +0.01 " "of the initial price or highest bid amount!") redirect_url = reverse('aucdetail', args=[query_auction.id]) return HttpResponseRedirect(redirect_url) else: messages.error(request, "Invalid data. Please enter the correct amount!") redirect_url = reverse('aucdetail', args=[query_auction.id]) return HttpResponseRedirect(redirect_url) else: messages.info(request, 'No Auction found for bidding.') else: placebid = AuctionBidderForm() context = {'singleauction': query_auction, 'form': placebid} return render_to_response("aucdetail.html", context, context_instance) except Auction.DoesNotExist: raise Http404