Beispiel #1
0
 def post(self):
     name = self.get_argument('name')
     if not name:
         self.render(err=u'Category Name can\'t be empty!')
     elif Category.count(dict(name=name, status={'$ne': '0'})):
         self.render(err=u'Name already be used!')
     else:
         status = self.get_argument('status')
         Category._save(name=name, status=status)
         self.redirect("/category/manage")
Beispiel #2
0
    def get(self):
        status = {'0': 'Paused', '1': 'Active', '2': 'Pending'}
        offer_id = self.get_argument('offer_id')
        offer = Offers.find_one(dict(_id=int(offer_id)))
        if not offer:
            self.write(u'The offer is not exist!')
            return
        offer.status = status.get(offer.status)
        if offer.advertiser_id:
            ad = User._get(offer.advertiser_id)
            offer['advertiser'] = ad.account if ad else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        if offer.access_status == '1':
            offer.access_status = 'Public'
        elif offer.access_status == '2':
            offer.access_status = 'Need Approve'
        else:
            offer.access_status = 'Private'

        if offer.platform == '1':
            offer.platform = 'IOS'
        elif offer.platform == '2':
            offer.platform = 'ANDROID'
        elif offer.platform == '0':
            offer.platform = 'All'

        offer_affiliates = OAffiliate._query(offer_ids=[offer_id])
        for off_aff in offer_affiliates:
            affiliate = User.find_one(dict(_id=int(off_aff.affiliate_id)))
            affiliate_extend = Affiliate.find_one(
                dict(user_id=int(off_aff.affiliate_id)))
            if not affiliate_extend or not affiliate_extend.account_manager:
                off_aff['am_name'] = ''
            elif off_aff.status == '1':
                am = User.find_one(
                    dict(_id=int(affiliate_extend.account_manager)))
                off_aff['am_name'] = am.account
            off_aff['affiliate_name'] = affiliate.account if affiliate else ''
            if off_aff.status == '1':
                off_aff['application_status'] = 'Approved'
            elif off_aff.status == '2':
                off_aff['application_status'] = 'Pending'
            else:
                off_aff['application_status'] = 'Rejected'

        self.render(offer=offer, offer_affiliates=offer_affiliates)
Beispiel #3
0
    def post(self, cat_id):
        err = False
        content = loads(self.request.body)
        name = content.get('name')
        status = content.get('status')
        category = Category.find_one(dict(_id=int(cat_id)))
        if not name:
            err = u'Category Name can\'t be empty!'
        elif name != category.name and Category.count(
                dict(name=name, status={'$ne': '0'})):
            err = u'Name already be used!'
        else:
            Category._update(cat_id, name=name, status=status)

        self.finish(dict(err=err))
Beispiel #4
0
 def get(self):
     advertiser_extends = Advertisers.find(dict(status='1'))
     ads = User.find(
         dict(_id={'$in': [int(ad.user_id) for ad in advertiser_extends]},
              deleted=False))
     cat = Category._query()
     self.render(ads=ads, cat=cat, countries=c().countries)
Beispiel #5
0
    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))
Beispiel #6
0
 def get(self, offer_id):
     advertiser_extends = Advertisers.find(dict(status={"$ne": '0'}))
     ads = User.find(
         dict(_id={'$in': [int(ad.user_id) for ad in advertiser_extends]},
              deleted=False))
     cat = Category._query()
     offer = Offers.find_one(dict(_id=int(offer_id)))
     self.render(cat=cat,
                 ads=ads,
                 offer_id=offer_id,
                 offer=offer,
                 countries=c().countries)
Beispiel #7
0
    def get(self):
        offer_id = self.get_argument('offer_id', None, strip=True)
        offer = Offers.find_one(dict(_id=int(offer_id)))
        off_aff = OfferAffiliate.find_one(
            dict(offer_id=int(offer._id),
                 affiliate_id=int(self.current_user_id),
                 deleted=False))

        if offer.platform == '1':
            offer.platform = 'IOS'
        elif offer.platform == '2':
            offer.platform = 'ANDROID'
        elif offer.platform == '0':
            offer.platform = 'All'

        if off_aff:
            if off_aff.payout:
                offer.payment = off_aff.payout
            if off_aff.day_cap:
                offer.day_cap = off_aff.day_cap
            if off_aff.month_cap:
                offer.month_cap = off_aff.month_cap
            if off_aff.total_cap:
                offer.total_cap = off_aff.total_cap

            if offer.access_status == '1':
                offer['application_status'] = '1'
            if offer.access_status == '2':
                if off_aff.status == '1':
                    offer['application_status'] = '1'
                else:
                    offer['application_status'] = off_aff.status
        else:
            offer['application_status'] = '3'
        if offer.category_id:
            category = Category.find_one(dict(_id=int(offer.category_id)))
            if category:
                offer['category'] = category.name
        self.render(
            aff_id=self.current_user_id,
            offer=offer,
        )
Beispiel #8
0
    def get(self):
        offer_spce = dict(status={"$ne": 0}, is_api={"$ne": True})
        offers = Offers.find(offer_spce, dict(_id=1, title=1))

        affiliate_spec = dict(status={"$ne": 0})
        affiliates = Affiliate.find(affiliate_spec, dict(user_id=1))
        for aff in affiliates:
            user = User.find_one(dict(_id=int(aff.user_id)),
                                 dict(_id=1, account=1))
            if not user:
                continue
            aff['_id'] = user._id
            aff['name'] = user.account

        advertiser_spec = dict(status={"$ne": 0})
        advertisers = Advertisers.find(advertiser_spec, dict(user_id=1))
        for ad in advertisers:
            user = User.find_one(dict(_id=int(ad.user_id)),
                                 dict(_id=1, account=1))
            if not user:
                continue
            ad['_id'] = user._id
            ad['name'] = user.account

        categories = Category.find(dict(status={"$ne": 0}), dict(_id=1,
                                                                 name=1))

        ams = User.find(dict(role_id=Role.am()._id, deleted=False),
                        dict(_id=1, account=1, role_id=1))
        ams = [am for am in ams if am.role_id and am._role == 'AM']
        bds = User.find(dict(role_id=Role.bd()._id, deleted=False),
                        dict(_id=1, account=1, role_id=1))
        bds = [bd for bd in bds if bd.role_id and bd._role == 'BD']
        self.finish(
            dict(offers=offers,
                 affiliates=affiliates,
                 advertisers=advertisers,
                 categories=categories,
                 ams=ams,
                 bds=bds))
Beispiel #9
0
 def get(self):
     category = Category.find(dict(status={'$ne': '0'}))
     self.render(categories=category, countries=_c().countries)
Beispiel #10
0
    def get(self):
        filter = loads(self.get_argument('filter', ''))
        offer_id = filter.get('offer_id')
        is_api = filter.get('is_api')
        status = filter.get('status')
        category = filter.get('category')
        price_model = filter.get('price_model')
        advertiser = filter.get('advertiser')
        country = filter.get('geo', '')
        payment_min = filter.get('payout_min')
        payment_max = filter.get('payout_mix')

        is_api = True if is_api == '1' else {"$ne": True}
        query = {"is_api": is_api}
        if offer_id:
            query["_id"] = int(offer_id)
        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 = Offers.find(query, sort=[('_id', 1)])
        fields = [
            '_id', 'name', 'category', 'payout_model', 'advertiser', 'payout',
            'revenue', 'preview_url', 'geo_count', 'clicks', 'conversions',
            'day_cap', 'total_cap'
        ]
        result_offers = []
        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
            off_tmp = dict(_id=offer._id,
                           name=offer.title,
                           category=offer.get('category'),
                           payout_model=offer.price_model,
                           advertiser=offer.get('advertiser'),
                           payout=offer.payment,
                           revenue=offer.revenue,
                           preview_url=offer.preview_url,
                           geo_count=len(offer.geo_targeting),
                           clicks=offer.clicks,
                           conversions=offer.conversions,
                           day_cap=offer.day_cap,
                           total_cap=offer.total_cap)
            result_offers.append(off_tmp)

        with open('offer.csv', 'wb') as f:
            f.write(codecs.BOM_UTF8)
            fieldnames = fields
            dict_writer = csv.DictWriter(f, fieldnames=fieldnames)
            dict_writer.writeheader()
            dict_writer.writerows(result_offers)

        file = open('offer.csv', 'r')
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition',
                        'attachment; filename=offer.csv')
        self.write(file.read())
Beispiel #11
0
    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,
            ))
Beispiel #12
0
 def get(self, cat_id):
     category = Category.find_one(dict(_id=int(cat_id)))
     self.render(category=category, )
Beispiel #13
0
 def get(self, cat_id):
     cat = Category.find_one(dict(_id=int(cat_id)))
     cat.deleted = True
     cat.save()
     self.redirect("/category/manage")