def get(self): status = self.get_argument('status', '') limit = int(self.get_argument('limit', '100')) page = int(self.get_argument('page', '1')) skip = (page - 1) * limit ads = Advertisers.find(dict( status={"$ne": '0'} if not status or status == '0' else status), limit=limit, skip=skip) ads_count = Advertisers.count(dict( status={"$ne": '0'} if not status or status == '0' else status), limit=limit, skip=skip) for ad in ads: if ad.user_id: # offer_count = Offers.count(dict(advertiser=str(ad.user_id))) user = User._get(ad.user_id) bd = User._get(ad.account_manager) ad.account_manager = bd.account if ad.pm: pm = User._get(ad.pm) ad.pm = pm.account else: ad.pm = '' ad['name'] = user.account ad['email'] = user.email ad['skype_id'] = user.skype_id ad._id = user._id ad.status = 'Active' if ad.status == '1' else 'Pending' # ad.offer_count = offer_count self.finish(dict(ads=ads, ads_count=ads_count))
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))
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)
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)
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)
def post(self, aff_id): affiliate_edit = Affiliate.find_one(dict(_id=int(aff_id))) user_edit = User._get(affiliate_edit.user_id) form = loads(self.request.body) err = {} if not form.get('email'): err['email'] = 'Please input email' else: emails = form['email'].replace(' ', '').split(',') for e in emails: if not is_email(e): err['email'] = 'Email not valid, email=%s' % e elif e not in user_edit.email and User.count( dict(email=e, deleted=False)): err['email'] = "email %s already be used!" % e if not form.get('account'): err['account'] = 'Pleast input your account' elif form.get('account') != user_edit.account and User.count( dict(account=form.get('account'), deleted=False)): err['account'] = 'Account already be used!' if not form.get('password'): err['password'] = '******' elif form.get( 'password') != user_edit.password and not is_valid_password( form.get('password')): err['password'] = '******' if not form.get('account_manager') and form.get('status') != '0': err['account_manager'] = 'Please select Account Manager!' if not err: kw = dict( email=emails, password=form.get('password'), account=form.get('account'), role_id=Role.affiliate()._id, skype_id=form.get('skype_id'), phone=form.get('phone'), ) user = User._update(user_edit._id, **kw) aff = Affiliate._update(aff_id, **form) self.finish(dict(err=err if err else False))
def post(self): err = JsOb() user_id = self.json._id user_edit = User._get(user_id) if not self.json.account: err.account = u'Account not be empty!' elif self.json.account != user_edit.account and User.count( dict(account=self.json.account, deleted=False)): err.account = u'Account already in use!' if not self.json.email: err.email = u'Email not be empty!' else: emails = self.json.email.replace(' ', '').split(',') for e in emails: if not is_email(e): err.email = 'Email not valid, email=%s' % e elif e not in user_edit.email and User.count( dict(email=e, deleted=False)): err.email = "email %s already in use" % e if self.json.password: if self.json.password != user_edit.password and not is_valid_password( self.json.password): err.password = u'password not valid!' if not err: content = dict(account=self.json.account, role_id=self.json.role_id, email=emails, password=self.json.password, skype_id=self.json.skype_id, phone=self.json.phone) res = User._update(user_id, **content) if not res: err.update = u'update user:{} failure'.format(user_id) self.render(err)