Пример #1
0
    def post(self):
        status = self.get_argument('status', '')
        page = int(self.get_argument('page', '1'))
        limit = int(self.get_argument('limit', '100'))
        skip = (page - 1) * limit

        affs = Affiliate.find(
            dict(
                status={"$ne": '0'} if not status or status == '0' else status,
                # account_manager=int(self.current_user_id) if not self.current_user.is_admin else {'$ne': ''}
            ),
            limit=limit,
            skip=skip)
        for aff in affs:
            aff.status = 'Active' if aff.status == '1' else 'Pending'
            user = User._get(aff.user_id)
            if aff.account_manager:
                account_manager = User._get(aff.account_manager)
                aff.account_manager = account_manager.account
            aff['name'] = user.account
            aff['email'] = user.email
            aff['password'] = user.password
            aff['_id'] = user._id
            aff['skype_id'] = user.skype_id
            aff['phone'] = user.phone
            aff['offer_count'] = OAffiliate.count(
                dict(affiliate_id=int(aff._id)))
        affs_count = Affiliate.count(
            dict(
                status={"$ne": '0'} if not status or status == '0' else status,
                # account_manager=int(self.current_user_id) if not self.current_user.is_admin else {'$ne': ''}
            ))

        self.finish(dict(affs=affs, affs_count=affs_count))
Пример #2
0
    def post(self):
        start = self.json.start
        end = self.json.end
        query_fields = self.json.query_fields
        selected_filter = self.json.selected_filter or {}
        ams = selected_filter.get('ams_id', None)
        bds = selected_filter.get('bds_id', None)
        if ams:
            affiliates = Affiliate.find(
                dict(account_manager={"$in": [int(am_id) for am_id in ams]}))
            for aff in affiliates:
                selected_filter['affiliates_name'].append(aff.user_id)

        if bds:
            advertisers = Advertisers.find(
                dict(account_manager={"$in": [int(bd_id) for bd_id in bds]}))
            for ad in advertisers:
                selected_filter['advertisers_name'].append(ad.user_id)
        conversions_is_zero = self.json.conversions_is_zero
        limit = int(self.json.limit)
        page = int(self.json.page)
        hour = query_fields.get('hour')
        obj = ReportHour() if hour else ReportDay()

        data, data_count, total = yield self.get_data(obj, start, end,
                                                      query_fields, limit,
                                                      page, selected_filter,
                                                      conversions_is_zero)

        self.finish(dict(docs=data, doc_count=data_count, total=total[0]))
Пример #3
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))
Пример #4
0
    def get(self, action):
        obj_list = []
        if action == 'affiliate':
            offer_id = self.get_argument('offer_id')
            off_affs = OAffiliates._query(offer_ids=[offer_id])
            obj_ids = [off_aff.affiliate_id for off_aff in off_affs]
            affilate_extends = Affiliate.find(
                dict(account_manager={"$ne": ''}, status={'$ne': '0'}))
            objs = User.find(
                dict(_id={
                    "$in": [
                        int(aff.user_id) for aff in affilate_extends
                        if aff.account_manager
                    ]
                },
                     deleted=False))
            res = dict(affiliates=obj_list)

        elif action == 'offers':
            affiliate_id = self.get_argument('affiliate_id')
            off_affs = OAffiliates._query(affiliate_id=affiliate_id)
            obj_ids = [off_aff.offer_id for off_aff in off_affs]
            objs = Offers.find({
                'status': {
                    '$ne': '0'
                },
                'is_api': {
                    "$ne": True
                }
            })
            res = dict(offers=obj_list)

        for obj in objs:
            if int(obj._id) not in obj_ids:
                obj_list.append(obj)

        self.finish(res)
Пример #5
0
 def get(self):
     affiliates = Affiliate.find(dict(status={'$ne': '0'}))
     affiliate_user_ids = [a.user_id for a in affiliates if a]
     affiliates = User.find(dict(role_id=int(Role.affiliate()._id), _id={'$in': affiliate_user_ids}))
     self.render(affiliates=affiliates, currencys=CURRENCY_TYPES)
Пример #6
0
    def get(self):
        cookie = self.get_cookie('S')
        query_fields = loads(self.get_argument('fields'))
        selected_filter = loads(self.get_argument('filter'))
        ams = selected_filter.get('ams_id', None)
        bds = selected_filter.get('bds_id', None)
        if ams:
            affiliates = Affiliate.find(
                dict(account_manager={"$in": [int(am_id) for am_id in ams]}))
            for aff in affiliates:
                selected_filter['affiliates_name'].append(aff.user_id)

        if bds:
            advertisers = Advertisers.find(
                dict(account_manager={"$in": [int(bd_id) for bd_id in bds]}))
            for ad in advertisers:
                selected_filter['advertisers_name'].append(ad.user_id)
        payout_is_zero = loads(self.get_argument('payout_is_zero'))
        time_range = loads(self.get_argument('time_range'))
        start = time_range.get('start')
        end = time_range.get('end')
        hour = query_fields.get('hour')
        obj = ReportHour() if hour else ReportDay()
        data, data_count, total = yield self.get_result(
            obj, start, end, query_fields, payout_is_zero, selected_filter)

        if isinstance(data, bool) and not data:
            self.write(u'The result exceeds maximum size!')
            self.finish()
            return

        _file_name = '{}_report.csv'.format(cookie)
        with open(_file_name, 'wb') as f:
            init_fieldnames = ['impressions', 'clicks', 'cost', 'conversions']
            fieldnames = [k.decode('utf-8') for k in query_fields.keys()]
            for i in ['hour', 'day', 'week', 'month', 'year']:
                if i in fieldnames:
                    fieldnames.remove(i)
                    fieldnames.insert(0, i)

            if 'affiliate_name' in fieldnames:
                fieldnames.extend(['affiliate_id', 'AM'])

            if 'advertiser_name' in fieldnames:
                fieldnames.extend(['advertiser_id', 'BD'])

            [
                fieldnames.append(i) for i in init_fieldnames
                if i not in fieldnames
            ]

            dict_writer = csv.DictWriter(f, fieldnames=fieldnames)
            dict_writer.writeheader()
            dict_writer.writerows(data)
            dict_writer.writerow(total)

        _file = file(_file_name, 'r')
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition',
                        'attachment; filename=report.csv')
        self.write(_file.read())
        self.finish()