def show_Auction(request, idItem): print idItem if Auction.exists(idItem): request.session['visited'] = request.session['visited'] + 1 nAuc = Auction.getByidItem(idItem) else: return HttpResponse("That blog doesn't exist") if '_edit' in request.POST: return HttpResponseRedirect("/yaas/editauction/" + str(nAuc.idItem) + "/") elif '_bid' in request.POST: return HttpResponseRedirect("/yaas/bid/" + str(nAuc.idItem) + "/") elif '_ban' in request.POST: return HttpResponseRedirect("/yaas/banauction/" + str(nAuc.idItem) + "/") contex = { "titleAuc": nAuc.titleAuc, "deadLine": nAuc.deadLine, "posted": nAuc.posted, "content": nAuc.content, "minPrice": nAuc.minPrice, "author": nAuc.author, "idItem": idItem } return render(request, "show.html", contex)
def show_auction(request, id): if Auction.exists(id): auction = Auction.get_by_id(id) title = auction.title description = auction.description seller = auction.seller deadline = auction.deadline last_bid = auction.last_bid last_bider = auction.last_bider status = auction.status desc_version = auction.desc_version is_seller = False if seller == request.user.username: is_seller = True is_super = False if request.user.is_superuser: is_super = True #Status to show in the template print "Status: "+status if status=="ACT": status_m="ACTIVE" elif status=="BAN": status_m="BANNED" elif status=="DUE": status_m="DUE" else: status_m="ADJUDICATED" m=request.GET.get('m','') show_msg=True message="" if m=="success": message="Bid placed succesfully! " elif m=="banned": message="The auction has been banned" elif m == "changed": message="The description of the auction has changed or your bid is not big enough. Please place your bet again." elif m == "own_act": message="You cannot bid you own auction" else: show_msg=False if request.session["lang"]=="ENG": template="auciton.html" elif request.session["lang"]=="ESP": template="auction-es.html" return render_to_response(template, dict(title=title, description=description, desc_version=desc_version, seller=seller, last_bid=last_bid, last_bider=last_bider, deadline=deadline, id=id, is_seller=is_seller, show_msg=show_msg,message=message,status=status_m,is_super=is_super), context_instance=RequestContext(request))
def ban(request,id): if request.user.is_superuser and Auction.exists(id): auction = Auction.get_by_id(id) auction.status="BAN" auction.save() return HttpResponseRedirect("/auction/"+str(auction.id)+"?m=banned") return HttpResponseRedirect("/")
def create(request): """ This function will display your creat page for new auctions """ if request.method == 'GET': return render(request, 'create.html') if request.method == 'POST': try: duration = request.POST.get('aduration') auction = Auction() auction.item_name = request.POST.get('aname') auction.description = request.POST.get('adesc') auction.list_price = price_to_cents(request.POST.get('aprice')) auction.cur_price = auction.list_price auction.owner = request.user auction.expires = duration_to_datetime(duration) auction.save() AUCTIONEER.create(auction, float(duration)) return HttpResponseRedirect(reverse('auction', args=(auction.id,))) except (TypeError, ValueError) as err: print err return render(request, 'create.html', { 'error_message': 'Invalid input types for parameters' }) except IntegrityError as err: print err return render(request, 'create.html', { 'error_message': 'You have already created an Auction by that name' }) return HttpResponse(status=500)
def edit_auction(request, idItem): if Auction.exists(idItem): auction = Auction.getByidItem(idItem) else: return HttpResponse("That item doens't exist") if request.user.username == auction.author: if auction.locked == "": # article is not locked, we lock it print "cookie:", request.session._get_or_create_session_key() auction.locked = request.session._get_or_create_session_key() auction.save() elif auction.locked != request.session._get_or_create_session_key(): # article is locked by others, we return an error message context = { "titleAuc": auction.titleAuc, "deadLine": auction.deadLine, "posted": auction.posted, "content": auction.content, "minPrice": auction.minPrice, "author": auction.author, "idItem": idItem } return render_to_response("locked.html", context) if request.method == "POST" and request.POST.has_key("content"): # a valid POST request: save the new contents of the article # Always clean the input from the user auction = Auction.getByidItem(idItem) auction.content = request.POST.get("content") auction.locked = "" auction.save() #request.session["edited"] = request.session["edited"] + 1 #contedited = request.session["edited"] # Always redirect after a successful POST request print "entra a editar" print auction.content return HttpResponseRedirect("/yaas/") else: context = { "titleAuc": auction.titleAuc, "deadLine": auction.deadLine, "posted": auction.posted, "content": auction.content, "minPrice": auction.minPrice, "author": auction.author, "idItem": idItem } return render(request, "editAuction.html", context) else: messages.add_message( request, messages.ERROR, "You are not the seller, only sellers can edit this") return HttpResponseRedirect("/yaas/")
def edit_auction(request, idItem): if Auction.exists(idItem): auction = Auction.getByidItem(idItem) else: return HttpResponse("That item doens't exist") if request.user.username == auction.author: if auction.locked=="": # article is not locked, we lock it print "cookie:",request.session._get_or_create_session_key() auction.locked=request.session._get_or_create_session_key() auction.save() elif auction.locked!=request.session._get_or_create_session_key(): # article is locked by others, we return an error message context = { "titleAuc": auction.titleAuc, "deadLine": auction.deadLine, "posted": auction.posted, "content": auction.content, "minPrice": auction.minPrice, "author": auction.author, "idItem": idItem } return render_to_response("locked.html", context) if request.method == "POST" and request.POST.has_key("content"): # a valid POST request: save the new contents of the article # Always clean the input from the user auction = Auction.getByidItem(idItem) auction.content = request.POST.get("content") auction.locked="" auction.save() #request.session["edited"] = request.session["edited"] + 1 #contedited = request.session["edited"] # Always redirect after a successful POST request print "entra a editar" print auction.content return HttpResponseRedirect("/yaas/") else: context = { "titleAuc": auction.titleAuc, "deadLine": auction.deadLine, "posted": auction.posted, "content": auction.content, "minPrice": auction.minPrice, "author": auction.author, "idItem": idItem } return render(request, "editAuction.html", context) else: messages.add_message(request, messages.ERROR, "You are not the seller, only sellers can edit this") return HttpResponseRedirect("/yaas/")
def edit_auction(request, id): if Auction.exists(id): auction = Auction.get_by_id(id) if auction.seller == request.user.username: if request.method == "POST": auction.description = request.POST["description"] auction.desc_version += 1 auction.save() return HttpResponseRedirect("/auction/" + str(auction.id)) else: return render_to_response("editauction.html", {'title': auction.title, 'description': auction.description, 'id': auction.id}, context_instance=RequestContext(request))
def ban_auction(request, idItem): print "entra al ban" if Auction.exists(idItem): #request.session['visited'] = request.session['visited'] + 1 nAuc = Auction.getByidItem(idItem) nAuc.banded = "banded" nAuc.save() from_email = '*****@*****.**' bidders = Bidders.objects.all() emailBidders = [] for bider in bidders: emailBidders.append(bider.bidderEmail) send_mail('New bid add', 'The item '+str(nAuc.titleAuc)+"has been banded", from_email , emailBidders, fail_silently=False) return HttpResponseRedirect("/yaas/")
def api_auction(request,id): auction = Auction.get_by_id(id) auction_ser = serializers.serialize('json',[auction,]) struct = json.loads(auction_ser) auction_ser = json.dumps(struct[0]) return HttpResponse(auction_ser, content_type='application/json')
def saveAucConf(request): option = request.POST.get('option') if option == "Yes": print request.POST.get('auc_DeadLine', '') auxDate1 = request.POST.get('auxDate', '') auc_DeadLine = datetime.datetime.strptime(auxDate1, "%Y-%m-%d %H:%M") auc_titleAuc = request.POST.get('auc_titleAuc', '') auc_content = request.POST.get('auc_content', '') auc_minPrice = request.POST.get('auc_minPrice', '') nAuction = Auction(titleAuc=auc_titleAuc, deadLine=auc_DeadLine, content=auc_content, minPrice=auc_minPrice) nAuction.author = request.user.username nAuction.authoremail = request.user.email nAuction.locked = "" nAuction.save() emailUser = request.user.email send_mail('Subject here', 'The auction has been created.', '*****@*****.**', [emailUser], fail_silently=False) return HttpResponseRedirect("/yaas/") elif option == "No": return HttpResponseRedirect("/yaas/createauction/")
def ban_auction(request, idItem): print "entra al ban" if Auction.exists(idItem): #request.session['visited'] = request.session['visited'] + 1 nAuc = Auction.getByidItem(idItem) nAuc.banded = "banded" nAuc.save() from_email = '*****@*****.**' bidders = Bidders.objects.all() emailBidders = [] for bider in bidders: emailBidders.append(bider.bidderEmail) send_mail('New bid add', 'The item ' + str(nAuc.titleAuc) + "has been banded", from_email, emailBidders, fail_silently=False) return HttpResponseRedirect("/yaas/")
def searchAuction(request): if request.method == 'POST': print "entra al search" aSearch= request.POST.get('search') result = Auction.objects.filter(titleAuc=aSearch) if result: nAuc = Auction.getBytitleAuc(aSearch) if nAuc.banded == "banded": messages.add_message(request, messages.INFO, "This item is banded") return render(request, "search.html") return show_Auction(request, nAuc.idItem) messages.add_message(request, messages.INFO, "This item doesn't exist") return render(request, "search.html")
def bid(request, id): if request.user.is_authenticated() and Auction.exists(id): print "Bid: "+str(request.POST["bid"]) placed_bid = round(float(request.POST["bid"]), 2) auction = Auction.get_by_id(id) print "placed_bid: "+str(placed_bid)+" last_bd: "+str(auction.last_bid)+" resta: "+str(placed_bid - float(auction.last_bid)) if auction.desc_version != int(request.POST["desc_version"]) or (placed_bid - float(auction.last_bid)) < 0.01: return HttpResponseRedirect("/auction/"+str(auction.id)+"?m=changed") elif auction.seller==request.user.username: return HttpResponseRedirect("/auction/"+str(auction.id)+"?m=own_auct") elif auction.status == "ACT": #Email to the seller seller = User.objects.get(username=auction.seller) email = EmailMessage('YAAS: Someone bid on your auction '+auction.title, 'Hello ' + seller.username + ",\n The user '" + request.user.username + "' has place a bid.", to=[seller.email]) email.send() #Email to the last bidder email = EmailMessage('YAAS: You placed a bid on '+auction.title, 'Hello ' + request.user.username + ",\n You have correctly place a bid", to=[request.user.email]) email.send() print "Las_bider: "+str(auction.last_bider) #Email to the previous bidder if auction.last_bider != "": previous_bidder = User.objects.get(username=auction.last_bider) email = EmailMessage('YAAS: Someone increased your bid on '+auction.title, 'Hello ' + request.user.username + ",\n Someone has placed a bid bigger than yours.", to=[previous_bidder.email]) email.send() auction.last_bid = placed_bid auction.last_bider = request.user.username auction.save() return HttpResponseRedirect("/auction/"+str(auction.id)+"?m=success") else: return HttpResponseRedirect("/")
def create(request): """ This function will display your creat page for new auctions """ if request.method == 'GET': return render(request, 'create.html') if request.method == 'POST': try: duration = request.POST.get('aduration') auction = Auction() auction.item_name = request.POST.get('aname') auction.description = request.POST.get('adesc') auction.list_price = price_to_cents(request.POST.get('aprice')) auction.cur_price = auction.list_price auction.owner = request.user auction.expires = duration_to_datetime(duration) auction.save() AUCTIONEER.create(auction, float(duration)) return HttpResponseRedirect(reverse('auction', args=(auction.id, ))) except (TypeError, ValueError) as err: print err return render( request, 'create.html', {'error_message': 'Invalid input types for parameters'}) except IntegrityError as err: print err return render( request, 'create.html', { 'error_message': 'You have already created an Auction by that name' }) return HttpResponse(status=500)
def add_auction(request, item_id): item = get_object_or_404(Item, pk=item_id) if request.POST: auction = Auction() auction.item = item auction.opening_bid = request.POST['opening_bid'] auction.auction_end_date = request.POST['auction_end_date'] auction.increment = request.POST['increment'] auction.save() return HttpResponseRedirect(reverse('auction:auction_detail', args=(auction.id,))) return render(request, 'add_auction.html', {'item_id': item_id})
def show_Auction(request, idItem): print idItem if Auction.exists(idItem): request.session['visited'] = request.session['visited'] + 1 nAuc = Auction.getByidItem(idItem) else: return HttpResponse("That blog doesn't exist") if '_edit' in request.POST: return HttpResponseRedirect("/yaas/editauction/"+str(nAuc.idItem)+"/") elif '_bid' in request.POST: return HttpResponseRedirect("/yaas/bid/"+str(nAuc.idItem)+"/") elif '_ban' in request.POST: return HttpResponseRedirect("/yaas/banauction/"+str(nAuc.idItem)+"/") contex = { "titleAuc": nAuc.titleAuc, "deadLine": nAuc.deadLine, "posted": nAuc.posted, "content": nAuc.content, "minPrice": nAuc.minPrice, "author": nAuc.author, "idItem": idItem } return render(request, "show.html", contex )
def searchAuction(request): if request.method == 'POST': print "entra al search" aSearch = request.POST.get('search') result = Auction.objects.filter(titleAuc=aSearch) if result: nAuc = Auction.getBytitleAuc(aSearch) if nAuc.banded == "banded": messages.add_message(request, messages.INFO, "This item is banded") return render(request, "search.html") return show_Auction(request, nAuc.idItem) messages.add_message(request, messages.INFO, "This item doesn't exist") return render(request, "search.html")
def test_one(): joao = User(name='Joao') jose = User(name='Jose') maria = User(name='Maria') auction = Auction("Playstation 3 Novo") auction.register_bid(Bid(joao, 300.0)) auction.register_bid(Bid(jose, 400.0)) auction.register_bid(Bid(maria, 250.0)) appraiser = Appraiser() appraiser.appraise(auction) expected_biggest = 400.0 expected_smallest = 250.0 assert expected_biggest == appraiser.biggest_bid assert expected_smallest == expected_smallest
def saveAucConf(request): option = request.POST.get('option') if option == "Yes": print request.POST.get('auc_DeadLine', '') auxDate1 = request.POST.get('auxDate', '') auc_DeadLine = datetime.datetime.strptime(auxDate1, "%Y-%m-%d %H:%M") auc_titleAuc = request.POST.get('auc_titleAuc', '') auc_content = request.POST.get('auc_content', '') auc_minPrice = request.POST.get('auc_minPrice', '') nAuction = Auction(titleAuc= auc_titleAuc, deadLine=auc_DeadLine, content=auc_content, minPrice=auc_minPrice) nAuction.author = request.user.username nAuction.authoremail = request.user.email nAuction.locked = "" nAuction.save() emailUser = request.user.email send_mail('Subject here', 'The auction has been created.', '*****@*****.**', [emailUser], fail_silently=False) return HttpResponseRedirect("/yaas/") elif option == "No": return HttpResponseRedirect("/yaas/createauction/")
def auction_new(request): if request.method == "POST" and request.POST.get("choice1"): getcontext().prec = 2 auction = Auction() auction.seller = request.user auction.name = request.POST["name"] auction.description = request.POST["description"] auction.priceMin = Decimal(request.POST["priceMin"]) auction.time = datetime.now() delta = int(request.POST["dateEnd"]) auction.due = datetime.now() + timedelta(hours=delta) auction.a_hash = hash(auction.name + auction.description + str(auction.due) + str(auction.priceMin) + salt) auction.banned = False auction.resolved = False # if request.user.email is not "" and request.user.email is not None: # auction.confirmation_email() auction.save() update_session_stats(request, 'auction_new') messages.add_message(request, messages.SUCCESS, "Auction created") return HttpResponseRedirect('/auction/' + str(auction.id) + '/') elif request.method == "POST": auction = Auction() auction.name = request.POST["name"] auction.description = request.POST["description"] auction.priceMin = Decimal(request.POST["priceMin"]) delta = int(request.POST["dateEnd"]) if auction.priceMin.as_tuple().exponent < -2: messages.add_message( request, messages.ERROR, "You have to give the starting price with 2 decimals.") if delta < 72: messages.add_message( request, messages.ERROR, "Auction due time must be at least 72 hours in the future.") if len(messages.get_messages(request)) > 0: return render(request, "auction_new.html", {'auction': auction}) return render(request, "auction_new_confirm.html", { 'auction': auction, 'due': delta }) else: return render(request, "auction_new.html")
def bid_auction(request, idItem): if Auction.exists(idItem): nAuc = Auction.getByidItem(idItem) #con esta linea entra al autor del objeto author = User.objects.filter(username=nAuc.author) if nAuc.locked=="":# article is not locked, we lock it print "cookie:",request.session._get_or_create_session_key() nAuc.locked=request.session._get_or_create_session_key() nAuc.save() elif nAuc.locked!=request.session._get_or_create_session_key(): # article is locked by others, we return an error message context = { "titleAuc": nAuc.titleAuc, "deadLine": nAuc.deadLine, "posted": nAuc.posted, "content": nAuc.content, "minPrice": nAuc.minPrice, "author": nAuc.author, "idItem": idItem } return render_to_response("lockedbid.html", context) if request.method == "POST" and request.POST.has_key("minPrice"): from_email = '*****@*****.**' newPrice = request.POST.get('minPrice', '') auxNew = float(newPrice) aux = nAuc.minPrice if auxNew > aux: oldBidder = nAuc.bidder newBidder = request.user.username newBidderEmail = request.user.email if newBidder != nAuc.author: if oldBidder != newBidder: oldUserEmail = nAuc.bidderemail authoremail = nAuc.authoremail nBiddeer = Bidders(bidderName=newBidder, bidderEmail= newBidderEmail, bidItem= nAuc.idItem) nBiddeer.save() nAuc.minPrice = newPrice nAuc.bidder = newBidder nAuc.bidderemail = newBidderEmail nAuc.save() bidders = Bidders.objects.all() emailBidders = [] for bider in bidders: emailBidders.append(bider.bidderEmail) send_mail('New bid add', 'A new bid has add to the item .', from_email , emailBidders, fail_silently=False) return HttpResponseRedirect("/yaas/") else: nAuc.locked ="" nAuc.save() messages.add_message(request, messages.INFO, "You are the last bidder") return HttpResponseRedirect("/yaas/") else: messages.add_message(request, messages.INFO, "The price have to be higher than"+ str(nAuc.minPrice)) return HttpResponseRedirect("/yaas/bid/"+str(nAuc.idItem)+"/") context = { "titleAuc": nAuc.titleAuc, "minPrice": nAuc.minPrice, "idItem": idItem } return render(request, "bid.html", context)
def confirm_auction(request): if request.method == "POST": if request.POST["save"] == "YES": auction = Auction() auction.title = request.POST["title"] auction.description = request.POST["description"] auction.minimun_price = round(float(request.POST["minimum_price"]), 2) deadline = datetime.strptime(request.POST["deadline"], "%d.%m.%Y_%H:%M") auction.deadline = deadline auction.last_bid = round(float(request.POST["minimum_price"]), 2) auction.status = "ACT" auction.seller = request.user.username auction.last_bider = "" auction.save() email = EmailMessage('YAAS: Auction created', 'Hello ' + request.user.username + ",\n Your auction '" + request.POST[ "title"] + "' has been succesfully created", to=[request.user.email]) email.send() return HttpResponseRedirect('/')
def load_auctions(auction_file, verbose=False): with open(auction_file, 'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Auction.objects.count() == 0: skip_lookup = True for row in reader: pin = '{:0>14}'.format(int(Decimal(row[1]))) doc = row[2].strip() date_doc = spss_to_posix(row[3]) date_rec = spss_to_posix(row[4]) reo = True if int(row[5]) == 1 else False buyer = row[6].strip() buyer_type = row[7].strip() seller = row[8].strip() seller_type = row[9].strip() try: yq_doc = int(row[10]) except: yq_doc = None try: yeard = int(row[11]) except: yeard = None apt = row[12].strip() direction = row[13].strip() houseno = row[14].strip() street = row[15].strip() suffix = row[16].strip() addr_final = row[17].strip() city_final = row[18].strip() try: lat_y = float(row[19]) except: lat_y = None try: long_x = float(row[20]) except: long_x = None try: tract_fix = float(row[21]) except: tract_fix = None no_tract_info = True if int(row[22]) == 1 else False try: ca_num = row[23] except: ca_num = None ca_name = row[24].strip() place = row[25].strip() gisdate = row[26].strip() try: ptype_id = int(row[27]) except: ptype_id = None try: residential = int(row[28]) except: residential = None try: adj_yq = int(row[29]) except: adj_yq = None try: adj_yd = int(row[30]) except: adj_yd = None loc = None if row[19] == '' else Point( (Decimal(row[20]), Decimal(row[19]))) try: if skip_lookup: raise Exception('no lookup') auction = Auction.objects.get(\ pin = pin\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,reo = reo\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) except: auction = Auction(\ pin = pin\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,reo = reo\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) auction.save()
def load_auctions(auction_file, verbose=False): with open(auction_file, "r") as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Auction.objects.count() == 0: skip_lookup = True for row in reader: pin = "{:0>14}".format(int(Decimal(row[1]))) doc = row[2].strip() date_doc = spss_to_posix(row[3]) date_rec = spss_to_posix(row[4]) reo = True if int(row[5]) == 1 else False buyer = row[6].strip() buyer_type = row[7].strip() seller = row[8].strip() seller_type = row[9].strip() try: yq_doc = int(row[10]) except: yq_doc = None try: yeard = int(row[11]) except: yeard = None apt = row[12].strip() direction = row[13].strip() houseno = row[14].strip() street = row[15].strip() suffix = row[16].strip() addr_final = row[17].strip() city_final = row[18].strip() try: lat_y = float(row[19]) except: lat_y = None try: long_x = float(row[20]) except: long_x = None try: tract_fix = float(row[21]) except: tract_fix = None no_tract_info = True if int(row[22]) == 1 else False try: ca_num = row[23] except: ca_num = None ca_name = row[24].strip() place = row[25].strip() gisdate = row[26].strip() try: ptype_id = int(row[27]) except: ptype_id = None try: residential = int(row[28]) except: residential = None try: adj_yq = int(row[29]) except: adj_yq = None try: adj_yd = int(row[30]) except: adj_yd = None loc = None if row[19] == "" else Point((Decimal(row[20]), Decimal(row[19]))) try: if skip_lookup: raise Exception("no lookup") auction = Auction.objects.get( pin=pin, doc=doc, date_doc=date_doc, date_rec=date_rec, reo=reo, buyer=buyer, buyer_type=buyer_type, seller=seller, seller_type=seller_type, yq_doc=yq_doc, yeard=yeard, apt=apt, direction=direction, houseno=houseno, street=street, suffix=suffix, addr_final=addr_final, city_final=city_final, lat_y=lat_y, long_x=long_x, tract_fix=tract_fix, no_tract_info=no_tract_info, ca_num=ca_num, ca_name=ca_name, place=place, gisdate=gisdate, ptype_id=ptype_id, residential=residential, adj_yq=adj_yq, adj_yd=adj_yd, loc=loc, ) except: auction = Auction( pin=pin, doc=doc, date_doc=date_doc, date_rec=date_rec, reo=reo, buyer=buyer, buyer_type=buyer_type, seller=seller, seller_type=seller_type, yq_doc=yq_doc, yeard=yeard, apt=apt, direction=direction, houseno=houseno, street=street, suffix=suffix, addr_final=addr_final, city_final=city_final, lat_y=lat_y, long_x=long_x, tract_fix=tract_fix, no_tract_info=no_tract_info, ca_num=ca_num, ca_name=ca_name, place=place, gisdate=gisdate, ptype_id=ptype_id, residential=residential, adj_yq=adj_yq, adj_yd=adj_yd, loc=loc, ) auction.save()
def bid_auction(request, idItem): if Auction.exists(idItem): nAuc = Auction.getByidItem(idItem) #con esta linea entra al autor del objeto author = User.objects.filter(username=nAuc.author) if nAuc.locked == "": # article is not locked, we lock it print "cookie:", request.session._get_or_create_session_key() nAuc.locked = request.session._get_or_create_session_key() nAuc.save() elif nAuc.locked != request.session._get_or_create_session_key(): # article is locked by others, we return an error message context = { "titleAuc": nAuc.titleAuc, "deadLine": nAuc.deadLine, "posted": nAuc.posted, "content": nAuc.content, "minPrice": nAuc.minPrice, "author": nAuc.author, "idItem": idItem } return render_to_response("lockedbid.html", context) if request.method == "POST" and request.POST.has_key("minPrice"): from_email = '*****@*****.**' newPrice = request.POST.get('minPrice', '') auxNew = float(newPrice) aux = nAuc.minPrice if auxNew > aux: oldBidder = nAuc.bidder newBidder = request.user.username newBidderEmail = request.user.email if newBidder != nAuc.author: if oldBidder != newBidder: oldUserEmail = nAuc.bidderemail authoremail = nAuc.authoremail nBiddeer = Bidders(bidderName=newBidder, bidderEmail=newBidderEmail, bidItem=nAuc.idItem) nBiddeer.save() nAuc.minPrice = newPrice nAuc.bidder = newBidder nAuc.bidderemail = newBidderEmail nAuc.save() bidders = Bidders.objects.all() emailBidders = [] for bider in bidders: emailBidders.append(bider.bidderEmail) send_mail('New bid add', 'A new bid has add to the item .', from_email, emailBidders, fail_silently=False) return HttpResponseRedirect("/yaas/") else: nAuc.locked = "" nAuc.save() messages.add_message(request, messages.INFO, "You are the last bidder") return HttpResponseRedirect("/yaas/") else: messages.add_message( request, messages.INFO, "The price have to be higher than" + str(nAuc.minPrice)) return HttpResponseRedirect("/yaas/bid/" + str(nAuc.idItem) + "/") context = { "titleAuc": nAuc.titleAuc, "minPrice": nAuc.minPrice, "idItem": idItem } return render(request, "bid.html", context)