Пример #1
0
    def build(cls, **kwds):
	owner = users.get_current_user()
	if not owner:
	    raise ValueError('No owner specified.')
	kwds['owner'] = user_steam_id(owner)

	if not cls.lazy_verify:
	    kwds['profile'] = profile = PlayerProfile.get_by_user(owner)
	    profile.refresh()
	else:
	    kwds['profile'] = None

	verify_items_inactive(uid for uid, item in kwds['item_ids'])
	listing_id = int(kwds.pop('listing_id'))
	listing = kwds['listing'] = Listing.get_by_id(listing_id)

	## TODO: check for existing bid by owner and disallow creating
	## multiple bids.
	if not listing:
	    raise TypeError('Invalid listing.')
	if listing.status != 'active':
	    raise TypeError('Invalid listing status.')
	key = db.run_in_transaction(cls.build_transaction, **kwds)
    	listing.bid_count += 1
        listing.update_top(put=False)
	listing.put()
	return key
Пример #2
0
    def build(cls, **kwds):
	## 0.  verify the owner, duration and description before
	## we do anything else (to prevent needless expensive checks).
        ## like the listing item, we need to get the profile before
	## we run the transaction.
	owner = users.get_current_user()
	if not owner:
	    raise ValueError('No owner specified.')
	kwds['owner'] = id64 = user_steam_id(owner)
	if not cls.lazy_verify:
	    kwds['profile'] = profile = PlayerProfile.get_by_user(user_steam_id(owner))
	    profile.refresh()
	else:
	    kwds['profile'] = None
	kwds['is_subscriber'] = PlayerProfile.is_subscriber_id64(id64)

	## this check has to be performed outside of the transaction
	## because its against items outside the new listing ancestry.
	## this whole check should move to a
	## "maybe-cancel-invalid-new-listing" queue:
	verify_items_inactive(uid for uid, item in kwds['item_ids'])
	return db.run_in_transaction(cls.build_transaction, **kwds)
Пример #3
0
    def build(cls, owner, status='initial'):
	## lazy to avoid circular imports:
	from tf2auctions.models.profile import PlayerProfile
	from tf2auctions.models.settings import PlayerSettings

	profile = PlayerProfile.build(owner)
	settings = PlayerSettings.build(owner)
	obj = cls.get_or_insert(owner, profile=profile, settings=settings, status=status)
	if not obj.is_saved():
	    obj.put()
	else:
	    obj.status = status
	    obj.put()
	return obj
Пример #4
0
    def reverify(self, cls, key):
	""" Verify item ownership against the owner's backpack.

	This method will return the object if ownership is correct,
	otherwise it will cancel the listing or bid.
	"""
	kind = cls.__name__.lower()
	obj = cls.get(key)
	info('re-verify items in %s: %s', kind, key)
	items = obj.items()
	profile = PlayerProfile.get_by_user(user_steam_id(obj.owner))
	profile.refresh()
	#warn('re-verify items: %s', [long(i.uniqueid) for i in items])
	if profile.owns_all([long(i.uniqueid) for i in items]):
	    return obj
	else:
	    obj.cancel('Item ownership changed (%s)' % (kind, ))
Пример #5
0
    def build_update(cls, **kwds):
	owner = users.get_current_user()
	if not owner:
	    raise ValueError('No owner specified.')
	listing_id = int(kwds.pop('listing_id'))
	listing = kwds['listing'] = Listing.get_by_id(listing_id)
	if not listing:
	    raise TypeError('Invalid listing.')
	if listing.status != 'active':
	    raise TypeError('Invalid listing status.')
	bid = kwds['bid'] = cls.all().filter('owner =', user_steam_id(owner)).filter('listing =', listing).get()
	if not bid:
	    raise ValueError('No existing bid to update.')
	kwds['owner'] = user_steam_id(owner)
	kwds['profile'] = PlayerProfile.get_by_user(owner)
	verify_items_inactive(uid for uid, item in kwds['item_ids'])
	key = db.run_in_transaction(cls.build_update_transaction, **kwds)
        listing.update_top(put=True)
	return key
Пример #6
0
    def encode_builtin(self, bids=False, items=True, feedback=True, currency_type_map=dict(currency_types())):
	""" Encode this instance using only built-in types.

	"""
	key = self.key()
	bids = self.bids() if bids else ()
	wins = [b for b in bids if b.status == 'awarded']
        bfb = Feedback.get_by_listing(self) if feedback else ()
	user = users.get_current_user()
	private = False
	if bids and user and user_steam_id(user) == self.owner:
	    private = True
        try:
            currency_type = currency_type_map[self.bid_currency_type]
        except (KeyError, ):
            currency_type = None
	return {
	    'id' : key.id(),
	    'key': str(key),
	    'owner' : PlayerProfile.get_by_user(self.owner).encode_builtin(subscription=False),
	    'created' : js_datetime(self.created),
	    'expires' : js_datetime(self.expires),
	    'description' : self.description,
	    'bid_count' : self.bid_count,
	    'min_bid' : self.min_bid,
	    'items' : [i.encode_builtin() for i in self.items()] if items else (),
	    'status' : self.status,
	    'status_reason' : self.status_reason,
	    'bids' : [b.encode_builtin(listing=False, private=private) for b in bids],
	    'feedback' : [fb.encode_builtin() for fb in bfb],
	    'featured' : self.featured,
	    'bid_currency_use' : self.bid_currency_use,
	    'bid_currency_start' : self.bid_currency_start,
	    'bid_currency_type' : currency_type,
            'bid_currency_top' : self.bid_currency_top,
	}
Пример #7
0
    def build(cls, bid, listing, source, target, rating, comment):
	obj = cls(bid=bid, listing=listing, source=source, target=target, rating=rating, comment=comment)
	obj.put()
	PlayerProfile.get_by_id64(target).add_rating(rating)
	return obj
Пример #8
0
    def owner_profile(self):
	""" Returns the player profile for this bid.

	"""
	return PlayerProfile.get_by_user(self.owner)