def post(self): content = loads(self.request.body) status = content.get("status", "") limit = int(content.get("limit")) page = int(content.get("page")) skip = (page - 1) * limit cats = Category.find(dict( status={"$ne": '0'} if not status or status == '0' else status), skip=skip, limit=limit) cat_count = Category.count(dict( status={"$ne": '0'} if not status or status == '0' else status), skip=skip, limit=limit) for cat in cats: cat['offer_count'] = Offers.count(dict(category=str(cat._id))) cat.status = 'Active' if cat.status == '1' else 'Pending' self.finish(dict(cat=cats, cat_count=cat_count))
def get(self, ad_id): ad = Advertisers.find_one(dict(user_id=int(ad_id))) ad_user = User.find_one(dict(_id=int(ad_id))) if ad_user: ad['_id'] = ad_user._id ad['name'] = ad_user.account ad['email'] = ';'.join(ad_user.email) ad['skype_id'] = ad_user.skype_id bd = User.find_one(dict(_id=ad.account_manager)) ad['bd'] = bd.account if bd else '' pm = User.find_one(dict(_id=ad.pm)) ad['pm'] = pm.account if pm else '' offers_count = Offers.count(dict(advertiser_id=ad_user._id)) ad['offers_count'] = offers_count status_map = {'0': 'Deleted', '1': 'Active', '2': 'Paused'} ad['status'] = status_map.get(ad.status) ad['white_list'] = ','.join(ad.white_list) if ad.white_list else '' self.render(advertiser=ad) else: self.write('The advertiser not exist!')
def post(self): _ids = self.json.offer_ids status = self.json.status is_api = self.json.is_api category = self.json.category price_model = self.json.price_model advertiser = self.json.advertiser country = self.json.country payment_min = self.json.payment_min payment_max = self.json.payment_max limit = 100 if not self.json.limit else int(self.json.limit) page = 1 if not self.json.page else int(self.json.page) skip = (page - 1) * limit is_api = True if is_api == '1' else {"$ne": True} query = {'is_api': is_api} if _ids: query["_id"] = {"$in": [int(id) for id in _ids]} if status: query["status"] = status if category: query["category"] = category if price_model: query["price_model"] = price_model if advertiser: query["advertiser"] = advertiser if country: country_list = country.split(',') query["geo_targeting"] = country if len(country_list) == 1 else { '$in': country_list } if payment_max or payment_min: query["payment"] = {} if payment_min: query["payment"]["$gte"] = float(payment_min) if payment_max: query["payment"]["$lte"] = float(payment_max) offers_count = Offers.count(query) offers = Offers.find(query, sort=[('_id', 1)], limit=limit, skip=skip) advertiser_extends = Advertisers.find(dict(status={"$ne": '0'})) advertisers = User.find( dict(_id={'$in': [int(ad.user_id) for ad in advertiser_extends]}, deleted=False)) categories = Category.find(dict(status={"$ne": '0'})) for offer in offers: if offer.status == '0': offer.status = 'Paused' elif offer.status == '1': offer.status = 'Active' else: offer.status = 'Pending' if offer.price_model == '1': offer.price_model = 'CPA' elif offer.price_model == '2': offer.price_model = 'CPS' elif offer.price_model == '3': offer.price_model = 'CPC' if offer.advertiser_id: ad = User.find_one(dict(_id=int(offer.advertiser_id))) offer['advertiser'] = ad.account if offer.category_id: category = Category.find_one(dict(_id=int(offer.category_id))) offer['category'] = category.name self.finish( dict( offers_count=offers_count, offers=offers, advertisers=advertisers, categories=categories, ))