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)
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