def post(self):
        """ Called by the task queue API when a this task is ready to
	    run.  The tasks are created by the Listing model.
	"""
        listing = Listing.get(self.request.get("listing_key"))
        summary = {"listing": {"id": listing.key().id()}}
        send(body=json_dumps(summary))
Beispiel #2
0
    def post(self):
	try:
	    vs = self.body_json()
	    source, bid, listing, rating, text = \
		    vs['source'], vs['bid'], vs['listing'], int(vs['rating']), vs['text'][0:400]
	    user = users.get_current_user()
	    bid = Bid.get(bid)
	    listing = Listing.get(listing)
	    fb = Feedback.get_by_source(bid, listing, user_steam_id(user))
	    if rating > 100 or rating < -100:
		raise TypeError('Invalid feedback rating')
	    if source == 'lister':
		## lister is adding feedback for bidder; target is bid owner
		target = bid.owner
	    elif source == 'bidder':
		## bidder is adding feedback for lister; target is listing owner
		target = listing.owner
	    else:
		raise TypeError('Invalid feedback source')
	    source = user_steam_id(user)
            if fb:
		#raise TypeError('Feedback exists')
                fb.rating = rating
                fb.comment = text
                fb.put()
            else:
                fb = Feedback.build(bid, listing, source, target, rating, text)
	except (Exception, ), exc:
	    self.error(500)
	    raise
	    exc = exc.message if hasattr(exc, 'message') else str(exc)
	    result = {'msg':'error', 'description':exc}
Beispiel #3
0
    def post(self):
        try:
            post = self.body_json()
            listing_id = int(post["id"])
            listing = Listing.get_by_id(listing_id)
            if not listing:
                self.error(404)
                return
            current_user = users.get_current_user()
            if current_user and (listing.owner == user_steam_id(current_user.nickname())):
                db_result = listing.cancel("Cancelled by user.")
            else:
                import logging

                logging.warn(
                    "wtf %s %s %s",
                    user_steam_id(current_user.nickname()),
                    listing.owner,
                    current_user.nickname() == listing.owner,
                )
                self.error(401)
                return
            result = {"msg": "okay", "result": db_result}
        except (Exception,), exc:
            self.error(500)
            exc = exc.message if hasattr(exc, "message") else str(exc)
            result = {"msg": "error", "description": exc}
Beispiel #4
0
    def get(self):
	listing_id = int(self.path_tail())
	listing = Listing.get_by_id(listing_id)
	if not listing:
	    self.error(404)
	    return
	self.write_json(listing.encode_builtin(bids=True))
Beispiel #5
0
    def post(self):
	next = None
	bookmark = self.request.get('subscription_key')

	q = Subscription.all().order('__key__').filter('status =', Subscription.verified)
	if bookmark:
	    q.filter('__key__ >', db.Key(bookmark))
	subscription = q.get()

	## 0. done if there are no more subscriptions
	if not subscription:
	    return

	## 1. otherwise, process this subscription via its settings:
	listing_key = self.request.get('listing_key')
	listing = Listing.get(listing_key)
	settings = subscription.settings
	if settings.email and settings.notify_listing_defs:
	    items = [i.defindex for i in listing.items()]
	    for defindex in items:
		if defindex in settings.notify_listing_defs:
		    ## no name, that would mean yet another datastore read...
		    send(settings.email, listing.url())
		    break

	## 2.  add another item to the queue:
	queue_tool.notify_listing(subscription_key=subscription.key(),
				  listing_key=listing_key)
Beispiel #6
0
	def inner_search():
	    q = Listing.basic_query()
	    q.filter('featured =', True)
	    q.order('-created')
	    listings = q.fetch(self.limit)
	    if encoded:
		listings = [lst.encode_builtin() for lst in listings]
	    return listings
Beispiel #7
0
    def post(self):
	try:
	    key = self.request.get('key')
	    warn('expire listing: %s', key)
	    listing = Listing.get(key)
	    if listing:
		listing.expire('Expired by system.')
	except (Exception, ), exc:
	    error('expire listing exception: %s', exc)
	    self.response.out.write('ERROR')
Beispiel #8
0
	def inner_search():
	    listings, qs = [], self.qs
	    for di in qs.get('di', [])[0:self.max_defs]:
		try:
		    di = int(di)
		except (ValueError, ):
		    continue
		q = ListingItem.all(keys_only=True).filter('status = ', 'active')
		q.filter('defindex =', di)
		listings += Listing.get(i.parent() for i in q.fetch(self.limit))
	    listings = dict((lst.key(), lst) for lst in listings).values() ## remove dupes
	    listings.sort(key=lambda o:o.expires) ## TODO:  verify this is desired
	    if encoded:
		listings = [lst.encode_builtin() for lst in listings]
	    return listings, '', False
Beispiel #9
0
	def inner_search():
	    listings, qs = [], self.qs
	    for mb in qs.get('mb', [])[0:self.max_defs]:
		try:
		    mb = int(mb)
		except (ValueError, ):
		    continue
		q = Listing.basic_query()
		q.filter('min_bid =', mb)
		listings += q.fetch(self.limit)
	    listings = dict((lst.key(), lst) for lst in listings).values() ## remove dupes
	    listings.sort(key=lambda o:o.expires) ## TODO:  verify this is desired
	    if encoded:
		listings = [lst.encode_builtin() for lst in listings]
	    return listings, '', False
Beispiel #10
0
    def get(self):
	try:
	    id64 = self.path_tail()
	    q = Listing.all()
	    q.filter('owner = ', id64)
	    qs = parse_qs(self.request.query_string)
	    #if (user_steam_id(users.get_current_user()) == id64) and 'ext' in qs:
            if not 'ext' in qs:
		q.filter('status = ', 'active')
	    q.order('-created')
	    rs = [r.encode_builtin() for r in q.fetch(limit=100)]
	    self.write_json(rs)
	except (Exception, ), exc:
	    self.error(500)
	    self.write_json({'exception':str(exc)})
Beispiel #11
0
    def post(self):
	try:
	    post = self.body_json()
	    listing_id = int(post['id'])
	    listing = Listing.get_by_id(listing_id)
	    if not listing:
		self.error(404)
		return
	    bid = post['bid']
	    current_user = users.get_current_user()
	    if current_user and (listing.owner == user_steam_id(current_user.nickname())):
		db_result = listing.winner(bid)
	    else:
		self.error(401)
		return
	    result = {'msg':'okay', 'result':db_result}
	except (Exception, ), exc:
	    self.error(500)
	    exc = exc.message if hasattr(exc, 'message') else str(exc)
	    result = {'msg':'error', 'description':exc}
Beispiel #12
0
    def post(self):
	try:
	    data = self.body_json()
	    items = data['items']
	    item_ids = [(i['id'], i) for i in items]
	    if len(item_ids) != len(items):
		raise TypeError('Missing item identifiers.')
	    desc = data['desc'][0:400]
	    days = data['days'] + 0 # force exception
	    if days < 0 or days > 30:
		raise TypeError('Invalid duration.')
	    min_bid = [b+0 for b in data['min_bid']] # again, force an exception
	    key = Listing.build(item_ids=item_ids, desc=desc, days=days, min_bid=min_bid,
				bid_currency_use=data.get('bid_currency_use'),
				bid_currency_start=data.get('bid_currency_start'),
				bid_currency_type=data.get('bid_currency_type'),
				feature_listing=data.get('feature_listing'))
	except (Exception, ), exc:
	    error('add listing: %s', exc)
	    self.error(500)
	    exc = exc.message if hasattr(exc, 'message') else str(exc)
	    result = {'msg':'error', 'description':exc}
Beispiel #13
0
    def run(self, encoded=True):
	q = Listing.basic_query()
	qs = self.qs
	@cache(self.rqs, ttl=180)
	def inner_search():
	    for key, title in self.filter_items():
		if qs.get(key, [''])[0] == 'on':
		    q.filter('categories =', key)
	    sort = qs.get('sort', ['created'])[0]
	    title, order = self.orders.get(sort, self.orders['created'])
	    if order:
		order(q)
	    if 'c' in qs:
		q.with_cursor(qs['c'][0])
	    try:
		limit = min(self.limit, int(qs['limit'][0]))
	    except (Exception, ), exc:
		limit = self.limit
	    listings = q.fetch(limit)
	    if encoded:
		listings = [lst.encode_builtin(feedback=False) for lst in listings]
	    return listings, self.next_qs(q, qs), self.more(q)
Beispiel #14
0
    def get(self):
	try:
	    key = db.Key.from_path('Listing', int(self.path_tail()))
	    exists = Listing.all(keys_only=True).filter('__key__', key).get()
	except (Exception, ), exc:
	    self.error(500)