Ejemplo n.º 1
0
    def query_all_live_auctions(self, involved_only=False):

        def filter_func(auc_record):
            return auc_record.get("status") == const.AUCTION_STATUS_IN_PROGRESS

        auctions = Auction.all(filter_func)

        if involved_only:
            bids = Bid.all(lambda x: x["participant_id"] == self.id)
            involved_auction_ids = set([b.auction_id for b in bids])
            auctions = [a for a in auctions if a.id in involved_auction_ids]

        return auctions
Ejemplo n.º 2
0
    def unstage_item_from_auction(self, item_name):
        item = Item.one(item_name)
        if item is None:
            return {
                "status": "error",
                "errors": ["Item does not exist."],
            }

        if item.status != const.ITEM_STATUS_STAGED:
            return {
                "status": "error",
                "errors": ["Item is not staged for auction."],
            }

        def filter_func(auc_record):
            item_name_met = auc_record.get("item_name") == item_name
            auc_status_met = auc_record.get("status") == const.AUCTION_STATUS_CREATED

            return item_name_met and auc_status_met

        ret = Auction.all(filter_func)
        if ret:
            auction = ret[0]
            auction.delete()
        else:
            return {
                "status": "error",
                "errors": [
                    "Auction for this item already progressed, and cannot "
                    "unstage the item at this time."
                ],
            }

        item.status = const.ITEM_STATUS_AVAILABLE
        item.save()

        return {
            "status": "success",
            "item_name": item.name,
        }
Ejemplo n.º 3
0
    def create_auction(self, item_name):
        item = Item.one(item_name)
        if item is None:
            return {
                "status": "error",
                "errors": ["Item does not exist."],
            }

        def filter_func(auc_record):
            return auc_record.get("status") != const.AUCTION_STATUS_CALLED_FAIL

        if Auction.all(filter_func):
            return {
                "status": "error",
                "errors": ["Auction already exists for this item."],
            }

        auction = Auction(item_name)
        auction.save()

        return {
            "status": "success",
            "auction_id": auction.id,
        }
Ejemplo n.º 4
0
    def query_latest_summary_for_item(self, item_name):
        item = Item.one(item_name)
        if item is None:
            return {
                "status": "error",
                "errors": ["Item does not exist."],
            }

        item_info = {
            "name": item.name,
            "reserved_price": item.reserved_price,
            "status_code": item.status,
            "status_name": const.ITEM_STATUS_NAMES[item.status],
            "created_at": item.created_at,
            "updated_at": item.updated_at,
        }

        auction = None
        auction_info = None
        if item.status > const.ITEM_STATUS_AVAILABLE:

            # We will exclude any past failed auctions in summary because
            # presumably that's not good for auction.
            def filter_func(auc_record):
                item_name_met = auc_record.get("item_name") == item_name
                auc_status_met = auc_record.get("status") != const.AUCTION_STATUS_CALLED_FAIL
                return item_name_met and auc_status_met

            ret = Auction.all(filter_func)
            if ret:
                auction = ret[0]
                auction_info = {
                    "id": auction.id,
                    "status_code": auction.status,
                    "status_name": const.AUCTION_STATUS_NAMES[auction.status],
                    "highest_bid_id": auction.highest_bid_id,
                    "winning_bid_id": auction.winning_bid_id,
                    "created_at": auction.created_at,
                    "started_at": auction.started_at,
                    "closed_at": auction.closed_at,
                }

        bid_id = None
        if auction and auction.winning_bid_id:
            bid_id = auction.winning_bid_id
        elif auction and auction.highest_bid_id:
            bid_id = auction.highest_bid_id

        bid_info = None
        if bid_id:
            prevailing_bid = Bid.one(bid_id)
            if prevailing_bid:
                bid_info = {
                    "id": prevailing_bid.id,
                    "offer_price": prevailing_bid.offer_price,
                    "participant_id": prevailing_bid.participant_id,
                    "submitted_at": prevailing_bid.submitted_at,
                }

        return {
            "status": "success",
            "item": item_info,
            "auction": auction_info,
            "prevailing_bid": bid_info,
        }
Ejemplo n.º 5
0
    def query_all_auctions(self, status_code=None):
        auctions = Auction.all()
        if status_code:
            auctions = [a for a in auctions if a.status == status_code]

        return auctions