Пример #1
0
 def get(self,uid):
     if (not self.user) or (str(self.user.key().id())!=uid):
         self.redirect('/login')
         return
     itemList=Item.getAll()
     itemList=make_row(itemList)
     result=self.request.get("result")
     self.render('lobby.html',user=self.user,itemList=itemList,result=result)
Пример #2
0
    def get(self,uid,itemID):
        if (not self.user) or (str(self.user.key().id())!=uid):
            self.redirect('/login')
            return


        item=Item.getByID(itemID)
        latestBid=Bid.getLatestBidByItem(itemID)
        myLatestBid=Bid.getLatestBidByItemAndUser(itemID,uid)
        if not item or dt.datetime.now()+dt.timedelta(hours=8)>item.endDate:
            self.redirect('/'+uid)
            return

        self.render("item.html",user=self.user,item=item,latestBid=latestBid,myLatestBid=myLatestBid)
Пример #3
0
def update_move(json):
    post = db.session.query(MoveDetails).filter(
        and_(MoveDetails.id == json['id'], not_(MoveDetails.deleted))).first()
    if not post:
        abort(400, 'Existing post does not exist.')

    if post.status != 'OPEN':
        abort(
            400,
            'You cannot edit a post if you have already accepted an offer for it.'
        )

    old_from = db.session.query(FromAddress).filter(
        FromAddress.id == post.address_from).first()
    address_from = FromAddress(line1=json['fromAddrL1'],
                               line2=json['fromAddrL2'],
                               city=json['fromCity'],
                               state=json['fromState'],
                               postcode=json['fromPostCo'])
    db.session.add(address_from)
    db.session.commit()
    post.address_from = address_from.id

    old_to = db.session.query(ToAddress).filter(
        ToAddress.id == post.address_to).first()
    address_to = ToAddress(line1=json['toAddrL1'],
                           line2=json['toAddrL2'],
                           city=json['toCity'],
                           state=json['toState'],
                           postcode=json['toPostCo'])
    db.session.add(address_to)
    db.session.commit()
    post.address_to = address_to.id

    db.session.delete(old_from)
    db.session.delete(old_to)
    db.session.commit()

    post.title = json['title']
    post.closing_datetime1 = datetime.strptime(
        json['date'] + '-' + json['time1'], '%d/%m/%Y-%H:%M')
    post.closing_datetime2 = datetime.strptime(
        json['date'] + '-' + json['time2'], '%d/%m/%Y-%H:%M')
    post.description = json['desc']
    post.budget = int(json['budget'])
    post.last_updated = datetime.now()

    db.session.commit()

    for item in post.items:
        db.session.delete(item)
    for item in json['items']:
        new_item = Item(name=item['name'],
                        weight=item['weight'],
                        volume=item['volume'],
                        amount=item['amount'],
                        description=item['description'],
                        move_id=post.id)
        post.items.append(new_item)
    db.session.commit()

    updated = []

    for comment in post.comments:
        if comment.is_offer and not comment.is_stale and comment.poster not in updated:
            update = Update(update_type='post_update',
                            updated_movee_id=comment.poster,
                            concerning_movee_id=post.movee_id,
                            description='',
                            move_id=post.id,
                            update_time=datetime.now())
            db.session.add(update)
            updated.append(comment.poster)

        comment.is_stale = True
    db.session.commit()

    resp = jsonify({'success': True, 'move': post.to_dict()})
    resp.status_code = 200

    return resp
Пример #4
0
def create_order():
    print("Connecting to database...")
    customer_dao = CustomerDAO()
    customer_order_dao = CustomerOrderDAO()
    customer_order = CustomerOrder()
    product_dao = ProductDAO()
    item_dao = ItemDAO()
    employee_dao = EmployeeDAO()

    found = False
    list_of_employees = employee_dao.select_all()
    salesperson_num = 0
    while not found:
        print("Enter in salesperson number")
        salesperson_num = input()
        for emp in list_of_employees:
            if emp.get_salesperson_num() == salesperson_num:
                found = True
        if not found:
            print("No employee with that salesperson number")

    print("Please enter customer phone number ")
    phone_num = input()
    customer = customer_dao.select_by_phone(str(phone_num))
    customer_order.set_phone_num(customer.get_phone())
    customer_order.set_salesperson_num(salesperson_num)

    print("Please enter today's date ")
    date = input()
    customer_order.set_date_made(date)

    hold_num = generate_hold_num()
    customer_order.set_hold_num(hold_num)

    print("Please enter description of where tile will be located ")
    customer_order.set_description(input())

    print("Please enter delivery address")
    customer_order.set_delivery_address(input())
    customer_order.set_total_cost(
        0.00)  #Initialize to 0 we will manipulate this after

    customer_order_dao.insert_customer_order(customer_order)

    list_of_products = product_dao.select_all()
    done = True
    total_cost = 0
    while done:
        found = False
        item = Item()
        while not found:
            print("Enter product NTD number")
            ntd_num = input()
            for x in list_of_products:
                if x.get_ntd_num() == ntd_num:
                    item.set_ntd_num(ntd_num)
                    found = True
            if not found:
                print("Wrong NTD number")

        while True:
            print(
                "Enter desired quantity of product, if grout enter number of bags, if tile enter square footage"
            )
            desired_quantity = input()
            if float(desired_quantity) > float(
                    product_dao.select_by_ntd_num(ntd_num).get_amt_in_stock()):
                print("Not enough quantity in warehouse!")
            else:
                break
        item.set_quantity(desired_quantity)
        cost = float(item.get_quantity()) * float(
            product_dao.select_by_ntd_num(
                item.get_ntd_num()).get_cost_per_sf())
        total_cost = float(total_cost) + float(cost)
        item.set_total_cost(str(cost))
        item.set_hold_num(hold_num)
        item_dao.insert_item(item)

        product = product_dao.select_by_ntd_num(item.get_ntd_num())
        newSquareFootage = float(product.get_amt_in_stock()) - float(
            item.get_quantity())
        newCartonCount = int(
            float(newSquareFootage) / float(product.get_sf_per_carton()))
        newPieceCount = int(
            (float(newSquareFootage) % float(product.get_sf_per_carton())) /
            float(product.get_size_of_product()))
        product.set_amt_in_stock(str(newSquareFootage))
        product.set_carton_count(str(newCartonCount))
        product.set_piece_count(str(newPieceCount))
        product_dao.update(product)

        print("Enter another product?\n"
              "Press 1 for yes\n"
              "Press 2 to complete the order")
        choice = input()
        if choice == "2":
            customerOrder = customer_order_dao.select_by_hold_number(
                customer_order.get_hold_num())
            customerOrder.set_total_cost(total_cost)
            customer_order_dao.update(customerOrder)
            print("Customer's order hold number is " + str(hold_num))
            done = False
Пример #5
0
    def post(self,uid,itemID):
        #currently do not need authentication

        if (not self.user) or (str(self.user.key().id())!=uid):
            self.redirect('/login')
            return

        item=Item.getByID(itemID)
        if not item:
            self.redirect('/'+uid)
            return

        customerBid=self.request.get("customerBidPost")
        customerBid=float(customerBid)


        #Lock Mechanism to prevent concurrent bidding
        try:
            #lock mechanism
            #if lock then wait
            lock=memcache.get("lock"+itemID)
            count=0
            while lock and count<=9:
                memcache.set("sleep"+itemID+uid,0)
                sleep=0
                while sleep<=100:
                    memcache.incr("sleep"+itemID+uid)
                    sleep=memcache.get("sleep"+itemID+uid)
                lock=memcache.get("lock"+itemID)

            #set lock
            memcache.set("lock"+itemID,True)

            latestBid=Bid.getLatestBidByItem(itemID)

            #check if the bidding info is valid
            # if later than the end bid time or lower than the latest bid amount, invalid bidding
            if item.endDate<(dt.datetime.now()+dt.timedelta(hours=8)) or (latestBid and customerBid<=latestBid.bidAmount):
                raise Exception

            outBidder=None
            #expire old bid
            if latestBid:
                # to identify the identify of the outBidder
                if latestBid.bidder!=uid:
                    outBidder=latestBid.bidder
                latestBid.expire()
                latestBid.save()

            #insert the new bid
            bid=Bid(bidder=uid,item=itemID,bidAmount=customerBid,timeStamp=dt.datetime.now()+dt.timedelta(hours=8),activeFlag=True)
            bid.save()

            #update bidder info
            if itemID not in self.user.myBidItems:
                self.user.myBidItems.append(itemID)
                self.user.save()

            #send an email on every bid
            try:
                send_bid_email(self.user,item)
            except:
                pass

            #send email to the outBidder
            if outBidder:
                outBidder=Bidder.by_id(outBidder)
                try:
                    send_outbid_email(outBidder,item)
                except:
                    pass

            self.redirect('/'+uid+'?result=success')
        except:
            error="Your Bid Is Invalid"
            myLatestBid=Bid.getLatestBidByItemAndUser(itemID,uid)
            self.render("item.html",user=self.user,item=item,latestBid=latestBid,myLatestBid=myLatestBid,error=error)
        finally:
            #release lock
            success=memcache.delete("lock"+itemID)
            count=0
            while not success and count<10:
                success=memcache.delete("lock"+itemID)
                count+=1