Exemplo n.º 1
0
    def get(self, ad_id):
        advertiser = Advertisers.find_one(dict(user_id=int(ad_id)))
        white_list = advertiser.white_list
        advertiser.white_list = ','.join(white_list) if white_list else ''
        user = User._get(advertiser.user_id)
        spec = dict(deleted=False, role_id=Role.bd()._id)
        bds = User.find(spec)
        pms = User.find(dict(role_id=Role.pm()._id), deleted=False)
        if user:
            advertiser['name'] = user.account
            advertiser['email'] = ','.join(user.email)
            advertiser['skype_id'] = user.skype_id
            advertiser['password'] = user.password

        self.render(account_managers=bds, pms=pms, advertiser=advertiser)
Exemplo n.º 2
0
    def send_email(self, pause_date, offer_id):
        offer = Offers.find_one(dict(_id=int(offer_id)))
        offer_affiliate = OAffiliate.find(
            dict(offer_id=int(offer_id), status='1'), dict(affiliate_id=1))
        affiliate_uses = User.find(
            dict(_id={
                "$in":
                [int(off_aff.affiliate_id) for off_aff in offer_affiliate]
            }), dict(email=1))

        emails = map(lambda user: user.email, affiliate_uses)
        if not emails:
            return False
        recivers = reduce(lambda email_1, email_2: email_1.extend(email_2),
                          emails, [])
        content = dict(
            user_id=self.current_user_id,
            model_id=0,
            receiver=recivers,
            message=u'The offer named {offer} will be paused on {pause_date}'.
            format(offer=offer.title, pause_date=pause_date),
            subject=u'Leadhug offer paused notification',
            sender=self.current_user.account)
        EMail._create(**content)
        return True
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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))
Exemplo n.º 6
0
    def get(self, aff_id):
        affiliate = Affiliate.find_one(dict(user_id=int(aff_id)))
        user = User._get(affiliate.user_id)
        spec = dict(deleted=False, role_id=Role.am()._id)
        account_managers = User.find(spec)
        affiliate['account'] = user.account
        affiliate['email'] = user.email
        affiliate['skype_id'] = user.skype_id
        affiliate['phone'] = user.phone
        affiliate['password'] = user.password

        self.render(account_managers=account_managers,
                    affiliate=affiliate,
                    invoice_frequency=InvoiceFrequency)
Exemplo n.º 7
0
    def post(self):
        limit = int(self.json.limit)
        page = int(self.json.page)
        if self.current_user.is_admin:
            users = User.find({"deleted": False})
        else:
            users = [self.current_user]
        new_users = []
        for user in users:
            if user._role != 'Affiliate' and user._role != 'Advertiser':
                user['role'] = user._role
                new_users.append(user)

        users_count = len(new_users)
        start = (page - 1) * limit
        end = start + limit
        result = new_users[start:end]
        self.finish(dict(users=result, users_count=users_count))
Exemplo n.º 8
0
    def post(self):
        err = JsOb()
        content = loads(self.request.body)
        if content.get('affiliate_ids'):
            affiliate_ids = [int(_id) for _id in content.get('affiliate_ids')]
            affiliates = User.find(dict(_id={'$in': affiliate_ids}))
            for aff in affiliates:
                content['affiliate_id'] = aff._id
                if not content.get('payout'):
                    offer = Offers.find_one(
                        dict(_id=int(content.get('offer_id'))))
                    content['payout'] = offer.payment
                OAffiliates._save(**content)

        elif content.get('offer_ids'):
            offer_ids = [int(_id) for _id in content.get('offer_ids')]
            offers = Offers.find(dict(_id={'$in': offer_ids}))
            for offer in offers:
                content['offer_id'] = offer._id
                OAffiliates._save(**content)

        off_affs = OAffiliates.find(dict(status={'$ne': '0'}))
        self.finish(dict(off_affs=off_affs))
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def get(self):
     spec = dict(role_id=Role.bd()._id, deleted=False)
     account_managers = User.find(spec)
     pms = User.find(dict(role_id=Role.pm()._id, deleted=False))
     self.render(account_managers=account_managers, pms=pms)
Exemplo n.º 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,
            ))
Exemplo n.º 12
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)
Exemplo n.º 13
0
    def get(self):

        spec = dict(role_id=Role.am()._id, deleted=False)
        account_managers = User.find(spec)
        self.render(account_managers=account_managers,
                    invoice_frequency=InvoiceFrequency)