示例#1
0
文件: views.py 项目: Lizzy95/YAASWeb
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/")
示例#2
0
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")
示例#3
0
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
示例#4
0
文件: views.py 项目: MglMX/DEWAS
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('/')
示例#5
0
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)
示例#6
0
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()