Ejemplo n.º 1
0
    def build_update_transaction(cls, owner, profile, listing, bid, item_ids, public_msg, private_msg, currency_val=0):
	if not profile.owns_all(uid for uid, item in item_ids):
	    raise ValueError('Incorrect ownership.')
	schema = json_loads(fetch.schema())
	bid.message_public = public_msg
	bid.message_private = private_msg
        bid.currency_val = currency_val
	bid.put()
	item_types = item_type_map(schema)
	for uid, item in item_ids:
	    uid = str(uid)
	    bid_item = BidItem(
		parent=bid,
		uniqueid=uid,
		defindex=item['defindex'],
		source=json_dumps(item),
		item_type_name=item_types[item['defindex']],
		listing=listing,
		bid=bid)
	    bid_item.put()
	key = bid.key()
	queue_tool.bang_counters({'bid_items':len(item_ids)}, transactional=True)
	## we don't re-queue the bid verification because the
	## verification script will pick up all of the items when it
	## runs.
	queue_tool.notify_bid({'bid':key, 'update':True}, transactional=True)
	return key
Ejemplo n.º 2
0
    def build_transaction(cls, owner, profile, listing, item_ids, public_msg, private_msg, currency_val):
	if not cls.lazy_verify:
	    if not profile.owns_all(uid for uid, item in item_ids):
		raise ValueError('Incorrect ownership.')
	schema = json_loads(fetch.schema())
	bid = cls(owner=owner, listing=listing, message_private=private_msg, message_public=public_msg, currency_val=currency_val)
	key = bid.put()
	item_types = item_type_map(schema)
	for uid, item in item_ids:
	    uid = str(uid)
	    bid_item = BidItem(
		parent=bid,
		uniqueid=uid,
		defindex=item['defindex'],
		source=json_dumps(item),
		item_type_name=item_types[item['defindex']],
		listing=listing,
		bid=bid)
	    bid_item.put()
	queue_tool.bang_counters({'bids':1, 'bid_items':len(item_ids)}, transactional=True)
	queue_tool.reverify_items({'key':key, 'action':'init', 'type':'bid'}, transactional=True)
	queue_tool.notify_bid({'bid':key, 'update':False}, transactional=True)
	return key
Ejemplo n.º 3
0
    def build_transaction(cls, owner, profile, item_ids, desc, days, min_bid=None,
			  is_subscriber=False,
			  bid_currency_use=False,
			  bid_currency_start=0,
			  bid_currency_type='',
			  feature_listing=False):
	## 1.  check the user, get their backpack and verify the
	## inidicated items belong to them.
	if not cls.lazy_verify:
	    if not profile.owns_all(uid for uid, item in item_ids):
		raise ValueError('Incorrect ownership.')

	## 2. check the date
	if days not in cls.valid_days:
	    raise ValueError('Invalid number of days until expiration.')

	## regulation 46a:
	delta = timedelta(minutes=days*4) if features.devel else timedelta(days=days)
	expires = datetime.now() + delta

	## 3.  extract and create categories for the ListingItem
	## item types and for the min_bid defindex checks.
	schema = json_loads(fetch.schema())

	## 4. verify the min_bid values are present in the schema.
	min_bid = min_bid or []
	min_bid_defs = set(min_bid)
        valid_defs = set(i['defindex'] for i in schema['result']['items']['item'])
	if not (min_bid_defs & valid_defs == min_bid_defs):
	    raise TypeError('Invalid minimum bid items.')

	## 4.  create.  note that we're not setting a parent entity so
	## that we can query for the listing by id.
	listing = cls(
	    owner=owner,
	    expires=expires,
	    min_bid=min_bid,
	    description=desc)

	## 4a.  derive categories
	cats = item_categories([i for u, i in item_ids], schema)
	listing.categories =\
	    [cat for cat, ttl in known_categories if cat in cats]

	## 4b.  set subscriber features:
	if is_subscriber:
	    listing.bid_currency_use = bid_currency_use
	    listing.bid_currency_start = float(bid_currency_start)
	    listing.bid_currency_type = bid_currency_type
            ## listing.bid_currency_top == 0 by default
	    listing.featured = feature_listing

	key = listing.put()
	info('created new listing at: %s', listing.created)

	# 5. assign the items
	item_types = item_type_map(schema)
	for uid, item in item_ids:
	    uid = str(uid)
	    listing_item = ListingItem(
		parent=listing,
		uniqueid=uid,
		defindex=item['defindex'],
		source=json_dumps(item),
		item_type_name=item_types[item['defindex']],
		listing=listing)
	    listing_item.put()

	## 6.  submit an item to the expiration task queue.
	queue_tool.end_listing(key, expires, transactional=True)

	## 7.  submit an item to the re-verification task queue.
	queue_tool.reverify_items({'key':key, 'action':'init', 'type':'listing'}, transactional=True)

	## 8.  submit an item to the counter banging task queue.
	queue_tool.bang_counters({'listings':1, 'listing_items':len(item_ids)}, transactional=True)

	## 9. submit an item to the subscriber notification queue
	queue_tool.notify_listing(subscription_key=None, listing_key=key, transactional=True)

        ## 10. submit an item to the external share queue
        if not features.devel:
            queue_tool.external_share(listing_key=key, transactional=True)
	return key